这是本文档旧的修订版!
MP4
参考
- ffmpeg\libavformat\movenc.c
文档
- 14496-12 14496-14 14496-15 下载要收费了, csdn 解决
14496-15 涉及h264 h265 流 的 stsd box 封装
- 14496-15-2017 5.4.2 讲述 h264 的 avc1-avcC box 结构,
avcC主要是AVCDecoderConfigurationRecord
, 这个见 5.3.3.1.2 - avc1 是
AVCSampleEntry
, 继承VisualSampleEntry
VisualSampleEntry
结构见 14496-12_2015 12.1.3.2class VisualSampleEntry(codingname) extends SampleEntry (codingname){ unsigned int(16) pre_defined = 0; const unsigned int(16) reserved = 0; unsigned int(32)[3] pre_defined = 0; unsigned int(16) width; unsigned int(16) height; template unsigned int(32) horizresolution = 0x00480000; // 72 dpi template unsigned int(32) vertresolution = 0x00480000; // 72 dpi const unsigned int(32) reserved = 0; template unsigned int(16) frame_count = 1; string[32] compressorname; template unsigned int(16) depth = 0x0018; int(16) pre_defined = -1; // other boxes from derived specifications CleanApertureBox clap; // optional PixelAspectRatioBox pasp; // optional }
aligned(8) abstract class SampleEntry (unsigned int(32) format) extends Box(format){ const unsigned int(8)[6] reserved = 0; unsigned int(16) data_reference_index; }
- H265 的 hev1 - hvcC box 结构 14496-15_2013 就有提及,在 8.4.1 章节, hvcC box 包含 `HEVCDecoderConfigurationRecord` 结构,具体见 8.3.3.1 章节 - `Compressorname` in the base class VisualSampleEntry indicates the name of the compressor used with the value "\013HEVC Coding" being recommended (\013 is 11, the length of the string in bytes). - `HEVCDecoderConfigurationRecord` 结构:
aligned(8) class HEVCDecoderConfigurationRecord {
unsigned int(8) configurationVersion = 1; unsigned int(2) general_profile_space; unsigned int(1) general_tier_flag; unsigned int(5) general_profile_idc; unsigned int(32) general_profile_compatibility_flags; unsigned int(48) general_constraint_indicator_flags; unsigned int(8) general_level_idc; bit(4) reserved = ‘1111’b; unsigned int(12) min_spatial_segmentation_idc; bit(6) reserved = ‘111111’b; unsigned int(2) parallelismType; bit(6) reserved = ‘111111’b; unsigned int(2) chromaFormat; bit(5) reserved = ‘11111’b; unsigned int(3) bitDepthLumaMinus8; bit(5) reserved = ‘11111’b; unsigned int(3) bitDepthChromaMinus8; bit(16) avgFrameRate; bit(2) constantFrameRate; bit(3) numTemporalLayers; bit(1) temporalIdNested; unsigned int(2) lengthSizeMinusOne; unsigned int(8) numOfArrays; for (j=0; j < numOfArrays; j++) { bit(1) array_completeness; unsigned int(1) reserved = 0; unsigned int(6) NAL_unit_type; unsigned int(16) numNalus; for (i=0; i< numNalus; i++) { unsigned int(16) nalUnitLength; bit(8*nalUnitLength) nalUnit; } }
}
一些分析
mp4 的主要box: mp4.png
fmp4 的moov box: 1ad5e6674df5579f3c7169a42f963988.png
组装fmp4的 moov box 必须获取视频流的 width, height, pps, sps
获取 pps sps:
- avc1 参考 ffmpeg 的 mov_write_video_tag 函数