Revision 22f7a060

View differences:

ffmpeg.c
17 17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 18
 */
19 19
#define HAVE_AV_CONFIG_H
20
#include <limits.h>
20 21
#include "avformat.h"
21 22
#include "framehook.h"
22 23

  
......
2751 2752
                    codec_id = video_codec_id;
2752 2753
                
2753 2754
                video_enc->codec_id = codec_id;
2755
                codec = avcodec_find_encoder(codec_id);
2754 2756
                
2755 2757
                video_enc->bit_rate = video_bit_rate;
2756 2758
                video_enc->bit_rate_tolerance = video_bit_rate_tolerance;
2757 2759
                video_enc->frame_rate = frame_rate; 
2758 2760
                video_enc->frame_rate_base = frame_rate_base; 
2761
                if(codec && codec->supported_framerates){
2762
                    const AVRational *p= codec->supported_framerates;
2763
                    AVRational req= (AVRational){frame_rate, frame_rate_base};
2764
                    const AVRational *best=NULL;
2765
                    AVRational best_error= (AVRational){INT_MAX, 1};
2766
                    for(; p->den!=0; p++){
2767
                        AVRational error= av_sub_q(req, *p);
2768
                        if(error.num <0) error.num *= -1;
2769
                        if(av_cmp_q(error, best_error) < 0){
2770
                            best_error= error;
2771
                            best= p;
2772
                        }
2773
                    }
2774
                    video_enc->frame_rate     = best->num;
2775
                    video_enc->frame_rate_base= best->den;
2776
                }
2759 2777
                
2760 2778
                video_enc->width = frame_width + frame_padright + frame_padleft;
2761 2779
                video_enc->height = frame_height + frame_padtop + frame_padbottom;
2762 2780
		video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);
2763 2781
                video_enc->pix_fmt = frame_pix_fmt;
2764 2782

  
2765
                codec = avcodec_find_encoder(codec_id);
2766 2783
                if(codec && codec->pix_fmts){
2767 2784
                    const enum PixelFormat *p= codec->pix_fmts;
2768 2785
                    for(; *p!=-1; p++){

Also available in: Unified diff