Log in

View Full Version : Concatenation Conundrum - Apple Media Handler mp4


nopper
6th January 2016, 22:55
My attempt to concatenate some web clips (mp4 format, Apple Media Handler) appears to be initially successful - whether using ffmpeg, mkvmerge, or other tools.

The clips do concatenate and the a/v is in sync.

However, if the raw elementary h.264/aac streams are demuxed (for example, with mp4box) from the concatenated file - and then remuxed, the a/v sync is lost in the newly remuxed file (after the first concatenation point, and more noticeably after the third concatenation point).

My question is why is the a/v sync lost through a demux/remux step?

I suppose that I could just not demux/remux, but one of my device players deals better with a mp4box muxed mp4.

sneaker_ger
6th January 2016, 23:02
The sync can be lost because:
- different fps not accounted for
- video and audio of a given clip are of different lenths. E.g. video is 60 seconds, audio is 59 seconds. If you try to demux and append the single streams you will create a 1 second desync.

nopper
8th January 2016, 03:37
- video and audio of a given clip are of different lenths. E.g. video is 60 seconds, audio is 59 seconds. If you try to demux and append the single streams you will create a 1 second desync.

You nailed it. In one segment, the video duration is 00:08:13.727 while the audio duration is 00:08:13.692. All of the other segments have similar disparities.

So, what keeps the initial concatenation in sync? Only if I demux the initial concatenation and then remux the raw streams is the sync lost. What is lost in that process that is present in the initial concatenation?

I notice that if I use ffmpeg (with the initial concatenated file as the input) to transcode only the video but stream copy the audio, then the raw streams can be remuxed with full sync.

Is there another way around this issue without transcoding?

sneaker_ger
8th January 2016, 17:52
So, what keeps the initial concatenation in sync? Only if I demux the initial concatenation and then remux the raw streams is the sync lost. What is lost in that process that is present in the initial concatenation?
Mkv and mp4 have ways to account for irregularities like variable framerate and audio gaps in the streams. If you demux vital sync information can get lost.

Is there another way around this issue without transcoding?
I don't understand. You already know how:
My attempt to concatenate some web clips (mp4 format, Apple Media Handler) appears to be initially successful - whether using ffmpeg, mkvmerge, or other tools.

foxyshadis
11th January 2016, 14:21
You have to extract the timecodes and remux with them. (Shifting and concatenating all the timecodes to match your merged tracks, of course.) Unfortunately, while this is relatively straightforward for video, it's not something anyone's made for audio -- and whichever track is shorter needs the timestamps.

Can you just concatenate with ffmpeg, then remux that with mp4box? Seems like that would be enough.