From 22f7a0601e94583276b01f4a7c5a4d4ec77d4164 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 12 May 2004 16:51:39 +0000 Subject: [PATCH] automatic framerate selection Originally committed as revision 3132 to svn://svn.ffmpeg.org/ffmpeg/trunk --- ffmpeg.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ffmpeg.c b/ffmpeg.c index 6297587ea6..5d211a2ea0 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -17,6 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define HAVE_AV_CONFIG_H +#include #include "avformat.h" #include "framehook.h" @@ -2751,18 +2752,34 @@ static void opt_output_file(const char *filename) codec_id = video_codec_id; video_enc->codec_id = codec_id; + codec = avcodec_find_encoder(codec_id); video_enc->bit_rate = video_bit_rate; video_enc->bit_rate_tolerance = video_bit_rate_tolerance; video_enc->frame_rate = frame_rate; video_enc->frame_rate_base = frame_rate_base; + if(codec && codec->supported_framerates){ + const AVRational *p= codec->supported_framerates; + AVRational req= (AVRational){frame_rate, frame_rate_base}; + const AVRational *best=NULL; + AVRational best_error= (AVRational){INT_MAX, 1}; + for(; p->den!=0; p++){ + AVRational error= av_sub_q(req, *p); + if(error.num <0) error.num *= -1; + if(av_cmp_q(error, best_error) < 0){ + best_error= error; + best= p; + } + } + video_enc->frame_rate = best->num; + video_enc->frame_rate_base= best->den; + } video_enc->width = frame_width + frame_padright + frame_padleft; video_enc->height = frame_height + frame_padtop + frame_padbottom; video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255); video_enc->pix_fmt = frame_pix_fmt; - codec = avcodec_find_encoder(codec_id); if(codec && codec->pix_fmts){ const enum PixelFormat *p= codec->pix_fmts; for(; *p!=-1; p++){