summaryrefslogtreecommitdiff
path: root/ffmpeg.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2004-05-12 16:51:39 +0000
committerMichael Niedermayer <michaelni@gmx.at>2004-05-12 16:51:39 +0000
commit22f7a0601e94583276b01f4a7c5a4d4ec77d4164 (patch)
tree8e9c4793298d014c198860f9640d2b98b1e7f567 /ffmpeg.c
parentfcee01646748763cf63528c97b99e976d6c76da8 (diff)
automatic framerate selection
Originally committed as revision 3132 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'ffmpeg.c')
-rw-r--r--ffmpeg.c19
1 files changed, 18 insertions, 1 deletions
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 <limits.h>
#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++){