Revision 41773b73

View differences:

libavcodec/avcodec.h
826 826
#define FF_DEBUG_MB_TYPE   8
827 827
#define FF_DEBUG_QP        16
828 828
#define FF_DEBUG_MV        32
829
#define FF_DEBUG_VIS_MV    64
830
#define FF_DEBUG_SKIP      128
829
#define FF_DEBUG_VIS_MV    0x00000040
830
#define FF_DEBUG_SKIP      0x00000080
831
#define FF_DEBUG_STARTCODE 0x00000100
832
#define FF_DEBUG_PTS       0x00000200
831 833
    
832 834
    /**
833 835
     * error
libavcodec/h263.c
1564 1564
    }
1565 1565
}
1566 1566

  
1567
static void mpeg4_encode_vol_header(MpegEncContext * s)
1567
static void mpeg4_encode_gop_header(MpegEncContext * s){
1568
    int hours, minutes, seconds;
1569
    
1570
    put_bits(&s->pb, 16, 0);
1571
    put_bits(&s->pb, 16, GOP_STARTCODE);
1572
    
1573
    seconds= s->time/s->time_increment_resolution;
1574
    minutes= seconds/60; seconds %= 60;
1575
    hours= minutes/60; minutes %= 60;
1576
    hours%=24;
1577

  
1578
    put_bits(&s->pb, 5, hours);
1579
    put_bits(&s->pb, 6, minutes);
1580
    put_bits(&s->pb, 1, 1);
1581
    put_bits(&s->pb, 6, seconds);
1582
    
1583
    put_bits(&s->pb, 1, 0); //closed gov == NO
1584
    put_bits(&s->pb, 1, 0); //broken link == NO
1585

  
1586
    ff_mpeg4_stuffing(&s->pb);
1587
}
1588

  
1589
static void mpeg4_encode_visual_object_header(MpegEncContext * s){
1590
    int profile_and_level_indication;
1591
    int vo_ver_id;
1592
    
1593
    if(s->max_b_frames || s->quarter_sample){
1594
        profile_and_level_indication= 0xF1; // adv simple level 1
1595
        vo_ver_id= 5;
1596
    }else{
1597
        profile_and_level_indication= 0x01; // simple level 1
1598
        vo_ver_id= 1;
1599
    }
1600
    //FIXME levels
1601

  
1602
    put_bits(&s->pb, 16, 0);
1603
    put_bits(&s->pb, 16, VOS_STARTCODE);
1604
    
1605
    put_bits(&s->pb, 8, profile_and_level_indication);
1606
    
1607
    put_bits(&s->pb, 16, 0);
1608
    put_bits(&s->pb, 16, VISUAL_OBJ_STARTCODE);
1609
    
1610
    put_bits(&s->pb, 1, 1);
1611
        put_bits(&s->pb, 4, vo_ver_id);
1612
        put_bits(&s->pb, 3, 1); //priority
1613
 
1614
    put_bits(&s->pb, 4, 1); //visual obj type== video obj
1615
    
1616
    put_bits(&s->pb, 1, 0); //video signal type == no clue //FIXME
1617

  
1618
    ff_mpeg4_stuffing(&s->pb);
1619
}
1620

  
1621
static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number)
1568 1622
{
1569
    int vo_ver_id=2; //must be 2 if we want GMC or q-pel
1623
    int vo_ver_id;
1570 1624
    char buf[255];
1571 1625

  
1572
    if(s->max_b_frames){
1626
    if(s->max_b_frames || s->quarter_sample){
1627
        vo_ver_id= 5;
1573 1628
        s->vo_type= ADV_SIMPLE_VO_TYPE;
1574 1629
    }else{
1630
        vo_ver_id= 1;
1575 1631
        s->vo_type= SIMPLE_VO_TYPE;
1576 1632
    }
1577 1633

  
1578 1634
    put_bits(&s->pb, 16, 0);
1579
    put_bits(&s->pb, 16, 0x100);        /* video obj */
1635
    put_bits(&s->pb, 16, 0x100 + vo_number);        /* video obj */
1580 1636
    put_bits(&s->pb, 16, 0);
1581
    put_bits(&s->pb, 16, 0x120);        /* video obj layer */
1637
    put_bits(&s->pb, 16, 0x120 + vol_number);       /* video obj layer */
1582 1638

  
1583 1639
    put_bits(&s->pb, 1, 0);		/* random access vol */
