Skip to content

Instantly share code, notes, and snippets.

@uupaa
Last active December 12, 2023 11:38
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save uupaa/8493378ec15f644a3d2b to your computer and use it in GitHub Desktop.
Save uupaa/8493378ec15f644a3d2b to your computer and use it in GitHub Desktop.
parse AVCDecoderConfigurationRecord example

以下は、AVCDecoderConfigurationRecord のバイトデータです。

ADDR    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
------ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
000000 00 00 00 2e 61 76 63 43 01 42 c0 1e ff e1 00 16
000010 67 42 c0 1e d9 02 04 68 40 00 00 03 01 40 00 00
000020 03 00 83 c5 8b 92 01 00 05 68 cb 83 cb 20

このバイト列は以下のようにデコードされます

bytes filed 値,説明
00 00 00 2e BoxSize 'avcC' の Box サイズ
61 76 63 43 BoxType 'avcC'
01 configurationVersion 通常は1です
42 AVCProfileIndication 0x42(66), AVCのプロファィル(profile_idc)です
66はBaseline profileです
c0 profile_compatibility SPS の互換性情報です
1e AVCLevelIndication 30, Level です。30 は 3.0 になります
ff lengthSizeMinusOne 111111 + 11, NALUnit の長さ部分のバイト数は通常4ですが、
1,2,4 byte にも変更できます。3は不正な値です。
実際のbyte数から1引いた値になります
e1 numOfSequenceParameterSets 111 + 00001, SPS のパラメタセット数です
00 16 sequenceParameterSetLength 0x0016(22). SPS NALU のバイト数です
67 42 .. 8b 92 sequenceParameterSetNALUnit 22byte の SPS NALU です
01 numOfPictureParameterSets 0x01. PPS NALU のパラメタセット数です
00 05 pictureParameterSetLength 0x05. PPS NALU のバイト数です
68 cb 83 cb 20 pictureParameterSetNALUnit 5byte の PPS NALU です

バイト列にマッピングし直すとこのようになります。

ADDR    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
------ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
000000 00 00 00 2e 61 76 63 43 01 42 c0 1e ff e1 00 16
       ~~~~~~~~~~~                                      -> BoxSize
                   ~~~~~~~~~~~                          -> BoxType
                               ~~                       -> configurationVersion
                                  ~~                    -> AVCProfileIndication
                                     ~~                 -> profile_compatibility
                                        ~~              -> AVCLevelIndication
                                           ~~           -> lengthSizeMinusOne
                                              ~~        -> numOfSequenceParameterSets
                                                 ~~~~~  -> sequenceParameterSetLength
000010 67 42 c0 1e d9 02 04 68 40 00 00 03 01 40 00 00
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  -> sequenceParameterSetNALUnit
000020 03 00 83 c5 8b 92 01 00 05 68 cb 83 cb 20
       ~~~~~~~~~~~~~~~~~                                -> sequenceParameterSetNALUnit
                         ~~                             -> numOfPictureParameterSets
                            ~~~~~                       -> pictureParameterSetLength
                                  ~~~~~~~~~~~~~~        -> pictureParameterSetNALUnit

規格書(ISO/IEC 14496-15) の該当部分からの引用です。

5.2.4.1.1 Syntax
aligned(8) class AVCDecoderConfigurationRecord {
    unsigned int(8) configurationVersion = 1;
    unsigned int(8) AVCProfileIndication;
    unsigned int(8) profile_compatibility;
    unsigned int(8) AVCLevelIndication;
    bit(6) reserved = ‘111111’b;
    unsigned int(2) lengthSizeMinusOne;
    bit(3) reserved = ‘111’b;
    unsigned int(5) numOfSequenceParameterSets;
    for (i=0; i< numOfSequenceParameterSets; i++) {
      unsigned int(16) sequenceParameterSetLength ;
      bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit;
    }
    unsigned int(8) numOfPictureParameterSets;
    for (i=0; i< numOfPictureParameterSets; i++) {
      unsigned int(16) pictureParameterSetLength;
      bit(8*pictureParameterSetLength) pictureParameterSetNALUnit;
    }
}
  • AVCProfileIndication contains the profile code as defined in ISO/IEC 14496-10. profile_compatibility is a byte defined exactly the same as the byte which occurs between the
  • profile_IDC and level_IDC in a sequence parameter set (SPS), as defined in ISO/IEC 14496-10.
  • AVCLevelIndication contains the level code as defined in ISO/IEC 14496-10.
  • lengthSizeMinusOne indicates the length in bytes of the NALUnitLength field in an AVC video sample or AVC parameter set sample of the associated stream minus one. For example, a size of one byte is indicated with a value of 0. The value of this field shall be one of 0, 1, or 3 corresponding to a length encoded with 1, 2, or 4 bytes, respectively.
  • numOfSequenceParameterSets indicates the number of SPSs that are used as the initial set of SPSs for decoding the AVC elementary stream.
  • sequenceParameterSetLength indicates the length in bytes of the SPS NAL unit as defined in ISO/IEC 14496-10.
  • sequenceParameterSetNALUnit contains a SPS NAL unit, as specified in ISO/IEC 14496-10. SPSs shall occur in order of ascending parameter set identifier with gaps being allowed.
  • numOfPictureParameterSets indicates the number of picture parameter sets (PPSs) that are used as the initial set of PPSs for decoding the AVC elementary stream.
  • pictureParameterSetLength indicates the length in bytes of the PPS NAL unit as defined in ISO/IEC 14496-10.
  • pictureParameterSetNALUnit contains a PPS NAL unit, as specified in ISO/IEC 14496-10. PPSs shall occur in order of ascending parameter set identifier with gaps being allowed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment