videoffmpegmp4h.264mp4box

MP4 moof fragment headers


I have a MP4 parser software that get's a fragmented .mp4 video, parses the MOOV and fragment headers and streams it. I have generated a .mp4 file myself using FFMPEG and MP4Box/bento4, but the software has problems processing it.

ffmpeg -i input.mp4 -g 25 -c:v libx264 -c:a copy out1.mp4

mp4fragment out1.mp4 --fragment-duration 1000 --track 'video' output.mp4

Using the MP4 Explorer software, I noticed in my generated .mp4 file, for all moof.traf.trun, sample duration is set to 0, but in the Track Fragment Header box, it sets the default_sample_duration to 512. While in the another .mp4 file which works fine, there is no default_sample_duration field, but each individual sample has a duration of size 512. Looks like this might cause the problem. The right figure shows the working mp4, and the left one is my generated mp4.

Is this an update in the newer versions of FFMPEG (or MP4Box or bento4)? Is there any ways to force setting the sample duration in samples?

My .mp4 file

The working .mp4 file

enter image description here


Solution

    1. parse the TFHD
    2. extract the default_sample_duration
    3. use the default_sample_duration instead of the absent duration from TRUN