Join avi Or Other Movie Files Together 9

Terminal

Share
Join avi Or Other Movie Files Together

Hello

In this modern digital world we generate a lot of digital media, one of the most prevalent is movies. After a while I have a lot of indiviual movie files that could be better used as one long movie. This post aims to show you how to combine these movie files into one long movie. This isn’t going to use an app like iMovie where you have to create a movie or apply any video editing. This post is going to show you how to stick lots of movies together in a simple and easy to use way. There is going to be two methods shown, one using Terminal and one with Quicktime, where you can pick the best option for yourself.

Using Terminal

The first method I am going to show you is to use a couple of Terminal commands. This is slightly more complicated however in the long run it will process your movie files quicker. This options takes the individual movie files, sticks them together and then sorts out the header section of the movie file so it will play correctly. The method using Quicktime will involve it re-encoding the files and can take a long time.

To begin with this method change directory to where you movie files are located. First open up Terminal located in Applications > Utilites. Do this using the change directory command. You can either type the path out by hand or drop the folder into the Terminal window and press enter.

cd /path/to/seperate/video/files

We now need to stick the files together into one file. This process will take the second file, put the bytes on the end of the first file and repeat until it has gone through all of the files in the list. I like to think of it as putting a book together. You take your second book, spread glue on the cover and stick to the back of the first book. To do this in Terminal, we put out glue pot down, and use the cat, from the word”concatenate” cocommand.

cat video1.avi video2.avi videon.avi > output.avi

The cat command will take videos 1 and 2 and stick them together, it will place them in the order in the list so don’t get them mixed up. You can add as many as you want to the list, it doesn’t have to be two items long however I would keep in mind that really long list of video files to stick together may cause some problems, so if you have hundreds of files it may be best to do this in bulk. When this has finished you will noticed to things. First the file size of output.avi is the same as the sum of video1 and video2. Second, when you play the avi file it will only play the length to the length of the first video. This is beacause the header section of the first avi only knows its original length. Going back to our book analogy the contents page of the first book, only knows the contents of the first book and not the second. What we now need to do is rebuild the header file so it knows about the second video (or second book contents). This will make sure when it plays it plays all of the video and not just the first part.

To do this we are going to use a program called mencoder. Its from a site called mplayerhq, however we only need the binary for Terminal. To do this head over to stefpause and download the mencoder bianry located at the bottom of the page. When you have downloaded the binary move it using the following command.

sudo mv /path/to/mencoder /usr/local/bin

Terminal will ask for your admin password. This is done so you only have to write “mencoder” in Terminal and not the path to the mencoder file. More information on install this app can be found here.

Now that we have mencoder installed we can use it rebuild the header of our avi file. To do this write or copy and paste the following into Terminal. The command assumes you are in the same location as the file output.avi created earlier.

mencoder -forceidx -oac copy -ovc copy output.avi -o output_final.avi;

In a nutshell this commands rebuilds the header file. One unqiue point about this commands is that it only copies the frames and audio across, it doesn’t re-encode them. This saves a lot of time in building the final file. Most of the time you don’t need to re-encode anything. If you want more of an understanding of mencoder you can read the basic help.

When the command has finished, which shouldn’t take to long you should now have a working avi file which is the correct lenght and contains all of the previous videos.

To summarise the commands are:

cat video1.avi video2.avi videon.avi > output.avi
mencoder -forceidx -oac copy -ovc copy output.avi -o output_final.avi;
rm output.avi

The last line removes the incorrect output file from the cat command. There you have it a video made from the sum of the smaller parts. Once you understand what is happening this command is very fast and very useful.

If you want to learn more about cat and other unix commands I recommend Mac OS X Toolbox, if you want to learn more about mencoder amazon has thrown this book up, although I am dubious to it content.

Using Quicktime

If you are not very confident in using Terminal and want more more application based method, Quicktime Player 7, located in Applications > Utilites in Mac OS X 10.6,  has an option to do this sort of thing. The only downside is that you don’t have much control on the final video specs. I have found that it does a bit of re-encoding as well as converting the file from avi to mov. However if all you want to do is stick some movies together this method it very simple.

To begin with open up Quicktime located in the Utilites folder. Then open up your first movie. Move the scrubber to the far right as shown in the image below.

Editing movies with Quicktime is simple and easy.

Then drag and drop your second movie onto Quicktime, move the scrubber the far right and repeat.

When you have finished compling your movie go to File > Save As and select self-contained movie. The app will compile your movie and spit it out.

If you want to learn more about Quicktime something like QuickTime for Filmmakers is very well rated.

Conclusion

