Log in

View Full Version : Tool for *Nicely* Concatenating MP4s?


CarlEdman
11th November 2011, 23:32
Is there a tool which nicely concatenates MP4s?

By nicely, I mean not just taking each track and spitting out a concatenated output, but which deals properly with issues like certain audio or video tracks not being exactly the same length in each component. These differences are usually small (a second or less), but if you just concatenate the tracks individually you will often get noticeable de-sync on subsequent component parts. To avoid that, such a tool would have to be able to either (1) mix audio/video at the boundary (presumably difficult, in particular for video without recoding), (2) insert silence and black frames as needed (presumably easier, but not entirely trivial), or (3), perhaps, deal with time codes cleverly.

A perfect tool would also do the right thing with respect to other types of tracks like chapters (perhaps even inserting a chapter mark at each merge point) and subtitles in the various formats.

MP4box, last time I tested it, did not deal with these issues gracefully.

A CLI tool would be fine (in fact, preferred).:thanks:

Dmitry Vergheles
15th November 2011, 20:09
Hi CarlEdman,

You can check our editor that is able to join MP4 files and add silence to audio tracks if necessary.
http://www.solveigmm.com/download/SolveigMM_Video_Splitter_3_0_Beta.exe

CarlEdman
15th November 2011, 20:23
Thank you, Dmitry, for the suggestion. Unfortunately I have a fair number of files to concatenate and doing everything by hand would be a pain. What I'd really love is a CLI tool something along the lines of:
mp4cat file1.mp4 file2.mp4 ... file.mp4
In the end file.mp4 would contain all the video from all the files, with chapter marks inserted at each point (ideally preserving pre-existing chapter marks), and with the audio at the cut point expanded or trimmed as appropriate.
mp4cat --spacer spacer.mp4 ...
Might be even better with spacer.mp4 a blank, short (e.g., 1 second), silent video mp4 inserted between each component. Then trimming would hardly ever be necessary. Come to think of it, give me a day and I'd probably be able to whip something like that up with python, mp4box, and the mp4v2 tools...

Dmitry Vergheles
16th November 2011, 14:46
Hi CarlEdman,

In fact the Splitter has CLI but it eatc xml script as an input
http://www.solveigmm.com/en/faq/how-the-splitter-operates-in-command-line-mode/

If you need a merhing for some commercial project you can use our Ediring SDK to build own CLI, or we can make a CLI you need
http://www.solveigmm.com/en/products/video-editing-sdk/

Dmitry Vergheles
16th November 2011, 14:52
Might be even better with spacer.mp4 a blank, short (e.g., 1 second), silent video mp4 inserted between each component

That's not so easy to implement as a black frames should be encoded with the same params as an input stream, though as we are foing re-encoding of a part of a GOP just alike, it is doable.
Though it does not makes sense, as AVC has variable framerate and if is is a gap between last frame and next concatenated frame (if audio longer than video) it is just enough to set correct time stamp to a next frame and a decoder will just show a last frame (of 1st file) so long as an audio track requires.