1584 1640
    put_bits(&s->pb, 8, s->vo_type);	/* video obj type indication */
......
1621 1677
    put_bits(&s->pb, 1, 1);		/* obmc disable */
1622 1678
    if (vo_ver_id == 1) {
1623 1679
        put_bits(&s->pb, 1, s->vol_sprite_usage=0);		/* sprite enable */
1624
    }else{ /* vo_ver_id == 2 */
1680
    }else{
1625 1681
        put_bits(&s->pb, 2, s->vol_sprite_usage=0);		/* sprite enable */
1626 1682
    }
1627 1683
    
......
1665 1721
    int time_div, time_mod;
1666 1722
    
1667 1723
    if(s->pict_type==I_TYPE){
1668
        if(picture_number==0 || !s->strict_std_compliance)
1669
            mpeg4_encode_vol_header(s);
1724
        if(picture_number - s->last_vo_picture_number >= 300 || picture_number==0){
1725
            mpeg4_encode_visual_object_header(s);
1726
            mpeg4_encode_vol_header(s, 0, 0);
1727

  
1728
            s->last_vo_picture_number= picture_number;
1729
        }
1730
        mpeg4_encode_gop_header(s);
1670 1731
    }
1671 1732
    
1672 1733
    s->partitioned_frame= s->data_partitioning && s->pict_type!=B_TYPE;
......
1674 1735
//printf("num:%d rate:%d base:%d\n", s->picture_number, s->frame_rate, FRAME_RATE_BASE);
1675 1736
    
1676 1737
    put_bits(&s->pb, 16, 0);	        /* vop header */
1677
    put_bits(&s->pb, 16, 0x1B6);	/* vop header */
1738
    put_bits(&s->pb, 16, VOP_STARTCODE);	/* vop header */
1678 1739
    put_bits(&s->pb, 2, s->pict_type - 1);	/* pict type: I = 0 , P = 1 */
1679 1740

  
1680 1741
    time_div= s->time/s->time_increment_resolution;
......
4147 4208
#endif
4148 4209
}
4149 4210

  
4211
static int mpeg4_decode_gop_header(MpegEncContext * s, GetBitContext *gb){
4212
    int hours, minutes, seconds;
4213

  
4214
    hours= get_bits(gb, 5);
4215
    minutes= get_bits(gb, 6);
4216
    skip_bits1(gb);
4217
    seconds= get_bits(gb, 6);
4218

  
4219
    s->time_base= seconds + 60*(minutes + 60*hours);
4220

  
4221
    skip_bits1(gb);
4222
    skip_bits1(gb);
4223
    
4224
    return 0;
4225
}
4226

  
4150 4227
static int decode_vol_header(MpegEncContext *s, GetBitContext *gb){
4151 4228
    int width, height, vo_ver_id;
4152 4229

  
......
4504 4581
    }
4505 4582
    
4506 4583
    s->current_picture.pts= s->time*1000LL*1000LL / s->time_increment_resolution;
4584
    if(s->avctx->debug&FF_DEBUG_PTS)
4585
        printf("MPEG4 PTS: %f\n", s->current_picture.pts/(1000.0*1000.0));
4507 4586
    
