[SCM] libav/experimental: automatic framerate selection

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 15:40:23 UTC 2013


The following commit has been merged in the experimental branch:
commit 22f7a0601e94583276b01f4a7c5a4d4ec77d4164
Author: Michael Niedermayer <michaelni at gmx.at>
Date:   Wed May 12 16:51:39 2004 +0000

    automatic framerate selection
    
    Originally committed as revision 3132 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/ffmpeg.c b/ffmpeg.c
index 6297587..5d211a2 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++){

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list