5

I want to merge videos in batch size of twenty (20) each. I'm running a Linux machine. The videos are in mp4 format and moderate quality. Some even have the audio stream missing. So far I've tried ffmpeg, mencoder, cvlc/vlc and MP4Box. I want to write a command line script to achieve this, since I'm doing batch processing.

The main issue is that some of the solutions I tried work well for two videos, some work well for videos with audio stream and yet others work well for some other subset of my video set. However, I have not been able to find a comprehensive solution for this task.

Dhruv Singal
  • 158
  • 1
  • 2
  • 5
  • Here are some of the methods that I've tried so far: https://trac.ffmpeg.org/wiki/Concatenate `MP4Box -add video1.mp4 -cat video2.mp4 -cat video3.mp4 -new output.mp4` – Dhruv Singal Jun 16 '15 at 09:44
  • This question is more general computing than programming-related. You’d have a better chance of getting useful answers at [Super User](http://superuser.com/) or [Unix and Linux](http://unix.stackexchange.com/). – Anthony Geoghegan Jun 16 '15 at 09:50
  • 1
    Thank you, I didn't know that. – Dhruv Singal Jun 16 '15 at 09:54
  • Have you tried FFmpeg [`concat`](https://trac.ffmpeg.org/wiki/Concatenate) option? demuxer may work for you. – Chamath Jun 16 '15 at 10:07
  • I tried doing that. It doesn't work. Some videos are missing audio stream, which poses a problem. – Dhruv Singal Jun 16 '15 at 11:24

3 Answers3

3

If ffmpeg parameter usage seems complex and causes fear, just like it did to me, another alternative is mkvmerge.

For installation instructions, follow >> MKVToolNix

mkvmerge -o /path/to/file/output_file.mkv /path/to/file/01.mp4 \+ /path/to/file/02.mp4 \+ /path/to/file/03.mp4 \+ ...

PS: I had no chance to try this on different formatted media types.

LysanderM
  • 115
  • 1
  • 1
  • 6
1

FFmpeg is the best way to accomplish this from the command line using the concat filter. I tried 20+ different ways before I found this and it works like a charm. If the videos are without audio, your command would be:

ffmpeg -i vid-1.mp4 -i vid-2.mp4 -filter_complex '[0:v] [1:v] concat=n=2:v=1 [v]' -map '[v]' output.mp4

If the videos have audio, your command would be:

ffmpeg -i vid-1.mp4 -i vid-2.mp4 -ar 44100 -ab 64k -ac 1 -c:a libmp3lame -filter_complex '[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v]' -map '[v]' -map '[a]' output.mp4

You can obviously substitute the audio bitrate, channels, etc. for other numbers, but these are very standard.

jrkt
  • 2,615
  • 5
  • 28
  • 48
0

An easier option is to use Video editing tools like Kdenlive.

user2715182
  • 653
  • 2
  • 10
  • 23