News:

--

Main Menu

MP4 Copy mode produces corrupt video

Started by niczoom, May 27, 2019, 01:24:30 PM

Previous topic - Next topic

niczoom

Hi,

I'm appending 2 videos (Copy only) together by selecting 'Copy' from both the Video & Audio Outputs. The resulting 'merged' video is partly corrupted. The 2nd appended video is the corrupted part.

The first video was shot on my Sony X3000 Handycam, 1920x1080 50fps MP4, MediaInfo: CodecID=MSNV. The 2nd video was shot on my Panasonic FZ1000, 1920x1080 50fps MP4, MediaInfo: CodecID=mp42. I've attached the MediaInfo from both video files.

I can see some differences within the MediaInfo results which may be why Avidemux is having this problem. But when using MP4Joiner the resulting video file works, it is not corrupt, even when skipping through.

When using the file in Avidemux and appending another video from the FZ1000 the resulting file plays fine but when skipped the video corrupts. When editing this file (along with more appended files) Avidemux has issues when skipping forward and backwards through the joined file from above.

Is it impossible to join these 2 MP4 files together without re-encoding 1 type to match the other first?







eumagga0x2a

For saving of appended videos in copy mode to produce correctly playable files, codec settings (the extradata) of all source videos must perfectly match. In your case, already the H.264 profiles are different.

If the output of mp4joiner is playable, I strongly suspect that it re-encodes the video in the process.

niczoom

QuoteIf the output of mp4joiner is playable, I strongly suspect that it re-encodes the video in the process.
I'm sure that it doesn't re-encode as the process of joining is very quick and there is very low CPU usage.

I've attached a MediaInfo report (if you're interested) of a joined file using 'MP4 Joiner'.

The joined video contains the FZ1000 video 1st then the Handycam footage 2nd. When using it in Avidemux I can scroll forward through all the video then back through the Handycam footage but when I get to the FZ1000 footage the screen displays solid grey. When I then scroll forward again and get to the Handycam footage it displays properly.

eumagga0x2a

Quote from: niczoom on May 27, 2019, 11:37:51 PM
I've attached a MediaInfo report (if you're interested) of a joined file using 'MP4 Joiner'.

The joined video contains the FZ1000 video 1st then the Handycam footage 2nd. When using it in Avidemux I can scroll forward through all the video then back through the Handycam footage but when I get to the FZ1000 footage the screen displays solid grey. When I then scroll forward again and get to the Handycam footage it displays properly.

This means that it is not playable (decodable) correctly, which is normal and expected when the source video extradata doesn't match. What is somewhat unexpected is that mp4joiner seems to use the codec configuration from the second video for the output file. Avidemux always uses the extradata from the first one loaded. It is impossible to make both parts of the output work as the decoder is initialized with extradata only once.

niczoom

QuoteThe joined video contains the FZ1000 video 1st then the Handycam footage 2nd.

My mistake, it's the other way around! Handycam 1st then FZ1000.

Using MP4Box I got the following results:

Sony X3000 HandyCam MP4:

mp4box "2018 06 28    19-07-41 - .MP4" -info
Average GOP length: 49 samples

.\ffprobe -show_frames "2018 06 28    19-07-41 - .MP4" | findstr pict_type
pict_type=I
pict_type=P x23
pict_type=I

FZ1000 MP4:
mp4box "2018 06 28    19-24-24 - .MP4" -info
Average GOP length: 25 samples

.\ffprobe -show_frames "2018 06 28    19-24-24 - .MP4" | findstr pict_type
pict_type=B
pict_type=B
pict_type=I
pict_type=B
pict_type=B

pict_type=P -
pict_type=B -
pict_type=B - This block x7

pict_type=I

Would it be easier to just reencode all the videos as I'm cutting and joining them together?

Or reencode 1 format to match the other than use the 'Copy' method as I was before?

eumagga0x2a

Quote from: niczoom on May 28, 2019, 07:34:48 AM
QuoteThe joined video contains the FZ1000 video 1st then the Handycam footage 2nd.

My mistake, it's the other way around! Handycam 1st then FZ1000.

Taking the output of MediaInfo into account, everything is exactly as expected.

QuoteWould it be easier to just reencode all the videos as I'm cutting and joining them together?

Yes. Not just easier but often the only practicable solution.

QuoteOr reencode 1 format to match the other than use the 'Copy' method as I was before?

If preserving the original quality for the video which won't end up being re-encoded is the highest priority and your time doesn't matter, you could try to play with x264 encoder settings until you get a match (use just a few seconds of the video for testing). Avidemux prints hexdump of video extradata to the log.

niczoom

Using the MP4 AVC x264 encoder, in 'Frames/B-Frames' I set both to '0', and in 'Frames/I-Frames' I set the Min/Max to 1/24, once encoded this gave me both I & P frames matching the original sample. I used this with the other video but it did not work.

QuoteAvidemux prints hexdump of video extradata to the log
I had a look in the log and saw the hex dump. Could this help me in some way? I'm not sure what to do with it?

eumagga0x2a

You must also set the H.264 profile to match the first video.

Regarding the extradata, copy the hexdump starting with the line

[Editor]The video codec has some extradata

out of the Avidemux log file for the first video to a new text file as a reference. Experiment with x264 settings re-encoding a short sequence (e.g. 1 minute) of the second video until the hex dump of extradata printed to the log when loading the resulting file exactly matches the reference.

niczoom

QuoteYou must also set the H.264 profile to match the first video.
In the x264 Configuration/General tab the 'Profile' setting is greyed out unless 'Use advanced configuration' is unchecked. When this done then all other settings in the other tabs are greyed out and not accessible.

I tried this before: I unchecked 'Use advanced configuration' and set the profile to Main 4.2 which matches the Camcorder profile, but this takes away the ability to control the B+I frames in the 'Frame' tab, which I assumed is what I have to do to match the Camcorder I-Frames position?

I also unchecked 'Use advanced configuration' and set the profile to Main 4.2 then re-checked it so I could control the settings in the 'Frame' tab but this just defaults back to the 'High' profile once encoded.

I'll have another play around looking at the 'extra data' and see what comes of it.