Written By: Laserion
(Video demo on bottom of article)
Today, I will discuss and teach you on how to join files in ubuntu. To do that, we are going to use both commands, Concatenate and Mencoder in the terminal. Don’t worry, I will guide you and It’s not that hard to learn. You don’t need to memorize all these commands just some few basic key elements and you’re all set to start your everyday life in Ubuntu. I’m still a novice in Linux and quite a beginner using the terminal, but as you practice you learn more things about this interesting Operating System.
Just like in Windows Command Prompt you’ll see the familiar symbol C://> but in linux you’ll see this $ prompt instead. More look like a dollar string sign. To start the terminal; Goto - Applications/Accessories/Terminal and it will open into something like this.username@computer-name:~$ — normally, this is your home folder.For today’s session, I will use this symbol “$” prompt in all of my example. Now, let’s begin….type the following at the terminal and be sure you are connected online.
$ sudo apt-get install mencoder
— This will give you a temporary admin rights to install software packages into your Ubuntu box. It will prompt you to enter your password.
— It will give you an output like this, but yours might display different.
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following extra packages will be installed:
libtwolame0
Suggested packages:
libdvdcss mplayer-doc w32codecs
The following NEW packages will be installed:
libtwolame0 mencoder
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 3748kB of archives.
After this operation, 8745kB of additional disk space will be used.
Do you want to continue [Y/n]?
— then press “Y” and ENTER to continue…. it will download the package from it’s repositories….
Get:1 http://ph.archive.ubuntu.com hardy/universe libtwolame0 0.3.10-2 [57.5kB]
Get:2 http://ph.archive.ubuntu.com hardy/multiverse mencoder 2:1.0~rc2-0ubuntu13 [3690kB]
Fetched 3748kB in 2min45s (22.7kB/s)
Selecting previously deselected package libtwolame0.
(Reading database … 97770 files and directories currently installed.)
Unpacking libtwolame0 (from …/libtwolame0_0.3.10-2_i386.deb) …
Selecting previously deselected package mencoder.
Unpacking mencoder (from …/mencoder_2%3a1.0~rc2-0ubuntu13_i386.deb) …
Setting up libtwolame0 (0.3.10-2) …
Setting up mencoder (2:1.0~rc2-0ubuntu13) …
Processing triggers for libc6 …
ldconfig deferred processing now taking place
Then your all done. Is that easy….
I’m assuming you already have the files with you.
Figure: 1
Infile1.avi —– 100mb
Infile2.avi —– 100mb
Concatenate - Let’s you join/combine two or more files in one. You can even use this command with your documents. The command syntax for concatenate is “cat” then your file (infile1.avi) then followed by the file (infile2.avi) you want to join and “>” the output you want to save as your new joined files.
Figure: 2-1
$ cat infile1.avi infile2.avi > output-filename.avi
This will combine the two files, but were not done yet as these files will only create one big file. As they are still out-of-sync….
Figure: 3-1
Infile1.avi —– 100mb
Infile2.avi —– 100mb
output-filename.avi —– 200mb
Now, we are going to use the Mencoder, but before we do that. We just need to familiarize with the basic commands first.
mencoder - (MPlayer’s Movie Encoder) is a simple movie encoder, designed to encode MPlayer-playable movies. It encodes to MPEG-4 (DivX/Xvid), one of the libavcodec codecs and PCM/MP3/VBRMP3 audio in 1, 2 or 3 passes. Furthermore it has stream copying abilities, a powerful filter system (crop, expand, flip, postprocess, rotate, scale, noise, RGB/YUV conversion) and more.
-o (Output File) more likely the save as new-filename
-ovc (Output Video Codec) Encode with the given video codec
-oac (Output Audio Codec) Encode with the given audio codec
Example:
-ovc (codec name) your encoding choice
-ovc copy
no encoding, just streamcopy
-ovc lavc
Encode with a libavcodec codec.
-oac (codec name) your encoding choice
-oac copy
no encoding, just streamcopy
-oac mp3lame
Encode to MP3 (using LAME).
NOTE: to get a list of available video and audio codecs.
type the following at the terminal:
$ mencoder -ovc help
$ mencoder -oac help
Basic command syntax for mencoder:
Figure: 4
$ mencoder infile.avi -o outfile.avi -ovc copy -oac copy
Now, that we are more familiar with the commands. Let’s continue the tutorial’s and what’s left in Figure: 2-1.
Figure: 2-2
$ mencoder output-filename.avi -o final-output.avi -forceidx -ovc copy -oac copy
…..done….
-forceidx - Force index rebuilding. Useful for files with broken index (A/V desync, etc). This will enable seeking in files where seeking was not possible. You can fix the index permanently with MEncoder.
Figure: 3-2
Infile1.avi —– 100mb
Infile2.avi —– 100mb
output-filename.avi —– 200mb
final-output.avi —– 200mb
Note: you can safely remove output-filename.avi as it is no longer needed.
If you find this tutorials a bit confusing, Let’s skip the first one and get the short version instead…… hehehe……
Shorter Version:
$ mencoder infile1.avi infile2.avi -o final-output.avi -ovc copy -oac copy
…..and THAT’s IT!
type exit to close the terminal.







Laserion,
Good job on the article–very informative and thorough. I would probably just modify the title so that it reads, “How To Join .avi Files in Linux”. And where you apt-get, just qualify that with “in Ubuntu, I do this:” This generalizes an already terrific article.
Thanks again.
Nishiki