AVCodec.supported_framerates

Originally committed as revision 2821 to svn://svn.ffmpeg.org/ffmpeg/trunk
pull/126/head
Michael Niedermayer 21 years ago
parent 71141d771a
commit 8d52ec7eb0
  1. 3
      libavcodec/avcodec.h
  2. 31
      libavcodec/mpeg12.c
  3. 36
      libavcodec/mpeg12data.h

@ -17,7 +17,7 @@ extern "C" {
#define FFMPEG_VERSION_INT 0x000408 #define FFMPEG_VERSION_INT 0x000408
#define FFMPEG_VERSION "0.4.8" #define FFMPEG_VERSION "0.4.8"
#define LIBAVCODEC_BUILD 4705 #define LIBAVCODEC_BUILD 4706
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVCODEC_VERSION FFMPEG_VERSION #define LIBAVCODEC_VERSION FFMPEG_VERSION
@ -1605,6 +1605,7 @@ typedef struct AVCodec {
const AVOption *options; const AVOption *options;
struct AVCodec *next; struct AVCodec *next;
void (*flush)(AVCodecContext *); void (*flush)(AVCodecContext *);
AVRational *supported_framerates; ///array of supported framerates, or NULL if any, array is terminated by {0,0}
} AVCodec; } AVCodec;
/** /**

@ -195,9 +195,11 @@ static int find_frame_rate_index(MpegEncContext *s){
int64_t d; int64_t d;
for(i=1;i<14;i++) { for(i=1;i<14;i++) {
int64_t n0= 1001LL/frame_rate_tab[i].den*frame_rate_tab[i].num*s->avctx->frame_rate_base;
int64_t n1= 1001LL*s->avctx->frame_rate;
if(s->avctx->strict_std_compliance >= 0 && i>=9) break; if(s->avctx->strict_std_compliance >= 0 && i>=9) break;
d = ABS(MPEG1_FRAME_RATE_BASE*(int64_t)s->avctx->frame_rate - frame_rate_tab[i]*(int64_t)s->avctx->frame_rate_base); d = ABS(n0 - n1);
if(d < dmin){ if(d < dmin){
dmin=d; dmin=d;
s->frame_rate_index= i; s->frame_rate_index= i;
@ -249,6 +251,8 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA) if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA)
if (s->current_picture.key_frame) { if (s->current_picture.key_frame) {
AVRational framerate= frame_rate_tab[s->frame_rate_index];
/* mpeg1 header repeated every gop */ /* mpeg1 header repeated every gop */
put_header(s, SEQ_START_CODE); put_header(s, SEQ_START_CODE);
@ -295,8 +299,8 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
constraint_parameter_flag= constraint_parameter_flag=
s->width <= 768 && s->height <= 576 && s->width <= 768 && s->height <= 576 &&
s->mb_width * s->mb_height <= 396 && s->mb_width * s->mb_height <= 396 &&
s->mb_width * s->mb_height * frame_rate_tab[s->frame_rate_index] <= MPEG1_FRAME_RATE_BASE*396*25 && s->mb_width * s->mb_height * framerate.num <= framerate.den*396*25 &&
frame_rate_tab[s->frame_rate_index] <= MPEG1_FRAME_RATE_BASE*30 && framerate.num <= framerate.den*30 &&
vbv_buffer_size <= 20 && vbv_buffer_size <= 20 &&
v <= 1856000/400 && v <= 1856000/400 &&
s->codec_id == CODEC_ID_MPEG1VIDEO; s->codec_id == CODEC_ID_MPEG1VIDEO;
@ -328,7 +332,7 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
put_bits(&s->pb, 1, 0); /* do drop frame */ put_bits(&s->pb, 1, 0); /* do drop frame */
/* time code : we must convert from the real frame rate to a /* time code : we must convert from the real frame rate to a
fake mpeg frame rate in case of low frame rate */ fake mpeg frame rate in case of low frame rate */
fps = (frame_rate_tab[s->frame_rate_index] + MPEG1_FRAME_RATE_BASE/2)/ MPEG1_FRAME_RATE_BASE; fps = (framerate.num + framerate.den/2)/ framerate.den;
time_code = s->current_picture_ptr->coded_picture_number; time_code = s->current_picture_ptr->coded_picture_number;
s->gop_picture_number = time_code; s->gop_picture_number = time_code;
@ -1821,8 +1825,8 @@ static void mpeg_decode_sequence_extension(MpegEncContext *s)
av_reduce( av_reduce(
&s->avctx->frame_rate, &s->avctx->frame_rate,
&s->avctx->frame_rate_base, &s->avctx->frame_rate_base,
frame_rate_tab[s->frame_rate_index] * (frame_rate_ext_n+1), frame_rate_tab[s->frame_rate_index].num * (frame_rate_ext_n+1),
MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d+1), frame_rate_tab[s->frame_rate_index].den * (frame_rate_ext_d+1),
1<<30); 1<<30);
dprintf("sequence extension\n"); dprintf("sequence extension\n");
@ -2366,7 +2370,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
avctx->sample_aspect_ratio= av_d2q(aspect, 255); avctx->sample_aspect_ratio= av_d2q(aspect, 255);
s->frame_rate_index = get_bits(&s->gb, 4); s->frame_rate_index = get_bits(&s->gb, 4);
if (s->frame_rate_index == 0) if (s->frame_rate_index == 0 || s->frame_rate_index > 13)
return -1; return -1;
s->bit_rate = get_bits(&s->gb, 18) * 400; s->bit_rate = get_bits(&s->gb, 18) * 400;
if (get_bits1(&s->gb) == 0) /* marker */ if (get_bits1(&s->gb) == 0) /* marker */
@ -2386,13 +2390,8 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
avctx->has_b_frames= 1; avctx->has_b_frames= 1;
avctx->width = width; avctx->width = width;
avctx->height = height; avctx->height = height;
av_reduce( avctx->frame_rate = frame_rate_tab[s->frame_rate_index].num;
&avctx->frame_rate, avctx->frame_rate_base= frame_rate_tab[s->frame_rate_index].den;
&avctx->frame_rate_base,
frame_rate_tab[s->frame_rate_index],
MPEG1_FRAME_RATE_BASE, //FIXME store in allready reduced form
1<<30
);
avctx->bit_rate = s->bit_rate; avctx->bit_rate = s->bit_rate;
if(avctx->xvmc_acceleration){ if(avctx->xvmc_acceleration){
@ -2818,6 +2817,7 @@ AVCodec mpeg1video_encoder = {
encode_init, encode_init,
MPV_encode_picture, MPV_encode_picture,
MPV_encode_end, MPV_encode_end,
.supported_framerates= frame_rate_tab+1,
}; };
#ifdef CONFIG_RISKY #ifdef CONFIG_RISKY
@ -2830,6 +2830,7 @@ AVCodec mpeg2video_encoder = {
encode_init, encode_init,
MPV_encode_picture, MPV_encode_picture,
MPV_encode_end, MPV_encode_end,
.supported_framerates= frame_rate_tab+1,
}; };
#endif #endif
#endif #endif

@ -354,28 +354,24 @@ static const uint8_t mbMotionVectorTable[17][2] = {
{ 0xc, 10 }, { 0xc, 10 },
}; };
#define MPEG1_FRAME_RATE_BASE 1001 static const AVRational frame_rate_tab[] = {
{ 0, 0},
static const int frame_rate_tab[16] = { {24000, 1001},
0, { 24, 1},
24000, { 25, 1},
24024, {30000, 1001},
25025, { 30, 1},
30000, { 50, 1},
30030, {60000, 1001},
50050, { 60, 1},
60000,
60060,
// Xing's 15fps: (9) // Xing's 15fps: (9)
15015, { 15, 1},
// libmpeg3's "Unofficial economy rates": (10-13) // libmpeg3's "Unofficial economy rates": (10-13)
5005, { 5, 1},
10010, { 10, 1},
12012, { 12, 1},
15015, { 15, 1},
// random, just to avoid segfault !never encode these { 0, 0},
25025,
25025,
}; };
static const uint8_t non_linear_qscale[32] = { static const uint8_t non_linear_qscale[32] = {

Loading…
Cancel
Save