See the thread: "Implement in lavc a flag which makes avcodec_open()
to choose the best framerate".
Originally committed as revision 15445 to svn://svn.ffmpeg.org/ffmpeg/trunk
... | ... |
@@ -212,6 +212,7 @@ static int nb_frames_dup = 0; |
212 | 212 |
static int nb_frames_drop = 0; |
213 | 213 |
static int input_sync; |
214 | 214 |
static uint64_t limit_filesize = 0; // |
215 |
+static int force_fps = 0; |
|
215 | 216 |
|
216 | 217 |
static int pgmyuv_compatibility_hack=0; |
217 | 218 |
static float dts_delta_threshold = 10; |
... | ... |
@@ -3041,23 +3042,10 @@ static void new_video_stream(AVFormatContext *oc) |
3041 | 3041 |
|
3042 | 3042 |
set_context_opts(video_enc, avctx_opts[CODEC_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM); |
3043 | 3043 |
|
3044 |
+ if (codec && codec->supported_framerates && !force_fps) |
|
3045 |
+ fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)]; |
|
3044 | 3046 |
video_enc->time_base.den = fps.num; |
3045 | 3047 |
video_enc->time_base.num = fps.den; |
3046 |
- if(codec && codec->supported_framerates){ |
|
3047 |
- const AVRational *p= codec->supported_framerates; |
|
3048 |
- const AVRational *best=NULL; |
|
3049 |
- AVRational best_error= (AVRational){INT_MAX, 1}; |
|
3050 |
- for(; p->den!=0; p++){ |
|
3051 |
- AVRational error= av_sub_q(fps, *p); |
|
3052 |
- if(error.num <0) error.num *= -1; |
|
3053 |
- if(av_cmp_q(error, best_error) < 0){ |
|
3054 |
- best_error= error; |
|
3055 |
- best= p; |
|
3056 |
- } |
|
3057 |
- } |
|
3058 |
- video_enc->time_base.den= best->num; |
|
3059 |
- video_enc->time_base.num= best->den; |
|
3060 |
- } |
|
3061 | 3048 |
|
3062 | 3049 |
video_enc->width = frame_width + frame_padright + frame_padleft; |
3063 | 3050 |
video_enc->height = frame_height + frame_padtop + frame_padbottom; |
... | ... |
@@ -3862,6 +3850,7 @@ static const OptionDef options[] = { |
3862 | 3862 |
{ "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_tag}, "force video tag/fourcc", "fourcc/tag" }, |
3863 | 3863 |
{ "newvideo", OPT_VIDEO, {(void*)opt_new_video_stream}, "add a new video stream to the current output stream" }, |
3864 | 3864 |
{ "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" }, |
3865 |
+ { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&force_fps}, "force the selected framerate, disable the best supported framerate selection" }, |
|
3865 | 3866 |
|
3866 | 3867 |
/* audio options */ |
3867 | 3868 |
{ "ab", OPT_FUNC2 | HAS_ARG | OPT_AUDIO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" }, |