comparison mpeg12.c @ 3309:5e2c69db0ef7 libavcodec

MPEG-2 4:2:2 encoding support
author bcoudurier
date Tue, 16 May 2006 15:19:54 +0000
parents ceb221c4eca7
children d60dc0a7dee6
comparison
equal deleted inserted replaced
3308:57078a058b96 3309:5e2c69db0ef7
230 }else{ 230 }else{
231 av_log(avctx, AV_LOG_INFO, "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n", avctx->time_base.den, avctx->time_base.num); 231 av_log(avctx, AV_LOG_INFO, "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n", avctx->time_base.den, avctx->time_base.num);
232 } 232 }
233 } 233 }
234 234
235 if(avctx->profile == FF_PROFILE_UNKNOWN)
236 avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0;
237
238 if(avctx->level == FF_LEVEL_UNKNOWN)
239 avctx->level = s->chroma_format == CHROMA_420 ? 8 : 5;
240
235 return 0; 241 return 0;
236 } 242 }
237 243
238 static void put_header(MpegEncContext *s, int header) 244 static void put_header(MpegEncContext *s, int header)
239 { 245 {
317 ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); 323 ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
318 324
319 if(s->codec_id == CODEC_ID_MPEG2VIDEO){ 325 if(s->codec_id == CODEC_ID_MPEG2VIDEO){
320 put_header(s, EXT_START_CODE); 326 put_header(s, EXT_START_CODE);
321 put_bits(&s->pb, 4, 1); //seq ext 327 put_bits(&s->pb, 4, 1); //seq ext
322 put_bits(&s->pb, 1, 0); //esc 328
323 329 put_bits(&s->pb, 1, s->chroma_format == CHROMA_422); //escx
324 if(s->avctx->profile == FF_PROFILE_UNKNOWN){ 330
325 put_bits(&s->pb, 3, 4); //profile 331 put_bits(&s->pb, 3, s->avctx->profile); //profile
326 }else{ 332 put_bits(&s->pb, 4, s->avctx->level); //level
327 put_bits(&s->pb, 3, s->avctx->profile); //profile
328 }
329
330 if(s->avctx->level == FF_LEVEL_UNKNOWN){
331 put_bits(&s->pb, 4, 8); //level
332 }else{
333 put_bits(&s->pb, 4, s->avctx->level); //level
334 }
335 333
336 put_bits(&s->pb, 1, s->progressive_sequence); 334 put_bits(&s->pb, 1, s->progressive_sequence);
337 put_bits(&s->pb, 2, 1); //chroma format 4:2:0 335 put_bits(&s->pb, 2, s->chroma_format);
338 put_bits(&s->pb, 2, 0); //horizontal size ext 336 put_bits(&s->pb, 2, 0); //horizontal size ext
339 put_bits(&s->pb, 2, 0); //vertical size ext 337 put_bits(&s->pb, 2, 0); //vertical size ext
340 put_bits(&s->pb, 12, v>>18); //bitrate ext 338 put_bits(&s->pb, 12, v>>18); //bitrate ext
341 put_bits(&s->pb, 1, 1); //marker 339 put_bits(&s->pb, 1, 1); //marker
342 put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext 340 put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext
466 put_bits(&s->pb, 1, s->q_scale_type); 464 put_bits(&s->pb, 1, s->q_scale_type);
467 put_bits(&s->pb, 1, s->intra_vlc_format); 465 put_bits(&s->pb, 1, s->intra_vlc_format);
468 put_bits(&s->pb, 1, s->alternate_scan); 466 put_bits(&s->pb, 1, s->alternate_scan);
469 put_bits(&s->pb, 1, s->repeat_first_field); 467 put_bits(&s->pb, 1, s->repeat_first_field);
470 s->progressive_frame = s->progressive_sequence; 468 s->progressive_frame = s->progressive_sequence;
471 put_bits(&s->pb, 1, s->chroma_420_type=s->progressive_frame); 469 put_bits(&s->pb, 1, s->chroma_format == CHROMA_420 ? s->progressive_frame : 0); /* chroma_420_type */
472 put_bits(&s->pb, 1, s->progressive_frame); 470 put_bits(&s->pb, 1, s->progressive_frame);
473 put_bits(&s->pb, 1, 0); //composite_display_flag 471 put_bits(&s->pb, 1, 0); //composite_display_flag
474 } 472 }
475 if(s->flags & CODEC_FLAG_SVCD_SCAN_OFFSET){ 473 if(s->flags & CODEC_FLAG_SVCD_SCAN_OFFSET){
476 int i; 474 int i;
494 put_bits(&s->pb, 2, 2 - field_motion); /* motion_type: frame/field */ 492 put_bits(&s->pb, 2, 2 - field_motion); /* motion_type: frame/field */
495 put_bits(&s->pb, 1, s->interlaced_dct); 493 put_bits(&s->pb, 1, s->interlaced_dct);
496 } 494 }
497 } 495 }
498 496
499 void mpeg1_encode_mb(MpegEncContext *s, 497 static always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
500 DCTELEM block[6][64], 498 DCTELEM block[6][64],
501 int motion_x, int motion_y) 499 int motion_x, int motion_y,
500 int mb_block_count)
502 { 501 {
503 int i, cbp; 502 int i, cbp;
504 const int mb_x = s->mb_x; 503 const int mb_x = s->mb_x;
505 const int mb_y = s->mb_y; 504 const int mb_y = s->mb_y;
506 const int first_mb= mb_x == s->resync_mb_x && mb_y == s->resync_mb_y; 505 const int first_mb= mb_x == s->resync_mb_x && mb_y == s->resync_mb_y;
507 506
508 /* compute cbp */ 507 /* compute cbp */
509 cbp = 0; 508 cbp = 0;
510 for(i=0;i<6;i++) { 509 for(i=0;i<mb_block_count;i++) {
511 if (s->block_last_index[i] >= 0) 510 if (s->block_last_index[i] >= 0)
512 cbp |= 1 << (5 - i); 511 cbp |= 1 << (mb_block_count - 1 - i);
513 } 512 }
514 513
515 if (cbp == 0 && !first_mb && s->mv_type == MV_TYPE_16X16 && 514 if (cbp == 0 && !first_mb && s->mv_type == MV_TYPE_16X16 &&
516 (mb_x != s->mb_width - 1 || (mb_y != s->mb_height - 1 && s->codec_id == CODEC_ID_MPEG1VIDEO)) && 515 (mb_x != s->mb_width - 1 || (mb_y != s->mb_height - 1 && s->codec_id == CODEC_ID_MPEG1VIDEO)) &&
517 ((s->pict_type == P_TYPE && (motion_x | motion_y) == 0) || 516 ((s->pict_type == P_TYPE && (motion_x | motion_y) == 0) ||
613 s->last_mv[0][i][0]= s->mv[0][i][0]; 612 s->last_mv[0][i][0]= s->mv[0][i][0];
614 s->last_mv[0][i][1]= 2*s->mv[0][i][1]; 613 s->last_mv[0][i][1]= 2*s->mv[0][i][1];
615 } 614 }
616 s->mv_bits+= get_bits_diff(s); 615 s->mv_bits+= get_bits_diff(s);
617 } 616 }
618 if(cbp) 617 if(cbp) {
619 put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]); 618 if (s->chroma_y_shift) {
619 put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]);
620 } else {
621 put_bits(&s->pb, mbPatTable[cbp>>2][1], mbPatTable[cbp>>2][0]);
622 put_bits(&s->pb, 2, cbp & 3);
623 }
624 }
620 s->f_count++; 625 s->f_count++;
621 } else{ 626 } else{
622 static const int mb_type_len[4]={0,3,4,2}; //bak,for,bi 627 static const int mb_type_len[4]={0,3,4,2}; //bak,for,bi
623 628
624 if(s->mv_type == MV_TYPE_16X16){ 629 if(s->mv_type == MV_TYPE_16X16){
692 } 697 }
693 s->b_count++; 698 s->b_count++;
694 } 699 }
695 } 700 }
696 s->mv_bits += get_bits_diff(s); 701 s->mv_bits += get_bits_diff(s);
697 if(cbp) 702 if(cbp) {
698 put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]); 703 if (s->chroma_y_shift) {
699 } 704 put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]);
700 for(i=0;i<6;i++) { 705 } else {
701 if (cbp & (1 << (5 - i))) { 706 put_bits(&s->pb, mbPatTable[cbp>>2][1], mbPatTable[cbp>>2][0]);
707 put_bits(&s->pb, 2, cbp & 3);
708 }
709 }
710 }
711 for(i=0;i<mb_block_count;i++) {
712 if (cbp & (1 << (mb_block_count - 1 - i))) {
702 mpeg1_encode_block(s, block[i], i); 713 mpeg1_encode_block(s, block[i], i);
703 } 714 }
704 } 715 }
705 s->mb_skip_run = 0; 716 s->mb_skip_run = 0;
706 if(s->mb_intra) 717 if(s->mb_intra)
707 s->i_tex_bits+= get_bits_diff(s); 718 s->i_tex_bits+= get_bits_diff(s);
708 else 719 else
709 s->p_tex_bits+= get_bits_diff(s); 720 s->p_tex_bits+= get_bits_diff(s);
710 } 721 }
722 }
723
724 void mpeg1_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
725 {
726 if (s->chroma_format == CHROMA_420) mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6);
727 else mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8);
711 } 728 }
712 729
713 // RAL: Parameter added: f_or_b_code 730 // RAL: Parameter added: f_or_b_code
714 static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code) 731 static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
715 { 732 {
903 920
904 last_index = s->block_last_index[n]; 921 last_index = s->block_last_index[n];
905 922
906 /* DC coef */ 923 /* DC coef */
907 if (s->mb_intra) { 924 if (s->mb_intra) {
908 component = (n <= 3 ? 0 : n - 4 + 1); 925 component = (n <= 3 ? 0 : (n&1) + 1);
909 dc = block[0]; /* overflow is impossible */ 926 dc = block[0]; /* overflow is impossible */
910 diff = dc - s->last_dc[component]; 927 diff = dc - s->last_dc[component];
911 encode_dc(s, diff, component); 928 encode_dc(s, diff, component);
912 s->last_dc[component] = dc; 929 s->last_dc[component] = dc;
913 i = 1; 930 i = 1;
3247 sizeof(MpegEncContext), 3264 sizeof(MpegEncContext),
3248 encode_init, 3265 encode_init,
3249 MPV_encode_picture, 3266 MPV_encode_picture,
3250 MPV_encode_end, 3267 MPV_encode_end,
3251 .supported_framerates= frame_rate_tab+1, 3268 .supported_framerates= frame_rate_tab+1,
3252 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, 3269 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, -1},
3253 .capabilities= CODEC_CAP_DELAY, 3270 .capabilities= CODEC_CAP_DELAY,
3254 }; 3271 };
3255 #endif 3272 #endif
3256 3273
3257 #ifdef HAVE_XVMC 3274 #ifdef HAVE_XVMC