1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-03-23 04:24:35 +02:00

ffmpeg: move keyboard interaction in a function.

It makes the transcode loop easier to read (30% less code)
and the differences with avconv easier to spot.
This commit is contained in:
Nicolas George 2012-06-06 15:56:34 +02:00
parent 9915a33fc2
commit 25e87fc5f6

View File

@ -3210,43 +3210,12 @@ static int select_input_file(uint8_t *no_packet)
return file_index; return file_index;
} }
/* static int check_keyboard_interaction(int64_t cur_time)
* The following code is the main loop of the file converter
*/
static int transcode(void)
{ {
int ret, i; int i, ret, key;
AVFormatContext *is, *os;
OutputStream *ost;
InputStream *ist;
uint8_t *no_packet;
int no_packet_count = 0;
int64_t timer_start;
int key;
if (!(no_packet = av_mallocz(nb_input_files)))
exit_program(1);
ret = transcode_init();
if (ret < 0)
goto fail;
if (!using_stdin) {
av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
}
timer_start = av_gettime();
for (; received_sigterm == 0;) {
int file_index, ist_index;
AVPacket pkt;
int64_t cur_time= av_gettime();
/* if 'q' pressed, exits */
if (!using_stdin) {
static int64_t last_time; static int64_t last_time;
if (received_nb_signals) if (received_nb_signals)
break; return AVERROR_EXIT;
/* read_key() returns 0 on EOF */ /* read_key() returns 0 on EOF */
if(cur_time - last_time >= 100000 && !run_as_daemon){ if(cur_time - last_time >= 100000 && !run_as_daemon){
key = read_key(); key = read_key();
@ -3254,7 +3223,7 @@ static int transcode(void)
}else }else
key = -1; key = -1;
if (key == 'q') if (key == 'q')
break; return AVERROR_EXIT;
if (key == '+') av_log_set_level(av_log_get_level()+10); if (key == '+') av_log_set_level(av_log_get_level()+10);
if (key == '-') av_log_set_level(av_log_get_level()-10); if (key == '-') av_log_set_level(av_log_get_level()-10);
if (key == 's') qp_hist ^= 1; if (key == 's') qp_hist ^= 1;
@ -3313,7 +3282,7 @@ static int transcode(void)
input_streams[i]->st->codec->debug = debug; input_streams[i]->st->codec->debug = debug;
} }
for(i=0;i<nb_output_streams;i++) { for(i=0;i<nb_output_streams;i++) {
ost = output_streams[i]; OutputStream *ost = output_streams[i];
ost->st->codec->debug = debug; ost->st->codec->debug = debug;
} }
if(debug) av_log_set_level(AV_LOG_DEBUG); if(debug) av_log_set_level(AV_LOG_DEBUG);
@ -3331,8 +3300,45 @@ static int transcode(void)
"s Show QP histogram\n" "s Show QP histogram\n"
); );
} }
return 0;
} }
/*
* The following code is the main loop of the file converter
*/
static int transcode(void)
{
int ret, i;
AVFormatContext *is, *os;
OutputStream *ost;
InputStream *ist;
uint8_t *no_packet;
int no_packet_count = 0;
int64_t timer_start;
if (!(no_packet = av_mallocz(nb_input_files)))
exit_program(1);
ret = transcode_init();
if (ret < 0)
goto fail;
if (!using_stdin) {
av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
}
timer_start = av_gettime();
for (; received_sigterm == 0;) {
int file_index, ist_index;
AVPacket pkt;
int64_t cur_time= av_gettime();
/* if 'q' pressed, exits */
if (!using_stdin)
if (check_keyboard_interaction(cur_time) < 0)
break;
/* check if there's any stream where output is still needed */ /* check if there's any stream where output is still needed */
if (!need_output()) { if (!need_output()) {
av_log(NULL, AV_LOG_VERBOSE, "No more output streams to write to, finishing.\n"); av_log(NULL, AV_LOG_VERBOSE, "No more output streams to write to, finishing.\n");