diff --git a/ffmpeg.c b/ffmpeg.c index 045ee54a29..d1f358aaf4 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -96,6 +96,7 @@ static int frame_topBand = 0; static int frame_bottomBand = 0; static int frame_leftBand = 0; static int frame_rightBand = 0; +static int max_frames[3] = {INT_MAX, INT_MAX, INT_MAX}; static int frame_rate = 25; static int frame_rate_base = 1; static int video_bit_rate = 200*1000; @@ -711,6 +712,7 @@ static void do_video_out(AVFormatContext *s, }else ost->sync_opts= lrintf(ost->sync_ipts * enc->frame_rate / enc->frame_rate_base); + nb_frames= FFMIN(nb_frames, max_frames[CODEC_TYPE_VIDEO] - ost->frame_number); if (nb_frames <= 0) return; @@ -1838,6 +1840,10 @@ static int av_encode(AVFormatContext **output_files, if(!input_sync) file_index = ist->file_index; } } + if(ost->frame_number >= max_frames[ost->st->codec.codec_type]){ + file_index= -1; + break; + } } /* if none, if is finished */ if (file_index < 0) { @@ -3827,6 +3833,9 @@ const OptionDef options[] = { /* video options */ { "b", HAS_ARG | OPT_VIDEO, {(void*)opt_video_bitrate}, "set video bitrate (in kbit/s)", "bitrate" }, + { "vframes", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&max_frames[CODEC_TYPE_VIDEO]}, "set the number of video frames to record", "number" }, + { "aframes", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&max_frames[CODEC_TYPE_AUDIO]}, "set the number of audio frames to record", "number" }, + { "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[CODEC_TYPE_DATA]}, "set the number of data frames to record", "number" }, { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" }, { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },