January 20, 2022, 08:32:04 PM

News:

--


Merging MP4 files corrupts second file

Started by VulcanTourist, January 03, 2022, 10:47:23 PM

Previous topic - Next topic

VulcanTourist

I'm quite new to Avidemux; I've had it installed for many years but haven't made routine use of it.  Today I needed its skillset, however.  I had three pairs of videos that I needed to merge, so that Plex and other tools would correctly recognize them.  First, I updated to version 2.8.

I selected the first file, then dropped the second file of the first pair onto it.  The second file appeared correctly appended.  I chose the default Copy options, and selected MP4 as the output container.

The resulting file appeared to be a seamless merging of the two parts; perfect!  I even then managed to use another tool to merge the two separate subtitle files, with a correct offset, into a single subtitle file.  Awesome!

I thought I had the workflow figured out at this point.  Then disaster struck....

I queued up the next pair of MP4 files, and followed the exact same process.  Within Avidemux's playback viewport everything looked perfect.  The end result, however, was that the content of the second file was corrupted, several lines of shifting color bars at the top and then the rest of the space occupied by vertical shifting color gradients.

I tried switching to an MKV container, but got the same result.  I moved on to the third pair of videos, but still got the same result.

What am I doing wrong?

eumagga0x2a

Merging in copy mode presumes that codec extradata of all merged videos matches perfectly. Avidemux checks some decode parameters, but as far as I remember not all.

Please start Avidemux, load the first MP4 video, press Alt+Return, copy the hexdump of the first 64 bytes of extradata to a text file, close the video, load the next one, repeat the procedure.

Now check whether both hexdumps are identical. If they differ, you absolutely cannot merge these videos in copy mode.

If they both are 64 bytes long and match despite the second video not being decoded properly after merging, please compare the full extradata for each of the videos printed to admlog.txt in %localappdata%\avidemux directory as differing parts can be located beyond the limit of 64 bytes displayed in the properties dialog.

If extradata matches perfectly but the end result is bad, I'd need to have a look at the real files which behave that strangely.

VulcanTourist

January 05, 2022, 12:53:58 AM #2 Last Edit: January 05, 2022, 12:59:11 AM by VulcanTourist
Quote from: eumagga0x2a on January 03, 2022, 11:35:37 PMMerging in copy mode presumes that codec extradata of all merged videos matches perfectly. Avidemux checks some decode parameters, but as far as I remember not all.

Please start Avidemux, load the first MP4 video, press Alt+Return, copy the hexdump of the first 64 bytes of extradata to a text file, close the video, load the next one, repeat the procedure.

Now check whether both hexdumps are identical. If they differ, you absolutely cannot merge these videos in copy mode.

If they both are 64 bytes long and match despite the second video not being decoded properly after merging, please compare the full extradata for each of the videos printed to admlog.txt in %localappdata%\avidemux directory as differing parts can be located beyond the limit of 64 bytes displayed in the properties dialog.

If extradata matches perfectly but the end result is bad, I'd need to have a look at the real files which behave that strangely.
I copied the extra data of two that wouldn't merge:
=====================================================
Video Codec Extradata
=====================================================
Size: 43
Extradata: 01 64 00 29 FF E1 00 1B 67 64 00 29 AC D9 40 50 05 BA 6A 02 02 02 80 00 00 03 00 80 01 5F 90 07 8C 18 CB 01 00 05 68 EF 86 F2 C0
=====================================================
Video Codec Extradata
=====================================================
Size: 43
Extradata: 01 64 00 29 FF E1 00 1B 67 64 00 29 AC D9 40 50 05 BA 6A 02 02 02 80 00 00 03 00 80 01 5F 90 07 8C 18 CB 01 00 05 68 EF 87 F2 C0
=====================================================

As you can see, the extra data almost matches, differing only in the third to last hex value, and then only by a value of one.  Is there a way to fix this?

Interestingly, the first two videos that did merge successfully both have extra data that matches both each other and the first of the two videos above, but not the second video above.  That three all match but not the fourth suggests a bit of corruption?
=====================================================
Video Codec Extradata
=====================================================
Size: 43
Extradata: 01 64 00 29 FF E1 00 1B 67 64 00 29 AC D9 40 50 05 BA 6A 02 02 02 80 00 00 03 00 80 01 5F 90 07 8C 18 CB 01 00 05 68 EF 86 F2 C0
=====================================================
Video Codec Extradata
=====================================================
Size: 43
Extradata: 01 64 00 29 FF E1 00 1B 67 64 00 29 AC D9 40 50 05 BA 6A 02 02 02 80 00 00 03 00 80 01 5F 90 07 8C 18 CB 01 00 05 68 EF 86 F2 C0
=====================================================

eumagga0x2a

Quote from: VulcanTourist on January 05, 2022, 12:53:58 AMAs you can see, the extra data almost matches, differing only in the third to last hex value, and then only by a value of one.  Is there a way to fix this?

If the first video was created by x264 which records its configuration in the stream (MediaInfo application shows it), you could try re-encoding just the deviating video using exactly the configuration recreated from this record and see whether the resulting video gets matching extradata. Else the only solution is to re-encode both videos rather than using copy mode.

If Avidemux doesn't warn about mismatch on its own, the compatibility check needs to be extended in future versions => on my todo list.

eumagga0x2a

Quote from: VulcanTourist on January 05, 2022, 12:53:58 AMThat three all match but not the fourth suggests a bit of corruption?

To address this: no, absolutely not. If just video codec extradata of the appended video suffered bit-flip, video players would play the merged file without a hitch. It is really so that the internal structure of all frames (explained to the decoder by codec extradata) is different and "doesn't make sense" when interpreted based on the extradata from the first video.

VulcanTourist

Thankfully, the problem has been rendered moot: I found other files that I was able to merge with Copy without a hitch.  I am glad that Avidemux exists to enable me to do it at all.