qtmux: Wrong trun offset written for fragmented MP4 files
I've been trying to get GStreamer to generate fragmented MP4 files for some time but no matter what I tried, the files were always corrupt, so I decided to get to the bottom of this issue, and I believe I found it.
The problem is caused by this line: https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/blob/242f3cae6da748ac128e86b5cadcd406fa61aff6/gst/isomp4/gstqtmux.c#L4412
I think it is wrong in two different ways:
sizeis not the correct variable to use here, I think it contains the maximum size of the
databuffer, not the actual used bytes. I believe the correct variable would be
offset, as that is zeroed before the call to
atom_moof_copy_dataand contains the number of bytes copied.
size + 8is not sufficient, since
atom_trun_set_offsetadds another 4 bytes due to adding an optional u32 field. This should be either
offset + 12, or a dummy value should be written before calling
atom_trun_set_offset(first_trun, 0)) to reserve the bytes for the data offset field.
Does any of this make sense? If so, I could probably open a merge request to fix this bug, though it is only 1 or 2 lines that need to be changed.
With the fix applied, the MP4 files are playable and look fine.