Home > Tips 'n trick > Merge avi files with ffmpeg on Mac OS

Merge avi files with ffmpeg on Mac OS

Goals: Create one (and big) avi file from multiple or more avi files.
Our option:

  • Use Quicktime Pro, it’s easier but you need extra dollar to buy the account 😦
  • Use FFmpeg 🙂

Install FFmpeg, i’m using homebrew package:

$ brew install ffmpeg

Or if you are using Macports, simply run:

$ port install ffmpeg

OK, for example we will merge file video cd1.avi and cd2.avi. Each have 700MB size.
First, we concatenate them with the magic of cat command.

$ cat cd1.avi cd2.avi > cd_all.avi

Now, you’ll get cd_all.avi with 1.4GB. But wait? is it finish yet (where’s the ffmpeg?), if you open up and watch the cd_all.avi file you’ll get blank screen when the cd2 part is on or even not get to cd2 part, it’s because the video index is broken or only see the first part (cd1). So, it’s ffmpeg job to re-index it 🙂

$ ffmpeg -i cd_all.avi cd_all_reindexed.avi

Opps, i got “timebase not supported by mpeg 4 standard” error. It’s because ffmpeg cannot set the fps (frame per second) automatically from our input, so we need to set it manually, let’s use the default value 25.

$ ffmpeg -i cd_all.avi -r 25 cd_all_reindexed.avi

OK, it’s work, let’s wait about 5-10 minutes (depend on file size) to get ffmpeg finish the encoding and reindexing.

Opps, the encoding stop on “video:177642kB audio:57082kB global headers:0kB muxing overhead 4.904114%” and i only got 250MB and video quality is really bad, there’s something wrong. Ahh, we need to add sameq parameters to preserve same quality as input.

$ ffmpeg -i cd_all.avi -r 25 -sameq cd_all_reindexed.avi

It’s works 🙂 But, the filesize is become 1.75GB, there should be a way to set another paramater to make it 1.4GB (normal size), but let’s discover later :).

Reference:

Advertisements
Categories: Tips 'n trick Tags: ,
  1. Hugo
    April 3, 2011 at 5:25 pm

    How about:
    cat cd1.avi cd2.avi > cd_all.avi
    ffmpeg -i cd_all.avi -vcodec copy -acodec copy cd_all_reindexed.avi

    This way the video/audio doesn’t get re-encoded meaning there is no quality loss and the resulting file cd_all_reindexed.avi is only 1.4 GB. At least this is how it worked for me.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: