Concat mp4 files with a command line tool

960 views Asked by At

I am blocked trying to do something, and I'm ready to make a donation if somebody can help me:

I try to concat http://s.serero.free.fr/rolex.mp4 video and http://s.serero.free.fr/video.mp4 video in one output mp4 file and I tried during a big time without results.

I want to concat http://s.serero.free.fr/rolex.mp4 + http://s.serero.free.fr/video.mp4 or http://s.serero.free.fr/video.mp4 + http://s.serero.free.fr/rolex.mp4.

I tried with ffmpeg command line software and with mp4box command line software, I think that I don't have the good method.

I tried to transform http://s.serero.free.fr/video.mp4 in the same format of http://s.serero.free.fr/rolex.mp4 (and vice versa):

I transformed http://s.serero.free.fr/rolex.mp4 with the same frame rate of http://s.serero.free.fr/video.mp4

I transformed http://s.serero.free.fr/rolex.mp4 with the same video bitrate of http://s.serero.free.fr/video.mp4

I transformed http://s.serero.free.fr/rolex.mp4 with the same video audio bitrate of http://s.serero.free.fr/video.mp4

Can somebody help me?

Explain to me what is wrong in my strategy?

2

There are 2 answers

1
llogan On BEST ANSWER

Your input parameters vary, so you have to make them similar before concatenation.

  • rolex.mp4

    Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 835 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    
  • video.mp4

    Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1152x720, 1749 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, s16p, 127 kb/s (default)
    

This example will make video.mp4 more like rolex.mp4 then concat them:

ffmpeg -i rolex.mp4 -i video.mp4 -filter_complex \
"[1:v]pad=1280:720:(ow-iw)/2:0,fps=25,format=yuv420p[v1]; \
 [0:v][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" output.mp4

You don't actually need to declare fps or format because, as the concat filter documentation states:

All corresponding streams must have the same parameters in all segments; the filtering system will automatically select a common pixel format for video streams, and a common sample format, sample rate and channel layout for audio streams, but other settings, such as resolution, must be converted explicitly by the user.

...but doing so will allow you to manually choose the "common" settings instead of relying on the filter automatically doing so and potentially selecting a setting you don't want.

1
user1018697 On

Thanks for LordNeckbeard for his excellent answer, he just let a little mistake on the command, i just want to a little explanation :

If I want to concat video.mp4(1152X720) with rolex.mp4(1280X720), we must understand that "video.mp4" is the main video so the video(s) to concatene must have exactly the same frame size.

So before to do this operation you need to resize rolex.mp4 video with the same size like video.mp4 with ffmpeg :

ffmpeg -i rolex.mp4 -s 1152x720 -c:a copy newrolexsized.mp4

No video.mp4 and newrolexsized.mp4 has the same frame size, and you can use the command (spcifying pad=1152:720 => size of the main video):

ffmpeg -i video.mp4 -i newrolexsized.mp4 -filter_complex "[1:v]pad=1152:720:(ow-iw)/2:0,fps=25,format=yuv420p[v1];[0:v][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" out.mp4