Originally committed as revision 3132 to svn://svn.ffmpeg.org/ffmpeg/trunk
Michael Niedermayer authored on 2004/05/13 01:51:39... | ... |
@@ -17,6 +17,7 @@ |
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,18 +2752,34 @@ static void opt_output_file(const char *filename) |
2751 | 2751 |
codec_id = video_codec_id; |
2752 | 2752 |
|
2753 | 2753 |
video_enc->codec_id = codec_id; |
2754 |
+ codec = avcodec_find_encoder(codec_id); |
|
2754 | 2755 |
|
2755 | 2756 |
video_enc->bit_rate = video_bit_rate; |
2756 | 2757 |
video_enc->bit_rate_tolerance = video_bit_rate_tolerance; |
2757 | 2758 |
video_enc->frame_rate = frame_rate; |
2758 | 2759 |
video_enc->frame_rate_base = frame_rate_base; |
2760 |
+ if(codec && codec->supported_framerates){ |
|
2761 |
+ const AVRational *p= codec->supported_framerates; |
|
2762 |
+ AVRational req= (AVRational){frame_rate, frame_rate_base}; |
|
2763 |
+ const AVRational *best=NULL; |
|
2764 |
+ AVRational best_error= (AVRational){INT_MAX, 1}; |
|
2765 |
+ for(; p->den!=0; p++){ |
|
2766 |
+ AVRational error= av_sub_q(req, *p); |
|
2767 |
+ if(error.num <0) error.num *= -1; |
|
2768 |
+ if(av_cmp_q(error, best_error) < 0){ |
|
2769 |
+ best_error= error; |
|
2770 |
+ best= p; |
|
2771 |
+ } |
|
2772 |
+ } |
|
2773 |
+ video_enc->frame_rate = best->num; |
|
2774 |
+ video_enc->frame_rate_base= best->den; |
|
2775 |
+ } |
|
2759 | 2776 |
|
2760 | 2777 |
video_enc->width = frame_width + frame_padright + frame_padleft; |
2761 | 2778 |
video_enc->height = frame_height + frame_padtop + frame_padbottom; |
2762 | 2779 |
video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255); |
2763 | 2780 |
video_enc->pix_fmt = frame_pix_fmt; |
2764 | 2781 |
|
2765 |
- codec = avcodec_find_encoder(codec_id); |
|
2766 | 2782 |
if(codec && codec->pix_fmts){ |
2767 | 2783 |
const enum PixelFormat *p= codec->pix_fmts; |
2768 | 2784 |
for(; *p!=-1; p++){ |