axiomatic-systems / Bento4

Full-featured MP4 format, MPEG DASH, HLS, CMAF SDK and tools
http://www.bento4.com
1.97k stars 479 forks source link

mp4mux outputs empty mdat boxes #681

Open lfaureyt opened 2 years ago

lfaureyt commented 2 years ago

Hi, I am trying to use mp4mux to multiplex into a single MP4 file:

Each input file was obtained by mere concatenation of a dash init and a dash media segment from an unencrypted live DASH stream. The output file's ftyp and moov box seem consistent. However, despite the presence of audio and video (playable) media data in the input files, the output file's mdat box remains empty.

Is mp4mux lacking information about input samples ? Should I enrich the audio/video init segments with some information about the actual number of available samples to make this work ? (the entry_count, sample_count, duration, ... fields from input init segments are set to 0 because they are not known for live streams). Is there a simpler way to do this ? Thanks in advance for any guidance.

$ mp4mux --verbose --track video.mp4 --track audio.mp4 out.mp4
MP4 Import: importing all tracks from video.mp4
MP4 Import: importing all tracks from audio.mp4
$ mp4dump video.mp4 | grep mdat
[mdat] size=8+427457
$ mp4dump audio.mp4 | grep mdat
[mdat] size=8+23475
$ mp4dump out.mp4 | grep mdat
[mdat] size=8+0

https://user-images.githubusercontent.com/5099987/158215819-1b4a78d5-ebad-48aa-a035-003100551711.mp4

https://user-images.githubusercontent.com/5099987/158215823-cb692d09-e72b-4030-8331-cc6707285f26.mp4

barbibulle commented 2 years ago

I'll try with the examples provided and let you know ASAP.

barbibulle commented 2 years ago

The reason this produces an empty output here is because currently the mp4mux tool doesn't support reading input frames from fragmented mp4 files. When you add mp4 tracks to the mp4mux input list, the tracks get added 'as-is', not looking for fragments. Fragmented mp4 files do have tracks declared, but they usually have no samples of their own, all the samples are in subsequent tack fragments. It would be fairly easy to add support for reading track fragments as a supported input mode. I'll add that to the TODO list. How important is that use case for you?

lfaureyt commented 2 years ago

Thank you. I am creating some simple (not for production) diagnostics scripts for my own usage so this is not critical: don't assign a high prority to this enhancement. Still, maybe there's a simple modification (like moving some boxes around) I could apply to the init segment + track fragments to make them look like an actual mp4 track so that mp4mux could take their samples into account ?

Jssly commented 2 years ago

I am facing the same issue, hope it could be fixed soon