Mercurial > libavcodec.hg
comparison mpeg12.c @ 1837:a4d9e8b4e2f8 libavcodec
AVCodec.supported_framerates
author | michael |
---|---|
date | Thu, 26 Feb 2004 18:29:39 +0000 |
parents | fcbf31baa1af |
children | 05017f3b87d9 |
comparison
equal
deleted
inserted
replaced
1836:8fa34b5b35bc | 1837:a4d9e8b4e2f8 |
---|---|
193 int i; | 193 int i; |
194 int64_t dmin= INT64_MAX; | 194 int64_t dmin= INT64_MAX; |
195 int64_t d; | 195 int64_t d; |
196 | 196 |
197 for(i=1;i<14;i++) { | 197 for(i=1;i<14;i++) { |
198 int64_t n0= 1001LL/frame_rate_tab[i].den*frame_rate_tab[i].num*s->avctx->frame_rate_base; | |
199 int64_t n1= 1001LL*s->avctx->frame_rate; | |
198 if(s->avctx->strict_std_compliance >= 0 && i>=9) break; | 200 if(s->avctx->strict_std_compliance >= 0 && i>=9) break; |
199 | 201 |
200 d = ABS(MPEG1_FRAME_RATE_BASE*(int64_t)s->avctx->frame_rate - frame_rate_tab[i]*(int64_t)s->avctx->frame_rate_base); | 202 d = ABS(n0 - n1); |
201 if(d < dmin){ | 203 if(d < dmin){ |
202 dmin=d; | 204 dmin=d; |
203 s->frame_rate_index= i; | 205 s->frame_rate_index= i; |
204 } | 206 } |
205 } | 207 } |
247 int constraint_parameter_flag; | 249 int constraint_parameter_flag; |
248 | 250 |
249 if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA) | 251 if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA) |
250 | 252 |
251 if (s->current_picture.key_frame) { | 253 if (s->current_picture.key_frame) { |
254 AVRational framerate= frame_rate_tab[s->frame_rate_index]; | |
255 | |
252 /* mpeg1 header repeated every gop */ | 256 /* mpeg1 header repeated every gop */ |
253 put_header(s, SEQ_START_CODE); | 257 put_header(s, SEQ_START_CODE); |
254 | 258 |
255 put_bits(&s->pb, 12, s->width); | 259 put_bits(&s->pb, 12, s->width); |
256 put_bits(&s->pb, 12, s->height); | 260 put_bits(&s->pb, 12, s->height); |
293 put_bits(&s->pb, 10, vbv_buffer_size & 0x3FF); | 297 put_bits(&s->pb, 10, vbv_buffer_size & 0x3FF); |
294 | 298 |
295 constraint_parameter_flag= | 299 constraint_parameter_flag= |
296 s->width <= 768 && s->height <= 576 && | 300 s->width <= 768 && s->height <= 576 && |
297 s->mb_width * s->mb_height <= 396 && | 301 s->mb_width * s->mb_height <= 396 && |
298 s->mb_width * s->mb_height * frame_rate_tab[s->frame_rate_index] <= MPEG1_FRAME_RATE_BASE*396*25 && | 302 s->mb_width * s->mb_height * framerate.num <= framerate.den*396*25 && |
299 frame_rate_tab[s->frame_rate_index] <= MPEG1_FRAME_RATE_BASE*30 && | 303 framerate.num <= framerate.den*30 && |
300 vbv_buffer_size <= 20 && | 304 vbv_buffer_size <= 20 && |
301 v <= 1856000/400 && | 305 v <= 1856000/400 && |
302 s->codec_id == CODEC_ID_MPEG1VIDEO; | 306 s->codec_id == CODEC_ID_MPEG1VIDEO; |
303 | 307 |
304 put_bits(&s->pb, 1, constraint_parameter_flag); | 308 put_bits(&s->pb, 1, constraint_parameter_flag); |
326 | 330 |
327 put_header(s, GOP_START_CODE); | 331 put_header(s, GOP_START_CODE); |
328 put_bits(&s->pb, 1, 0); /* do drop frame */ | 332 put_bits(&s->pb, 1, 0); /* do drop frame */ |
329 /* time code : we must convert from the real frame rate to a | 333 /* time code : we must convert from the real frame rate to a |
330 fake mpeg frame rate in case of low frame rate */ | 334 fake mpeg frame rate in case of low frame rate */ |
331 fps = (frame_rate_tab[s->frame_rate_index] + MPEG1_FRAME_RATE_BASE/2)/ MPEG1_FRAME_RATE_BASE; | 335 fps = (framerate.num + framerate.den/2)/ framerate.den; |
332 time_code = s->current_picture_ptr->coded_picture_number; | 336 time_code = s->current_picture_ptr->coded_picture_number; |
333 | 337 |
334 s->gop_picture_number = time_code; | 338 s->gop_picture_number = time_code; |
335 put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); | 339 put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); |
336 put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); | 340 put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); |
1819 frame_rate_ext_n = get_bits(&s->gb, 2); | 1823 frame_rate_ext_n = get_bits(&s->gb, 2); |
1820 frame_rate_ext_d = get_bits(&s->gb, 5); | 1824 frame_rate_ext_d = get_bits(&s->gb, 5); |
1821 av_reduce( | 1825 av_reduce( |
1822 &s->avctx->frame_rate, | 1826 &s->avctx->frame_rate, |
1823 &s->avctx->frame_rate_base, | 1827 &s->avctx->frame_rate_base, |
1824 frame_rate_tab[s->frame_rate_index] * (frame_rate_ext_n+1), | 1828 frame_rate_tab[s->frame_rate_index].num * (frame_rate_ext_n+1), |
1825 MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d+1), | 1829 frame_rate_tab[s->frame_rate_index].den * (frame_rate_ext_d+1), |
1826 1<<30); | 1830 1<<30); |
1827 | 1831 |
1828 dprintf("sequence extension\n"); | 1832 dprintf("sequence extension\n"); |
1829 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO; | 1833 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO; |
1830 s->avctx->sub_id = 2; /* indicates mpeg2 found */ | 1834 s->avctx->sub_id = 2; /* indicates mpeg2 found */ |
2364 return -1; | 2368 return -1; |
2365 aspect= 1.0/mpeg1_aspect[s->aspect_ratio_info]; | 2369 aspect= 1.0/mpeg1_aspect[s->aspect_ratio_info]; |
2366 avctx->sample_aspect_ratio= av_d2q(aspect, 255); | 2370 avctx->sample_aspect_ratio= av_d2q(aspect, 255); |
2367 | 2371 |
2368 s->frame_rate_index = get_bits(&s->gb, 4); | 2372 s->frame_rate_index = get_bits(&s->gb, 4); |
2369 if (s->frame_rate_index == 0) | 2373 if (s->frame_rate_index == 0 || s->frame_rate_index > 13) |
2370 return -1; | 2374 return -1; |
2371 s->bit_rate = get_bits(&s->gb, 18) * 400; | 2375 s->bit_rate = get_bits(&s->gb, 18) * 400; |
2372 if (get_bits1(&s->gb) == 0) /* marker */ | 2376 if (get_bits1(&s->gb) == 0) /* marker */ |
2373 return -1; | 2377 return -1; |
2374 if (width <= 0 || height <= 0 || | 2378 if (width <= 0 || height <= 0 || |
2384 s->width = width; | 2388 s->width = width; |
2385 s->height = height; | 2389 s->height = height; |
2386 avctx->has_b_frames= 1; | 2390 avctx->has_b_frames= 1; |
2387 avctx->width = width; | 2391 avctx->width = width; |
2388 avctx->height = height; | 2392 avctx->height = height; |
2389 av_reduce( | 2393 avctx->frame_rate = frame_rate_tab[s->frame_rate_index].num; |
2390 &avctx->frame_rate, | 2394 avctx->frame_rate_base= frame_rate_tab[s->frame_rate_index].den; |
2391 &avctx->frame_rate_base, | |
2392 frame_rate_tab[s->frame_rate_index], | |
2393 MPEG1_FRAME_RATE_BASE, //FIXME store in allready reduced form | |
2394 1<<30 | |
2395 ); | |
2396 avctx->bit_rate = s->bit_rate; | 2395 avctx->bit_rate = s->bit_rate; |
2397 | 2396 |
2398 if(avctx->xvmc_acceleration){ | 2397 if(avctx->xvmc_acceleration){ |
2399 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420); | 2398 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420); |
2400 }else{ | 2399 }else{ |
2816 CODEC_ID_MPEG1VIDEO, | 2815 CODEC_ID_MPEG1VIDEO, |
2817 sizeof(MpegEncContext), | 2816 sizeof(MpegEncContext), |
2818 encode_init, | 2817 encode_init, |
2819 MPV_encode_picture, | 2818 MPV_encode_picture, |
2820 MPV_encode_end, | 2819 MPV_encode_end, |
2820 .supported_framerates= frame_rate_tab+1, | |
2821 }; | 2821 }; |
2822 | 2822 |
2823 #ifdef CONFIG_RISKY | 2823 #ifdef CONFIG_RISKY |
2824 | 2824 |
2825 AVCodec mpeg2video_encoder = { | 2825 AVCodec mpeg2video_encoder = { |
2828 CODEC_ID_MPEG2VIDEO, | 2828 CODEC_ID_MPEG2VIDEO, |
2829 sizeof(MpegEncContext), | 2829 sizeof(MpegEncContext), |
2830 encode_init, | 2830 encode_init, |
2831 MPV_encode_picture, | 2831 MPV_encode_picture, |
2832 MPV_encode_end, | 2832 MPV_encode_end, |
2833 .supported_framerates= frame_rate_tab+1, | |
2833 }; | 2834 }; |
2834 #endif | 2835 #endif |
2835 #endif | 2836 #endif |
2836 | 2837 |
2837 #ifdef HAVE_XVMC | 2838 #ifdef HAVE_XVMC |