In total these are two of many methods where you can combine movie files together. I prefer the Terminal method since it is quicker, however the Quicktime method may be more useful and easier to remember if you don’t use Terminal that frequently.

If you have any questions or comments about this trick please leave them below.


If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips

9 Responses to “Join avi Or Other Movie Files Together”

  1. 1

    Outstanding news it is actually. We’ve been waiting for this information.

    Comment By Jenine Dart on January 6th, at 3:29 pm

  2. 2

    Thanks for this tutorial.
    I tried to join a couple Flash video files (.f4v) using this method (hoping this might work) but saw a message from mencoder immediately after hitting return,
    “WARNING: OUTPUT FILE FORMAT IS _AVI_. See -of help.
    success: format: 0 data: 0×0 – 0xe1aa3f
    libavformat file format detected.”

    …and at the end of the progress,
    “ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.”

    The resulting .f4v file had to be changed to .avi extension to open in Quicktime player (v 10). It played audio but no video. Do you think its because I was joining non-avi files? Would this work with any other types of video formats?

    Thanks again,
    Matt

    Comment By Mattone on January 7th, at 7:13 pm

  3. 3

    Might be a problem for it being a flash file. If you could convert the flash to avi, then you would be able to join them.

    Comment By admin on January 7th, at 7:27 pm

  4. 4

    Everything worked fine until the final step. The output_final.avi is only 190 MB, while the output.avi is 1.4 GB, and the final only plays about 20 minutes. Any suggestions?

    Thanks,
    Craig

    Comment By Craig on January 18th, at 5:57 pm

  5. 5

    Can you give me more info on the files/size you are using? Have the files been joined correctly?

    Comment By admin on January 18th, at 6:46 pm

  6. 6

    I believe so. They are both .avi files, the first one being 713 MB and the second one is 708 MB. When I joined them, the final is 1.42 GB, so it appears they added together. I’ve also watched both files separately, so I know they work.

    When I use the mencoder command it returns:

    mencoder -forceidx -oac copy -ovc copy cmiyc.avi -o cmiyc_final_2.avi
    MEncoder dev-SVN-r27545-4.0.1 (C) 2000-2008 MPlayer Team
    CPU: Intel(R) Core(TM) i7 CPU M 620 @ 2.67GHz (Family: 6, Model: 37, Stepping: 5)
    CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
    Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2

    success: format: 0 data: 0×0 – 0x54b0e800
    AVI file format detected.
    [aviheader] Video stream found, -vid 0
    [aviheader] Audio stream found, -aid 1
    AVI: Generated index table for 57236 chunks!
    VIDEO: [DIV3] 544×288 24bpp 23.976 fps 1160.9 kbps (141.7 kbyte/s)
    [V] filefmt:3 fourcc:0×33564944 size:544×288 fps:23.976 ftime:=0.0417
    videocodec: framecopy (544×288 24bpp fourcc=33564944)
    audiocodec: framecopy (format=55 chans=2 rate=48000 bits=0 B/s=16000 sample-1)
    Writing header…
    ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
    Writing header…
    ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
    Seek failed 28616f (13%) 2667.91fps Trem: 1min 1353mb A-V:0.042 [1160:128]
    Writing index…18f (-21%) 2668.10fps Trem: 0min 0mb A-V:0.042 [1160:128]
    Writing header…
    ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.

    Video stream: 1160.901 kbit/s (145112 B/s) size: 173207940 bytes 1193.610 secs 28618 frames

    Audio stream: 128.000 kbit/s (16000 B/s) size: 19104925 bytes 1194.058 secs

    Doesn’t really mean a whole lot to me, but the line that says “seek failed” does stand out. And again this produces a file that is 193 MB.

    -Craig

    Comment By Craig on January 19th, at 8:41 pm

  7. 7

    Try

    mencoder -idx -oac copy -ovc copy cmiyc.avi -o cmiyc_final_2.avi

    instead, changes the header method, you can also refer to http://www.mplayerhq.hu/DOCS/man/en/mplayer.1.txt

    The failed to seek bit does seem to cause the problem.

    Comment By admin on January 20th, at 1:51 am

  8. 8

    Still didn’t work, but I successfully joined several other movies so I guess I’ll just live without that one. Thanks for the help.

    Comment By Craig on January 20th, at 5:47 am

  9. 9

    The command line/mencoder instructions are very clear (although were followed blindly and with not much investigation or understanding of the options given in the mencoder step. It worked pretty well for video on DivX AVI files, but unfortunately across the 3+ hours of video (2 DVDs) the audio is slightly out of synch making the results obtained following the “terminal method” unacceptable.

    Thanks anyway for the info.

    Comment By freakqnc on July 21st, at 9:41 am