4508 4587
    if(check_marker(gb, "before vop_coded")==0 && s->picture_number==0){
4509 4588
        printf("hmm, seems the headers arnt complete, trying to guess time_increment_bits\n");
......
4668 4747
        if((startcode&0xFFFFFF00) != 0x100)
4669 4748
            continue; //no startcode
4670 4749
        
4750
        if(s->avctx->debug&FF_DEBUG_STARTCODE){
4751
            printf("startcode: %3X ", startcode);
4752
            if     (startcode<=0x11F) printf("Video Object Start");
4753
            else if(startcode<=0x12F) printf("Video Object Layer Start");
4754
            else if(startcode<=0x13F) printf("Reserved");
4755
            else if(startcode<=0x15F) printf("FGS bp start");
4756
            else if(startcode<=0x1AF) printf("Reserved");
4757
            else if(startcode==0x1B0) printf("Visual Object Seq Start");
4758
            else if(startcode==0x1B1) printf("Visual Object Seq End");
4759
            else if(startcode==0x1B2) printf("User Data");
4760
            else if(startcode==0x1B3) printf("Group of VOP start");
4761
            else if(startcode==0x1B4) printf("Video Session Error");
4762
            else if(startcode==0x1B5) printf("Visual Object Start");
4763
            else if(startcode==0x1B6) printf("Video Object Plane start");
4764
            else if(startcode==0x1B7) printf("slice start");
4765
            else if(startcode==0x1B8) printf("extension start");
4766
            else if(startcode==0x1B9) printf("fgs start");
4767
            else if(startcode==0x1BA) printf("FBA Object start");
4768
            else if(startcode==0x1BB) printf("FBA Object Plane start");
4769
            else if(startcode==0x1BC) printf("Mesh Object start");
4770
            else if(startcode==0x1BD) printf("Mesh Object Plane start");
4771
            else if(startcode==0x1BE) printf("Still Textutre Object start");
4772
            else if(startcode==0x1BF) printf("Textutre Spatial Layer start");
4773
            else if(startcode==0x1C0) printf("Textutre SNR Layer start");
4774
            else if(startcode==0x1C1) printf("Textutre Tile start");
4775
            else if(startcode==0x1C2) printf("Textutre Shape Layer start");
4776
            else if(startcode==0x1C3) printf("stuffing start");
4777
            else if(startcode<=0x1C5) printf("reserved");
4778
            else if(startcode<=0x1FF) printf("System start");
4779
            printf(" at %d\n", get_bits_count(gb));
4780
        }
4781

  
4671 4782
        switch(startcode){
4672 4783
        case 0x120:
4673 4784
            decode_vol_header(s, gb);
4674 4785
            break;
4675
        case 0x1b2:
4786
        case USER_DATA_STARTCODE:
4676 4787
            decode_user_data(s, gb);
4677 4788
            break;
4678
        case 0x1b6:
4789
        case GOP_STARTCODE:
4790
            mpeg4_decode_gop_header(s, gb);
4791
            break;
4792
        case VOP_STARTCODE:
4679 4793
            return decode_vop_header(s, gb);
4680 4794
        default:
4681
//            printf("startcode %X found\n", startcode);
4682 4795
            break;
4683 4796
        }
4684 4797

  
libavcodec/mpeg4data.h
27 27
#define MB_TYPE_B_BACKW  2
28 28
#define MB_TYPE_B_FORW   3
29 29

  
30
#define VOS_STARTCODE        0x1B0
31
#define USER_DATA_STARTCODE  0x1B2
32
#define GOP_STARTCODE        0x1B3
33
#define VISUAL_OBJ_STARTCODE 0x1B5
34
#define VOP_STARTCODE        0x1B6
35

  
30 36
/* dc encoding for mpeg4 */
31 37
const UINT8 DCtab_lum[13][2] =
32 38
{
libavcodec/mpegvideo.h
435 435
    INT8 (*field_select_table)[2];   /* wtf, no really another table for interlaced b frames */
436 436
    int t_frame;                     /* time distance of first I -> B, used for interlaced b frames */
437 437
    int padding_bug_score;           /* used to detect the VERY common padding bug in MPEG4 */
438
    int last_vo_picture_number;      /* last picture number for which we added a VOS/VO/VOL header */
438 439

  
439 440
    /* divx specific, used to workaround (many) bugs in divx5 */
440 441
    int divx_version;
tests/ffmpeg.regression.ref
11 11
f3bc40b0a09eb06504fa5b51eb9135ee *./data/out.yuv
12 12
a11e0b741fa3c7fc491fb58ab8f7ca8d *./data/a-h263p.avi
13 13
615e3db2bdc535ca5b17996b29cabf24 *./data/out.yuv
14
5d7af332678d590e921064337ecde8ac *./data/a-odivx.avi
14
466e2365c9027dea8695cf205adf3b9d *./data/a-odivx.avi
15 15
3ede54eadc97f43b4ab260faeb5e8674 *./data/out.yuv
16
9638438b206816d6cca55a2f822abc24 *./data/a-mpeg4-rc.avi
16
5811f89254bc1f59528247f3daf11c1f *./data/a-mpeg4-rc.avi
17 17
d34057ff0806320c8be54fe34210c937 *./data/out.yuv
18
4be05fbae92279715a3e88feec87da8e *./data/a-mpeg4-adv.avi
18
5fa5a878e036d459edd08d873af6a03e *./data/a-mpeg4-adv.avi
19 19
59d969f054ed466da9bc9b4c211620fb *./data/out.yuv
20 20
2846c8e3d97d7395eb746bfce44e0443 *./data/a-mjpeg.avi
21 21
278033451d7a6bfeb8339abbe4228499 *./data/out.yuv

Also available in: Unified diff