====== MP4 ======
==== 参考 ====
* https://www.cnblogs.com/chyingp/p/mp4-file-format.html
* https://lucius0.github.io/2018/01/16/archivers/media-study-08/
* ffmpeg\libavformat\movenc.c
==== 文档 ====
* 参考:https://www.cnblogs.com/codertian/p/8277965.html
* 文档下载:https://standards.iso.org/ittf/PubliclyAvailableStandards/index.html
* 14496-12 14496-14 14496-15 下载要收费了, csdn 解决
* {{ :public:it:iso_iec_14496-12_2015.pdf |}}
* {{ :public:it:iso_iec_14496-14-2020.pdf |}}
* {{ :public:it:iso_iec_14496-15_2013_avcff.pdf |}}
* {{ :public:it:标准iso-iec14496-15-2017.docx |}} 这个是在WPS里用图片型PDF经ORC扫描生成的,可能有错漏。查看时可比对2013版
* 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.2
class 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:
* {{:public:it:426ff9a882f84a3e8503e94c5fe6d7c9.png?|}}
* fmp4 的moov box:
* {{:public:it:a23fa461c3944c798e5e51355a976832.png|}}
* 组装fmp4的 moov box 必须获取视频流的 width, height, pps, sps
* 获取 pps sps:
* avc1 参考 ffmpeg 的 mov_write_video_tag 函数
==== 哥伦布编码 ====
* https://www.cnblogs.com/wangguchangqing/p/6297792.html
* Golomb编码,及其两个变种:Golomb-Rice和Exp-Golomb