mp4 stsd/mp4a/esds 和 mp4 stsd/avc1/avcc

时间:2025-03-09 11:04:47

原文:/?p=1134002

mp4 stsd/mp4a/esds

00 00 00 27 65 73 64 73 00 00 00 00 03 19 00 02 ; ...'esds........

00 04 11 40 15 00 06 00 00 01 F4 00 00 01 F4 00 ; ...@............

05 02 12 10 06 01 02                            ; .......

Atom Box:
00 00 00 27 (box size) 65 73 64 73 ('esds') 00 00 00 00 (version + flag)

ES descriptor:
03 (tag) 19 (tag size) 00 02 (track_id) 
00 (flag)

DecoderConfig descriptor:
04 (tag) 11 (tag size) 40 (MPEG-4 audio) 15 (audio stream) 00 06 00 (Buffersize DB)  00 01 F4 00 (max bitrate 128000) 00 01 F4 00 (avg bitrate 128000)

DecoderSpecific info descriptor
05 (tag) 02 (tag size) 12 10 (Audio Specific Config)

Audio Specific Config:
5 bits: object type
4 bits: frequency index
4 bits: channel configuration
1 bit: frame length flag
1 bit: dependsOnCoreCoder
1 bit: extensionFlag

Audio Object Types
MPEG-4 Audio Object Types:
0: Null
1: AAC Main
2: AAC LC (Low Complexity)
3: AAC SSR (Scalable Sample Rate)
4: ... 

Sampling Frequencies
0: 96000 Hz
1: 88200 Hz
2: 64000 Hz
3: 48000 Hz
4: 44100 Hz
5: ... 

Channel Configurations
0: Defined in AOT Specifc Config
1: 1 channel: front-center
2: 2 channels: front-left, front-right
3: 3 channels: front-center, front-left, front-right 
4: ...  

frame length flag:
0: Each packet contains 1024 samples
1: Each packet contains 960 samples

Example:
1210h = 000
10010 00010000b = 00010(AAC LC)  010 0 (44100Hz)  0010 (strero) 0 (1024 samples) 00 ( ? )

SL descriptor
06 (tag) 01 (tag size) 02 (always 2 refer from 
mov_write_esds_tag);

 

Reference:
ffmpeg-2.7/libavformat/  mov_write_esds_tag
/?title=Understanding_AAC
/?title=MPEG-4_Audio

mp4 stsd/avc1/avcc

00 00 00 34 61 76 63 43 01 64 00 28 FF E1 00 1C ; ....(....
67 64 00 28 AC 34 E4 00 80 06 FF 97 01 10 00 00 ; gd.(.4..€.......
03 00 10 00 00 03 03 00 F1 83 11 20 
01 00 05 68 ; ........... ...h
EF B2 C8 B0
 ; ....

00 00 00 34: box size
61 76 63 43: avc1
01 64 00 28: 01 (version) 64 (AVC profile_idc) 00 (AVC profile compatibility) 28 (AVC level indication) 
FF: FF /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */)
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. 

E1: E1 (/* 3 bits reserved (111) + 5 bits number of sps (00001) */)
00 1C: sps_size 28
67 64 00 ... : sps without start code (00 00 01)
01: number of pps
00 05: pps size
68 EF B2 C8 B0: pps 


Now you should write H264 bitstream to mdat section and startcode (00 00 01)insteaof nal size . And the nal size length is specified as FF. It's 4 bytes declared here. 

Example:
00 00 00 3F 41 9E 42 42 FF 00 00 03 00 00 03 00 ; ...?........
00 03 00 00 03 00 00 03 00 00 03 00 00 03 00 00 ; ................
03 00 00 03 00 00 03 00 00 03 00 00 03 00 00 03 ; ................
00 00 03 00 00 03 00 00 03 00 00 03 00 00 03 00 ; ................
00 EA 81                                        ; ...

00 00 00 3F is the length of  41 9E 42 42  ... 00 EA 81

 

Reference:
ffmpeg-2.7/libavformat/: ff_isom_write_avcc 
ISO/IEC 14496-15: /asp/admin/editor/newsfile/