question about MP4AddH264VideoTrack

1,355 views
Skip to first unread message

Ottavio Campana

unread,
Sep 11, 2009, 3:14:11 AM9/11/09
to mp4v2
What's the meaning of the profile_compat and
sampleLenFieldSizeMinusOne fields?

Jeremy Noring

unread,
Sep 11, 2009, 3:04:19 PM9/11/09
to mp4v2
On Sep 11, 12:14 am, Ottavio Campana <ocamp...@gmail.com> wrote:
> What's the meaning of the profile_compat and
> sampleLenFieldSizeMinusOne fields?

I'm not 100% certain because the official documentation is a bit
vague, but I found this:

http://fuzzylai.dynagrid.net/2008/02/correct-h264-sample-structure-in-mp4.html

"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

unread,
Sep 14, 2009, 4:36:56 AM9/14/09
to mp4v2
On Sep 11, 9:04 pm, Jeremy Noring <kid...@gmail.com> wrote:
> ...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.

I'm having a weird behaviour from the library. The file cannot be
played, but if I use mplayer to dump video and to play the nal units
it works.

I don't understand what's going on, but since I'm also getting the nal
units from the encoder with the start tag 00000001, could you please
post an example of code that you're using? I think I am missing
something, but I don't know what.....

Edward Groenendaal

unread,
Sep 14, 2009, 5:11:26 AM9/14/09
to mp...@googlegroups.com
The only example I can think
Of and that I'm familier with is the handbrake sourcecode. Take a look
At muxmp4.c it uses the library to create valid mp4 video files with
aac and ac3 audio.

You can find the source code fairly easily via google.

Cheers Ed.

Ottavio Campana

unread,
Sep 14, 2009, 5:43:09 AM9/14/09
to mp4v2
On Sep 14, 11:11 am, Edward Groenendaal <ed...@me.com> wrote:
> The only example I can think
> Of and that I'm familier with is the handbrake sourcecode. Take a look
> At muxmp4.c it uses the library to create valid mp4 video files with  
> aac and ac3 audio.
>
> You can find the source code fairly easily via google.

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?

Edward Groenendaal

unread,
Sep 14, 2009, 6:16:18 AM9/14/09
to mp...@googlegroups.com
All I can think of is checking your byte order and double checking
everything.

Cheers Ed.

Jeremy Noring

unread,
Sep 14, 2009, 11:44:54 AM9/14/09
to mp...@googlegroups.com

Not sure, but it looks you're not converting it to big-endian before prefixing it to your sample.

http://en.wikipedia.org/wiki/Endianness

Ottavio Campana

unread,
Sep 16, 2009, 6:36:36 AM9/16/09
to mp4v2
On Sep 14, 5:44 pm, Jeremy Noring <kid...@gmail.com> wrote:
> 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.
Reply all
Reply to author
Forward
0 new messages