mp4v2封装函数H264中 MP4WriteSample参数问题

来源:互联网 发布:女装原单淘宝店 编辑:程序博客网 时间:2024/05/23 21:53

Ottavio Campana 
“question about MP4AddH264VideoTrack。
What's the meaning of the profile_compat and 
sampleLenFieldSizeMinusOne fields?”

Jeremy Noring
"Usually an NALU is prefixed by the start code 0x00000001. To write it 
as a sample in MP4 file format, just replace the start code with size 
of the NALU(without 4-byte start code) in big endian. You also need to 
specify how many bytes of the size value requires. Take libmp4v2 for 
example, the last parameter in MP4AddH264VideoTrack(.., uint8_t 
sampleLenFieldSizeMinusOne) indicate the number of byes minus one." 

...so each sample you and to mp4v2 should be prefixed with a size code 
(in big-endian, of course). I use a 4 byte size code, so 
sampleLenFieldSizeMinusOne gets set to 3. This seems to work; my 
files playback on just about everything. Perhaps one of the project 
maintainers can clarify this, and it'd also be good to update the 
documentation of that call to make this clear.”

Ottavio Campana 
that's the code I used as reference to write my program :-( 
but my doubt is that there must be something wrong somewhere, because 
boxes seem to be correctly written, but when I try to decode them I 
get errors like 
[h264 @ 0xb40fa0]AVC: nal size -502662121 
have you ever seen an error like this?

Ottavio Campana 
> Not sure, but it looks you're not converting it to big-endian before 
> prefixing it to your sample. 
well, eventually using ffmpeg to dump the read frames, I discovered 
that I had to strip che NALU start code, i.e. the 0x00000001, and to 
put the NALU size at its place. 
It works perfectly now, but I still wonder why I had to put the size 
at the begin of the data, since it is a parameter which is passed to 
MP4WriteSample, so I expected the function to add it.


所以

(1)h264流中的NAL,头四个字节是0x00000001;
(2)mp4中的h264track,头四个字节要求是NAL的长度,并且是大端顺序;


MP4WriteSample

 此函数接收I/P nalu,该nalu需要用4字节的数据大小头替换原有的起始头,并且数据大小为big-endian格式



0 0
原创粉丝点击