Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have used ffmpeg, but with it you have to first make mpg videos then do cat video1.mpg video2.mpg > joined.mpg and then convert to joined.mpg to joined.mp4 with ffmpeg to be able to upload on youtube. I heard there's mencoder which can join avi files without converting to mpg and using cat command. I'm making videos to upload on youtube so it needs to be avi mp4 or flv format. Which tool is the best to join videos from command line?

share|improve this question
up vote 2 down vote accepted


melt was meant as a test tool for the MLT framework, but it is also a powerful multitrack command line oriented video editor. It could also used as an minimalistic media player for audio and video files.


sudo apt-get install melt


This package contains mencoder, a simple movie encoder, designed to encode MPlayer-playable movies (AVI/ASF/OGG/DVD/VCD/VOB/MPG/MOV/VIV/FLI/RM/NUV/NET) to other MPlayer-playable formats. It can encode with various codecs, like DivX4 (1 or 2 passes), libavcodec, PCM/MP3/VBRMP3 audio. Also has stream copying and video resizing abilities.


 sudo apt-get install mencoder


share|improve this answer

For mp4 the only working solution I found was with MP4Box from gpac package

for file in $(ls *.mp4|sort -n);do
    filesList="$filesList -cat $file"
MP4Box $filesList -new merged_files_$(date +%Y%m%d_%H%M%S).mp4

or command is

MP4Box -cat file1.mp4 -cat file2.mp4 -new mergedFile.mp4

with mencoder and avconv I could'nt make it work :-(

share|improve this answer

This is called muxing (multiplexing). As well as the other suggestions, Handbrake will do this and a lot more, including ripping disks, transcoding etc. It has both a GUI and CLI version, and is available from the Software Centre. However, I find it to be a bit of overkill for simple muxing and use the simpler and faster mkvtoolnix package for that. It also has both GUI and CLI versions and is available for Ubuntu and many flavours of GNU/Linux and other Unix derivatives, even MS-Windows. mkvtools is also open source under the GPL, and is available from the website:

with instructions for installing it in Ubuntu. The only issue with Handbrake is that it just outputs to .mp4 (good for YouTube), or .mkv files, but I've had no trouble viewing .mkv video/movies with anything including Android (except a DIVX-only DVD player). mkvtools will only save in .mkv containers.

ffmpeg is probably the simplest CLI to convert your .mkvs to .mp4s

ffmpeg -i inputfilename.mkv -vcodec copy -acodec copy outputfilename.mp4

Hope this helps.

share|improve this answer
mp4? I cannot find any reference for it. – user1079002 Apr 16 '12 at 5:21
Sorry 'bout that, Chief. I edited my answer re output formats. – Smarteralec Apr 23 '12 at 17:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.