1

I'm trying to investigate an issue with an MP4 that I'm generating returning the error:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55f0ae819080] Failed to add index entry
Last message repeated 277 times
[h264 @ 0x55f0ae81c300] Invalid NAL unit size (-800932280 > 6).

The first frame decodes perfectly, and all future frames fail to decode. This results in a 0.042 second duration video.

To help with the investigation, I had ffmpeg encode the same video in the same way so I could compare the two files. I noticed, however, that in the ffmpeg-encoded file the video sample doesn't start with 0x000001 or 0x00000001.

I tried looking through the MP4 spec and the H.264 spec to understand why this start code is sometimes required but not required in this case, but there literally hundreds of pages and I couldn't find anything in a day of reading.

The ffmpeg-generated file is available here: http://files.stevendesu.com/test.mp4

If you open this with an MP4 atom parser you'll notice the first mdat atom starts:

0000 6DF4 6D64 6174 0000 04BF 6588 8101
1788 8C12 0001 1498 3800 188E 003F FFFC
...

The first 8 bytes make sense: 00006DF4 (28148) = the size of the mdat atom, 6D646174 = "mdat" in ASCII

After this the mdat atom starts with 0x000004. According to the traf atom in the preceding moof, the first video sample (with a duration of 800/16000 seconds and a size of 19899 bytes) should start exactly here. Therefore 0x000004 are the first 3 bytes of the first video sample.

Either this video sample doesn't start with a NALU start code, or there is some header / wrapper around the NALU that I don't understand.

Can anyone explain to me why this video sample doesn't start with a NALU start code?

stevendesu
  • 15,753
  • 22
  • 105
  • 182
  • 3
    mp4 does no originally contain start codes, check this answer for instance https://stackoverflow.com/a/29103276/1573638 – Michael Radionov Dec 14 '18 at 22:07
  • That's the key I was missing :) Annex-B versus AVCC. Thanks for the help. Now that I know to look at AVCC I may be able to make some sense of this error message. – stevendesu Dec 14 '18 at 22:24

1 Answers1

2

Only Annex-B files will contain the 000001 start code. I had AVCC data.

stevendesu
  • 15,753
  • 22
  • 105
  • 182