Search code examples
mp4http-live-streamingfmp4

Is it possible to reorder and recombine fragments in fmp4?


I have fragmented mp4 which I want to send users through HLS. It's ok if I just send it as is. But I need opportunity to reorder fragments in this video.

For example initial video, which looks like this: original video format

I want reorganize fragments and get this: expected video format

I try make it locally, and it's work in VLS player (HLS). For this I modified sequence number for fragments in moof (mfhd). But when I try play it remotely (HLS) it does not work. I think, that some players (js) expect some additional information from each fragment, probably for example time offset. But I can not find which atom (box) contain this information. I spent a lot of time searching and I'm still at the very beginning of the problem.

I tried to modify the fragment sequence number, but it doesn't work.


Solution

  • The "Track Fragment Media Decode Time Box" (tfdt) stores the baseMediaDecodeTime which is the accumulative decode time.

    Consider the following...

    • baseMediaDecodeTime must increase monotonically for each chunk.

    • This means you must update (replace) the tfdt entry of chunk with expected next tftd entry.

    • When you naively reorder the chunks, the baseMediaDecodeTime will be invalid.

    The "Track Fragment Media Decode Time Box" (tfdt) is located inside each moof header at:

    moof --> traf --> tfdt