Revision 2d974017 libavcodec/mpeg12.c

View differences:

libavcodec/mpeg12.c
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 241
    return 0;
236 242
}
237 243

  
......
319 325
            if(s->codec_id == CODEC_ID_MPEG2VIDEO){
320 326
                put_header(s, EXT_START_CODE);
321 327
                put_bits(&s->pb, 4, 1); //seq ext
322
                put_bits(&s->pb, 1, 0); //esc
323 328

  
324
                if(s->avctx->profile == FF_PROFILE_UNKNOWN){
325
                    put_bits(&s->pb, 3, 4); //profile
326
                }else{
327
                    put_bits(&s->pb, 3, s->avctx->profile); //profile
328
                }
329
                put_bits(&s->pb, 1, s->chroma_format == CHROMA_422); //escx
329 330

  
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
                }
331
                put_bits(&s->pb, 3, s->avctx->profile); //profile
332
                put_bits(&s->pb, 4, s->avctx->level); //level
335 333

  
336 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 336
                put_bits(&s->pb, 2, 0); //horizontal size ext
339 337
                put_bits(&s->pb, 2, 0); //vertical size ext
340 338
                put_bits(&s->pb, 12, v>>18); //bitrate ext
......
468 466
        put_bits(&s->pb, 1, s->alternate_scan);
469 467
        put_bits(&s->pb, 1, s->repeat_first_field);
470 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 470
        put_bits(&s->pb, 1, s->progressive_frame);
473 471
        put_bits(&s->pb, 1, 0); //composite_display_flag
474 472
    }
......
496 494
    }
497 495
}
498 496

  
499
void mpeg1_encode_mb(MpegEncContext *s,
500
                     DCTELEM block[6][64],
501
                     int motion_x, int motion_y)
497
static always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
498
                                                   DCTELEM block[6][64],
499
                                                   int motion_x, int motion_y,
500
                                                   int mb_block_count)
502 501
{
503 502
    int i, cbp;
504 503
    const int mb_x = s->mb_x;
......
507 506

  
508 507
    /* compute cbp */
509 508
    cbp = 0;
510
    for(i=0;i<6;i++) {
509
    for(i=0;i<mb_block_count;i++) {
511 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 514
    if (cbp == 0 && !first_mb && s->mv_type == MV_TYPE_16X16 &&
......
615 614
                }
616 615
                s->mv_bits+= get_bits_diff(s);
617 616
            }
618
            if(cbp)
619
                put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]);
617
            if(cbp) {
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 625
            s->f_count++;
621 626
        } else{
622 627
            static const int mb_type_len[4]={0,3,4,2}; //bak,for,bi
......
694 699
                }
695 700
            }
696 701
            s->mv_bits += get_bits_diff(s);
697
            if(cbp)
698
                put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]);
702
            if(cbp) {
703
                if (s->chroma_y_shift) {
704
                    put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]);
705
                } else {
706
                    put_bits(&s->pb, mbPatTable[cbp>>2][1], mbPatTable[cbp>>2][0]);
707
                    put_bits(&s->pb, 2, cbp & 3);
708
                }
709
            }
699 710
        }
700
        for(i=0;i<6;i++) {
701
            if (cbp & (1 << (5 - i))) {
711
        for(i=0;i<mb_block_count;i++) {
712
            if (cbp & (1 << (mb_block_count - 1 - i))) {
702 713
                mpeg1_encode_block(s, block[i], i);
703 714
            }
704 715
        }
......
710 721
    }
711 722
}
712 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);
728
}
729

  
713 730
// RAL: Parameter added: f_or_b_code
714 731
static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
715 732
{
......
905 922

  
906 923
    /* DC coef */
907 924
    if (s->mb_intra) {
908
        component = (n <= 3 ? 0 : n - 4 + 1);
925
        component = (n <= 3 ? 0 : (n&1) + 1);
909 926
        dc = block[0]; /* overflow is impossible */
910 927
        diff = dc - s->last_dc[component];
911 928
        encode_dc(s, diff, component);
......
3249 3266
    MPV_encode_picture,
3250 3267
    MPV_encode_end,
3251 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 3270
    .capabilities= CODEC_CAP_DELAY,
3254 3271
};
3255 3272
#endif

Also available in: Unified diff