* The following code is the main loop of the file converter */
| 4546 | * The following code is the main loop of the file converter |
| 4547 | */ |
| 4548 | static int transcode(void) |
| 4549 | { |
| 4550 | int ret, i; |
| 4551 | AVFormatContext *os; |
| 4552 | OutputStream *ost; |
| 4553 | InputStream *ist; |
| 4554 | int64_t timer_start; |
| 4555 | int64_t total_packets_written = 0; |
| 4556 | |
| 4557 | ret = transcode_init(); |
| 4558 | if (ret < 0) |
| 4559 | goto fail; |
| 4560 | |
| 4561 | if (stdin_interaction) { |
| 4562 | av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n"); |
| 4563 | } |
| 4564 | |
| 4565 | timer_start = av_gettime_relative(); |
| 4566 | |
| 4567 | #if HAVE_PTHREADS |
| 4568 | if ((ret = init_input_threads()) < 0) |
| 4569 | goto fail; |
| 4570 | #endif |
| 4571 | |
| 4572 | while (!received_sigterm) { |
| 4573 | int64_t cur_time= av_gettime_relative(); |
| 4574 | |
| 4575 | /* if 'q' pressed, exits */ |
| 4576 | if (stdin_interaction) |
| 4577 | if (check_keyboard_interaction(cur_time) < 0) |
| 4578 | break; |
| 4579 | |
| 4580 | /* check if there's any stream where output is still needed */ |
| 4581 | if (!need_output()) { |
| 4582 | av_log(NULL, AV_LOG_VERBOSE, "No more output streams to write to, finishing.\n"); |
| 4583 | break; |
| 4584 | } |
| 4585 | |
| 4586 | ret = transcode_step(); |
| 4587 | if (ret < 0 && ret != AVERROR_EOF) { |
| 4588 | char errbuf[128]; |
| 4589 | av_strerror(ret, errbuf, sizeof(errbuf)); |
| 4590 | |
| 4591 | av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n", errbuf); |
| 4592 | break; |
| 4593 | } |
| 4594 | |
| 4595 | /* dump report by using the output first video and audio streams */ |
| 4596 | print_report(0, timer_start, cur_time); |
| 4597 | } |
| 4598 | #if HAVE_PTHREADS |
| 4599 | free_input_threads(); |
| 4600 | #endif |
| 4601 | |
| 4602 | /* at the end of stream, we must flush the decoder buffers */ |
| 4603 | for (i = 0; i < nb_input_streams; i++) { |
| 4604 | ist = input_streams[i]; |
| 4605 | if (!input_files[ist->file_index]->eof_reached && ist->decoding_needed) { |
no test coverage detected