Copying and Burning DVDs

Table of Contents (TOC)

Copying and Burning a Data DVD
Copying and Burning a Video DVD
Converting Between NTSC and PAL
Using the Tovid Program Suite
Removing Unwanted Audio and Getting Portions of a File
DVDs of a TV series
Working With Subtitles
Making an mp4 or avi file from a DVD
Merging avi or mp4 files (and adding a commentary audio track)
Working with mkv Files
Reducing file size of avi and mp4 files
Downloading Multiple Files from Rapidshare
Working with rar files
Using Lightscribe
Converting files for iPad
A quick note on OSX dmg files


The information on this page is NOT provided in order to pirate media disks. It is intended for users to make backups for personal use, when allowed.

It is haphazard at times--I'll start working on a particular issue and then add it to the page, forgetting that I've covered something similar in another section. Then, it stays haphazard till I get the time and inclination to fix it.

There are a variety of pages and tools on burning and copying DVDs. This page is being put up for my own personal use, so that I don't have to look things up each time.

I am NOT any sort of video editing expert. There are many articles, (some of them are linked here) that cover the finer points of video editing. The wonderful ffmpeg has all sorts of options that I don't begin to cover. (Even their man page doesn't cover all of them. For example, there is a -vol option, to raise the volume, that isn't mentioned in the man page.)

A couple of distro (and O/S) specific ffmpeg notes:
Apparently Ubuntu and Debian developers have decided to not use ffmpeg anymore. If you install ffmpeg, when you try to run it, there's a message that you should use avconv. A brief test conversion on Fedora with ffmpeg and Ubuntu with avconv gave pretty similar results. It understands most, if not all of the ffmpeg flags. I don't really know the reasons behind the decision, but apparently ffmpeg has a fork, libav, and Debian went with that. According to Stackoverflow article it sounds like someone got insulted. Aside from the inconvenience to users, it's almost amusing. The launchpad bug referenced is a complaint about the wording. Apparently at least some Debian developers feel that if they're not using it, it's dead.

Some of what I say about ffmpeg might work with avconv, but almost all of what I do is done with RH based systems. To use the -vcodec libx264 that I mention below, in the reducing size section one does need, at least in Ubuntu, to install libavcodec-extra-53. The man pages seem to be identical for the two programs.

Most of this has been done on CentOS 5.x and 6.x. How it's done, package names and the like, will differ between distributions, but hopefully, the reader can adapt it to their own needs. The commands, once the various programs are installed, are usually similar, though from time to time, one will find that a distribution doesn't have a particular library.

Note that as of time of writing, I recommend using ATrpms for ffmpeg and other multimedia programs, rather than repoforge (formerly rpmforge). As mentioned below, some of the current (late Fall, 2011), repoforge packages are older versions, possibly lacking features in later releases. There is also the completely unofficial linuxtech repo, which, as the readme points out, consists of packages that its maintainer built for personal use. It has, for example, HandBrakeCLI which is discussed below. It can be found at linuxtech.. The link goes to the RHEL6.x packages, I think those are the only one covered.

In most cases, if one installs mplayer and/or vlc, many of the libraries will be provided as dependencies. One will usually also want dvdauthor, dvd+rw-tools, and ffmpeg. Lastly, I strongly recommend the tovid program, which makes many things much simpler.

These are various tips I've gotten from various places. One of my most frequently referenced pages is the article. I give other links when I have them throughout this article.

These days, with Linux becoming more and more Windows like, many people prefer the GUI tools to do these things. Judging from various forums, however, sometimes the GUI tools don't work, and just like Windows, it can be difficult to figure out why. CLI (Command Line Interface) tools also use fewer resources, can be run in screen or tmux, and quite possibly provide greater flexibility.

Lastly, note that much of this requires several gigs of disk space.

With all that out of the way, these are methods that work for me.

If you find some glaring error, feel free to drop me a note at scottro11 [at], and also feel free to send your own tips, but don't be offended if they don't appear here. Note that many of the commands will require being run as root or with root privilege using sudo.

Copying and Burning a Data DVD

With a data DVD, one can use vobcopy or dvdbackup, but it's not necessary. (I've also found it not to work, for whatever reason, when backing up OS X DVDs). As my main machine has a sata DVD burner, called /dev/scd0, I'll be using that nomenclature in all examples. Change it to match your machine's listing of its DVD burner. Once you have your data DVD in the drive
cat /dev/scd0 > datadisk.iso

This will take awhile, but at the end of it, you'll have an ISO file than can be burned to a backup DVD. People also use dd if=/dev/scd0 of=datadisk.iso, but I haven't found any difference.

The iso can now be burned to a DVD with the growisofs command, part of the dvd+rw-tools. I like to check it first, to make sure that it did get what I wanted, so I usually do
mount -o loop datadisk.iso /mnt
ls /mnt

Hopefully, this will show me the various files that are on the original DVD. Once that's done, unmount. Note that the command is umount, NOT unmount, something often missed by newcomers.
umount /mnt

Remove the source DVD and replace it with a blank DVD-R (or DVD+R, if that's what you use.)
growisofs -dvd-compat -Z /dev/scd0=datadisk.iso

One can, as is covered all over the place, also make a large collection of files into an iso, then burn that. For example, to make and burn an iso of a directory called myfiles, assuming you're in the directory that contains the myfiles directory
growisofs -Z /dev/scd0 -R -J ./myfiles

I have sometimes run into problems with this when making isos larger than 4 GB on CentOS 5.x. I haven't had the problem with video files, only with directories containing other types of data.

CentOS, as its users know, is binary compatible with RedHat, which, aimed at the enterprise, will use older, proven stable, versions of packages. The growisofs program relies upon mkisofs. The syntax for mkisofs, (to just create an iso of the myfiles directory) is
mkisofs -J -r -o myfiles.iso ./myfiles

The ./ refers to the current directory and is probably not necessary, it's simply a habit. The -o is for the output.

If you run the command
mkisofs --version

on Ubuntu, Fedora, and many other Debian or RH based distributions, you'll see a message like
mkisofs 2.01 is not what you see here. This line is only a fake for too
GUIs and other frontend applications. In fact, this program is:
genisoimage 1.1.10 (Linux)

In practice, when I did run into problems, I just put the files on either another machine or a VirtualMachine, running something with more current versions of makeisofs.

These days, I use CentOS 6.x, so it is no longer an issue. From what I understand, (untested by me), the more current versions of mkisofs itself also have no issues. The chances are that CentOS 5.x uses an older version and that is why I had the issue.

If the file is larger than a DVD's 4.7 GB, one can use a double layer (DL) DVD in the same manner. I've noticed that if it's a DVD+R DL DVD there is a message, when growisofs starts to burn, about splitting layers. I don't see that with a DVD-R DL DVD, however the message seems harmless, and files burn correctly.


Copying and Burning a Video DVD

Ok, that was an easy one. Now, let's take a more complex situation, where you have a video DVD. The steps will be to produce a directory that has the VIDEO_TS and sometimes the AUDIO_TS. (Lately, I've noticed that various DVDs only have the VIDEO_TS and the audio is included in there.)

There are two common tools for this, dvdbackup and vobcopy. I think vobcopy is supposed to be faster, but I've never done any benchmarks.

Unfortunately, there is no dvdbackup program in the CentOS repos at time of writing. (March 2010). However, rpmforge has lxdvdrip which includes dvdbackup_lxdvdrip, and it works the same way.

The problem below has either been fixed or will be fixed shortly
I'm leaving in the issue mentioned below for reference. However, I believe that Dag has already pushed the repaired lxdvdrip 1.70 and 1.76 through, so the reader should try to install via normal procedure first.

The issue was that if one tries to install the package with yum, using the rpmforge repo, (see the CentOS wiki article for information about enabling the rpmforge repo), it will fail, saying it needs dvdbackup and streamdvd.

One workaround is to find old versions of these packages (the oldest I saw were for Fedora Core 4, back when it was called Core), install them with the --nodeps option, then install lxdvdrip. The more elegant, in my opinion, option is to rebuild the spec file, removing those dependencies.

For those familiar with building rpms, I have a revised spec file (slow site, not always available) here. (On the same, somewhat unreliable site, I have my own version of the x86_64.rpm file, here.) This page is not a tutorial on rebuilding rpms. Once again, see the CentOS wiki article for information.

Assuming you know how to do this, if the link above is down, or you prefer to do it yourself, grab the src.rpm from Dag's site (current at time of writing), and install it. Then, in the spec file, you will see a line reading
Requires: dvdauthor, dvdbackup, dvd+rw-tools, mplayer, streamdvd, transcode

Change it to read
Requires: dvdauthor, dvd+rw-tools, mplayer, transcode

In other words, remove dvdbackup and streamdvd. Then rebuild it with
rpmbuild -ba lxdvdrip.spec

Then install it with rpm -ivh lxdvdrip-<version>.rpm. (For example, rpm -ivh lxdvdrip-1.76-1.x86_64.rpm).

Most other distros should have a package for it. I'm not sure about Fedora, but even if it's not in the repos, there is probably a current rpm around. I suppose one could install it on Ubuntu and use alien to create an rpm, but again, that's beyond the scope of this article.

Once it's installed, one can insert a DVD into the DVD drive and run the command
dvdbackup -M -i /dev/scd0 -o backupdir

(If using CentOS, substitute "dvdbackup," with "dvdbackup_lxdvdrip".) That's assuming you've created a backup directory called backupdir. -M is mirror, -i is input and -o is output. Inside that directory, you'll find a directory containing the DVD files. There will be one parent directory with the VIDEO_TS and possibly AUDIO_TS inside. For our example, we'll assume that dvdbackup called it MYVIDEO

Both vobcopy and dvdbackup may require libdvdcss. Depending upon your country and distribution, this may be be easy or hard to get. As it keeps changing, I'm just going to say that if necessary, and legal--and once again, one assumes you're doing this to make legal copies of what you own--either google for your distribution and libdvdcss or ask on the distro's forums.

If using vobcopy, one first mounts the DVD.
mount /dev/scd0 /mnt 

Now run vobcopy. It seems necessary to put the -m (for mirror) before the -i (for input directory), but your mileage may vary.
vobcopy -m -i /mnt

This will create a DVD directory in your current directory. Again, we'll assume it's called MYVIDEO. (It isn't necessary to specify an output directory for vobcopy, though you can give it a title if you choose--if you don't, vobcopy calls it by the existing title, in this case, MYVIDEO.) When done, unmount the mounted dvd.

umount /mnt

Get to the directory containing MYVIDEO (your current directory if you used vobcopy, or backupdir if you used dvdbackup.)

At this point, you can use mkisofs to first create an ISO, then burn it with growisofs, or do it in one step. The two step method, again, assuming you are in the directory containing the MYVIDEO directory.
mkisofs -dvd-video -o video.iso ./MYVIDEO

If you want to give it a title, you can do that here with
mkisofs -dvd-video -o video.iso -V "MY TITLE"  ./MYVIDEO

This will produce an iso called video.iso. (Obviously, you can call it whatever you want, such as myvideo.iso). You can now check the file if you wish, using mplayer, vlc or your media player of choice. For example, with mplayer
mplayer video.iso 

Now, put a blank DVD in your dvd burner and burn it with
growisofs -Z /dev/scd0=video.iso

To do it in one step, burning directly to disk without using mkisofs to make an iso first
growisofs -Z /dev/scd0 -dvd-video ./MYVIDEO

Again you can use the -V "MY TITLE" option if desired.

If you try to play the disk immediately after burning, you might find that mplayer and vlc are unable to play it. Before you say bad words and throw out what seems to be a coaster, eject the disk and replace it. A friend of mine's version of growisofs will do this automatically, (unless one uses the option use-the-force-luke=notray), but mine doesn't. It may depend upon your system, both software and hardware, but regardless, eject the disk once before trying to play it. Once ejected, it's fine. That is, you can eject it and put it directly into a tabletop player and it will play. The tovid suite's "tovid dvd -burn" may also automatically briefly open the tray after burning, depending upon tovid version. (They seem to have dropped this option in the latest subversion).

Once again, all this works in the same way with DL DVDs for larger files. If one just wants to make a backup copy of a purchased movie, for example, you can use vobcopy or dvdbackup to copy the DVD, put in a DL DVD and run growisofs as usual.

In some cases, one might just want the file. I've seen relatively complex solutions for, as an example, taking a video with several tracks and playing it on a Macbook Air. One can just copy the directory that was made with dvdbackup or vobcopy, transfer it over network or with USB to a Macbook Air, then play it with VLC. I don't know if Apple's own dvdplayer will play it--it shows up, by default, as a directory in the OS X finder, but dragging the directory into VLC will play it as a normal video.


Converting Between NTSC and PAL

Much of this was taking from an article on

I also used this article from for the first step.

If moving from one country to another, or receiving a present from another country, it may be that your tabletop DVD player can't play PAL or NTSC dvds. As I live in the US, and have only run into being unable to play PAL, this section is geared towards converting a PAL DVD to NTSC format.

Step one is to dump the DVD to a big vob file. The idolinux article suggests using mplayer with
mplayer dvd://1 -v -dumpstream -dumpfile dump.vob

This works, but I found that the following vobcopy command would also work. First mount the DVD, then use vobcopy as follows, with the -i and -m flags where I have them. (Otherwise, you get the usual video directory, that we used above).
mount /dev/scd0 /mnt
vobcopy -i -m /mnt

Note the order of the -i and -m flags. In this case, we want one big vob file, so the command is done differently than it was above.

This should create one large file called MYVIDEO.vob (with MYVIDEO being whatever title vobcopy was able to get from the disk.)

Next, it's always good to use mplayer or other media player, to make sure it's what you want.
mplayer MYVIDEO.vob

Assuming it looks good, use the incredibly versatile ffmpeg.
ffmpeg -i MYVIDEO.vob -target ntsc-dvd -acodec copy mynewvid.mpg

Note that's article adds in framerate and aspect. His version is
ffmpeg -i /path/to/vobfile -target ntsc-dvd -r '30000/1001' -aspect 16:9
-acodec copy outputfile.mpg

I didn't find that to be necessary, it seemed as if ffmpeg figured it out. The -acodec copy means to copy the audio from the source.

Now we have an mpg file. At this point, I use tovid, which segues nicely into the next section. (But see the section on mkv files, where I did find it necessary to include the aspect ratio.)


Using the tovid program suite

The incredibly useful tovid suite is a collection of various DVD authoring tools. Many distributions have a package for it. CentOS doesn't, but it's fairly easy to install. The link above goes to the wiki's front page, which has a link for the necessary dependencies (some of which are available as CentOS rpms), as well as the program itself with installation instructions.

Installation will be left as an exercise for the reader. It's a popular program, so help should be available on your distribution's forums. Ubuntu has a package for it. If using a distribution such as CentOS or Fedora, you may be able to use Ubuntu's alien to make a working rpm.

I'm usually using the subversion. There's a note on the front page that it needs a new maintainer, but the subversion has continued to work well for me. Instructions are given on the wiki pages. If for some reason, you are using 0.33, which is outdated by now, there was an issue with /usr/lib/tovid/makedvd. In 0.33 it had the line which included
IFS=$'\n' device=($(find -L /dev -type b -name 'dvdrw*' 2>/dev/null ))

This was resulting in makedvd -burn script to fail, not finding the device. Note that I've only put in part of the line. The key is to include a maxdepth option in find and it should work.
IFS=$'\n' device=($(find -L /dev -maxdepth 1 -type b -name 'dvdrw*' 2>/dev/null ))

One other minor point--at present, (2012, at time of writing), some of the more up-to-date distributions are using python 3. For example, in ArchLinux, I used subversion. When I ran the scripts they had, to build and install, I got errors about unknown modules. Therefore, rather than running ./ build (or whatever command was needed, as per the INSTALL documentation), on ArchLinux, I used
python2 ./ build_doc
python2 ./ build_tovid_init
sudo python2 ./ install

The first two commands should only be necessary with a new subversion installation. This is covered in the INSTALL provided with the subversion files.

I'm not going to go too deeply into using tovid here. There are some good basic wiki articles here. (I'm only giving the general wiki page, as the urls of the articles are constantly changing).

The repoforge version of ffmpeg doesn't play well with making thumbnails for titles. If making basic text menus, it's fine, but if using thumbnails, it will show the menu, but then hang. The only solution I've found, if I want to use thumbnail menus, is to use a distribution with a later edition of ffmpeg. (This applies to the current repoforge version of ffmpeg, ffmpeg-0.6.1-1.el6.rf. For those who use the ATrpms version, which is something like 0.6.8, this isn't an issue. See this thread on tovid users.

IMPORTANT NOTE: As of tovid 0.32, (I think) the syntax changed. I've tried to update this page and hope I haven't missed anything. Assuming you have an avi file, first encode it into an mpg. (This will also work with an mkv or mp4 file.)
tovid mpg -in myfile.avi -out myfile

(This used to be tovid -in myfile.avi -out myfile).

It will examine the file and eventually produce a file called myfile.mpg. At this point, I like to test it with mplayer. On occasion, audio will be badly out of sync. The tovid docs say that if this happens, be sure to use ffmpeg rather than mencoder, either by using -ffmpeg as an option, or fixing it in your ~/.tovid/tovid.ini. (That is where it is in subversion, depending upon your version, the file location may differ.)

Even with ffmpeg, I've had some files where I could simply not sync the video and audio. In those cases, which were possibly due to the type of audio encoding on the file, in at least one instance, I wound up giving up and using the GUI devede program, which encoded it properly. As I use ffmpeg as my default encoder for tovid, and devede, at least in the version I was using, uses mencoder, it's possible that had I used mencoder instead of ffmpeg that the mpg created with tovid would have been properly synced.

At any rate, once you have the mpg file, make an xml file to use. (Unless using subversion, see the note below).
tovid xml myfile.mpg -out myfile

(This used to be makexml myfile.mpg -out myfile).

This creates a file called myfile.xml.

It seems, though I'm not positive of this, that in the latest subversion, tovid no longer uses tovid xml. Instead, after creating the mpg, one goes directly to creating the disk structure. In subversion, which will become tovid-0.35, the command is, after having created the mpg
tovid disc -nomenu -files myfile.mpg -out myfile

The reason for using the -nomenu option is that the default will be to create a menu. As mentioned above, on CentOS and ScientficLinux 6.x with repoforge's version of ffmpeg, this doesn't work.

After creating the mpg, tovid may give a message to use -no-menu and not mention the -files flag. Either -nomenu or -no-menu should work, but -files is necessary.

One minor oddity--I have no idea if it was because I was using subversion or some other reason. I recently, on CentOS 6.2 upgraded ffmpeg, mplayer, and a few other related media packages. The next time I ran tovid mpg on an avi file, it failed, saying it couldn't recognize the avi file. I then uninstalled tovid (which I'd installed from subversion) and installed the latest subversion. After that, it worked. I was in a hurry at the time, and didn't make any investigation as to what broke what, I just mention this in case the reader ever finds themselves in a similar situation.

I do find that tovid's dvd -burn will often, when it's all done, give me an error, saying something to the effect of input/output error, write failed, then a row of !'s and message that it encountered an error. However, in all cases, as long as the rest of the burning seems to have gone successfully, that is the usual whatever% done, estimate finish and so on, that there is no problem. I eject and replace the dvd, test it with mplayer, and all is good.

If one has a collection of files, the tovid wiki has articles about making them into something with a thumbnail menu. Here's the quick version.

You've already made your mpg files, file1.mpg file2.mpg file3.mpg. The tovid command needs the files and titles--I like to add the menu-title option as well, otherwise, it may have a name at the bottom that I don't like. The title does have to be 16 characters or less--otherwise, it will give you an error, and tell you to try playing with the font settings. The man page says you can use submenus, but I've never gotten that to work. However, I'm fine with short titles, so I haven't tried very hard. Anyway, one could use this example, right from the man page. (They tend to break lines with \ which is easier to read--one can also just put it all on one line--if your browser breaks the command below, it should be on one line (or separate lines with a backslash as shown in the tovid man page.)
tovid disk -files file1,mpg file2.mpg file3.mpg -menu-title "My files" -titles "My Video 1" "My Video 2" "My Video 3" -out myfiles

Remember it will match the order of files with the title--if you left out one title, it will give an error that you have a different number of files and titles. If you leave -titles out, it will give them a title with the name of the file, minus the .mpg suffix, and give you a message to that effect. If you leave the -menu-title out it will use a default of My Video Collection or something similar.

Now it will start, giving you some information about what it's doing. It uses ImageMagick to display the thumbnail menu. It will then say if you're happy with the preview, type yes to continue. You can close the ImageMagick display by hitting escape (it gives you a message to that effect). If you don't specifically type yes at the prompt, it will exit, giving a message about possible configuration options to try. That is, hitting enter will cause it to close, you must type "yes" (without quotes).

When done, you'll have your file that you can preview with your player of choice, and then burn with tovid dvd -burn as explained above.

While on the subject of menus, if making something with menus, mplayer now supports dvdnav. This means that if I've made something with a menu, and want to check it, and the directory was called myvideo I can check with
mplayer -dvd-device ./myvideo dvdnav://

This can then be navigated with the number pad, using 1,3, 4, and 6. with 7, the home key on a standard US keyboard number pad, taking you back to the menu.

Depending upon your distribution, mplayer also has a default input.conf. In CentOS, with the atrpm version, this can be found in /usr/share/doc/mplayer-<version>/. On ArchLinux it seems to get installed in /etc/mplayer.

If you don't have the file in /etc/mplayer or your home/.mplayer directory, then the normal arrow keys won't work with dvd navigation. On a laptop, you might be able to select an item, but not get back to the menu. So, if your normal arrow keys (as opposed to number pad arrow keys) aren't working properly, make sure you have the input.conf file in /etc/mplayer or your home .mplayer directory.

If you do have the file, then you should be able to navigate with the normal arrow keys, using the escape key to get back to the menu.

If using tovid 0.34 and later, one can can immediately burn the dvd, or first create the structure. To create the structure in a separate step
tovid dvd myfile.xml

(This used to be makedvd).

This will create a DVD directory called MYFILE. Then you can burn it with
tovid dvd -burn ./MYFILE

To do it in one step
tovid dvd -burn myfile.xml

This will make the structure, then burn it. If you have two dvd burners, then specify the device.
tovid dvd -device /dev/scd0 -burn myfile.xml

(This isn't always necessary--however, sometimes I've found that for some reason, CentOS will symlink /dev/dvd to /dev/scd1 rather than /dev/scd0.)

If one already has an mpg file, they can just skip the first step of tovid mpg -in infile -out outfile. For example, in the previous section about PAL and NTSC, we created an mpg file called outputfile.mpg, using vobcopy and ffmpeg. Once that file is created, I can finish the job with tovid's xml command.
tovid xml outputfile.mpg -out outputfile

Once that's done, I can use tovid dvd as described above.

By default, I believe tovid still uses mencoder. This can take a long time as it encodes audio and video separately. Using ffmpeg is much faster, but has to be specified.
tovid mpg -ffmpeg -in myfile.avi -out myfile

At time of writing however, if using ffmpeg, you can't use subtitles unless they're already hardcoded into the avi file. If you want to include subtitles, don't use the ffmpeg option. Also, as the man page points out, when one does insert subtitles, they are hardcoded into the resulting mpg file, meaning you can't turn them off. I have more information on subtitles in general below

I have seen tovid have problems with some High Definition Blu-Ray ripped mp4 files. If using ffmpeg, it takes about 10 seconds and the resulting mpg file is a 0 byte file. If not using the ffmpeg option, it will examine the file, then exit with a message about having a problem encoding the audio to ac3 format.

When that happens, once again, ffmpeg can save the day. When I have run into this situation I've been able to fix it with
ffmpeg -i myfile.mp4 -target ntsc-dvd myfile.mpg

From there, I was able to use tovid xml on the mpg file and create a reasonably good DVD. As mentioned, in subversion rather than tovid xml, one would just use tovid disc -nomenu -files -myfile.mpg -out myfile


Removing Unwanted Audio and Getting Portions of a File

From time to time, you may have a file with several audio tracks and not want all of them. For example, there may be a video file with a foreign language track and a track in your language. Howard Pritchett's excellent ffmpeg page covers this in detail, but I'll go over it briefly.

I have more about subtitles in the subtitle section as well. The video track will usually be track 0. The audio track will usually be 1, and if there's a second audio track, that will be 2. (One way to confirm which is which is to use vlc and select the audio track from its menu. Howard covers ways to do it all from command line.)

In this case, we'll say that the first audio track, 1, is in French and the second, 2, in English, and the reader only wants the file with the English track.

ffmpeg -i movie.avi -map 0:0 -map 0:2 -target ntsc-dvd file.mpg

As usual, there are many more options that can be used. In this case, we're creating an mpg file that can be made into a DVD but will only have streams 0, the video, and 2, the English audio. As far as I understand the -map option, the first 0 refers to the first input file. The number after the colon refers to the stream. An explanation of the map option can be found here on the ffmpeg wiki.

The mencoder equivalent is -aid. For example, for things I find in the US, usually the first audio track is English, and the second another language. If I only want the English track, then I might use something like
mencoder -oac copy -ovc copy -aid 0 myfile.mkv -o myfile.mp4

If I wanted the second track, for example Japanese, I would use -aid 1. It counts the first audio track as 0, even though the first track will usually be video. Though I would usually use ffmpeg for this, as mentioned elsewhere, ffmpeg can sometimes have difficulty with subtitles. So, for this, I'll use mencoder. With an mkv file if I extract them, so that I have the subtitle file in the same directory as the mkv file, I can play the file. I cover this below in the subtitle section. For example, assuming that using mkvextract --identify we know that the third track is the subtitle track.
mkvextract --identify myfile.mkv
mkextract tracks myfile.mkv

If the file works with mkvmerge, then making a new file with one audio track can be very quick. If I have an anime that has English and Japanese audio, and I only want the Japanese, first I check with mkvmerge --identify to get the numbers of the audio tracks. Usually it will be tracks 2 and 3. If I play the file with no options, the first number will usually be the default audio. Therefore, if I play the file and the audio is English, it's usually safe to assume that English is audio 2 and Japanese audio 3. Therefore, to get the Japanese audio track
mkvmerge -o japaneselang.mkv -a 3 original.mkv

The -o is for output the -a is for audio. In this case, I'm telling it to just copy audio track 3, and it will leave out audio track 2. The same can be done with multiple subtitle tracks. For example if mkvmerge --identify tells me that 4 is an English subtitle track and 5 a Spanish one, I can do
mkvmerge -o japaneselang.mkv -a 3 -s 4 original.mkv

Be careful with this. Sometimes it will show two subtitle tracks as S_VOB. This means that it's the combination of sub and idx file so if you remove either one, you'll have no subtitles. If you tried to run the mkvextract tracks command to get the subtitle file, you will find that mkvextract will write it as an idx, not a srt file.

Therefore, if there were multiple languages, and you really only wanted one set of subtitles, you would have to use -s 3 -s 4 (or whatever numbers the English subtitles were.)

On a somewhat related note, ffmpeg can grab a section of a media file. If you want to only grab 5 minutes of a 20 minute video, the options are -ss in seconds for the start time and -t for the duration, also in seconds. You can also use HH:MM:SS, that is hours, minutes, and seconds. For example, if you have a 20 minute video and you want to only get the second five minutes of it, the syntax would be
ffmpeg -i myvideo.avi -ss 300 -t 300 fiveminutevid.avi

That means you will grab the video beginning at 5 minutes (300 seconds) into the video and stop grabbing after 5 minutes (the second 300).
Again, one can use the hours:minutes:seconds format for both the -ss and -t options.

If using mencoder, the syntax is
mencoder myvideo.avi -ss 300 -endpos 600 fiveminute.avi


DVDs of a TV Series

Recently, someone gave me a gift of a DVD of an anime series that I like. I wanted to back it up to disk. It defaulted to Japanese audio and English subtitles. In this case, the subtitles were idx/sub format. (There was also an English audio track and some highlight features that I didn't want.)

Step one was to figure out which titles were the actual episodes. I used the lsdvd command, available in most distributions. This showed me that several titles were around 23 minutes long, so I knew those were my episodes.

As I figured it would be much faster to run HandBrakeCLI on a file on disk as opposed to doing it directly from the CD, I would then use vobcopy to first copy a title to disk. I prefer to give it a title rather than let vobcopy decide, as I didn't want to mix them up.

Running lsdvd showed me, for example, that title 02 was 23 minutes and a few seconds long. This indicated that it was episode one of the series. As mentioned in the early part of this article, vobcopy requires a disk be mounted. So, I would mount the disk, then grab my file.
mount /dev/scd0 /mnt
vobcopy /mnt -n 2 -t episode01

The -n is for the title number. Although lsdvd showed it as 02, using -n 02 gave me an error, so I use 2. The -t is for the title I want to give it. After a minute or two, I then had a file episode01.vob

I then ran HandBrakeCLI to get me an mkv file. (Had I used mp4, I sometimes lose the subs)
HandBrakeCLI -i episode01.vob -s 1 -o episode01.mkv

The -s 1 was for the subtitle. In most cases this worked, but, as mentioned in the subtitle section below, with some episodes, for whatever reason, the subtitle would not show up. In those cases, as mentioned, I used mencoder to either encode with the subtitle or dump the idx/sub files separately so I could edit the idx file to make them easier to read.

Had I used HandBrake directly on the DVD, then I would have to specify the title there. (It shouldn't be necessary to mount the DVD, though if I did so, I could substitute /mnt for the /dev/scd0).
HandBrakeCLI -i /dev/scd0 -t 2 -s 1 -o 01episode.mkv

I never did figure out why HandBrake couldn't find the subtitle on these, (I tried a variety of options) but in many cases, the subtitles were in a difficult to read black, so I wound up extracting the subtitle file and editing the color palette. (Explained in the subtitle section) anyway. Then I would strip the original subtitle from the HandBrakeCLI created mkv file and merge the newly edited, easier to read file. This is explained elsewhere on this page, but the procedure would be
mkvmerge -S 01episode.mkv -o 01episodenosub.mkv
mkvextract tracks 01episode.mkv 3:01episode.sub

I should now have two subtitle files 01episode.idx and 01episode.sub. I edit 01episode.idx as explained below to make the subs easier to read, then make a new file.
mkvmerge 01episodenosub.mkv 01episode.idx  01episodenewsub.mkv

This segues nicely into our next section about subtitles.


Working With Subtitles

Subtitles can be a pain to embed. I've found it easiest to work with mkv files. The short version is convert your file or files into an mkv container, with ffmpeg or handbrake. If you want them embedded, then, merge them into the mkv file (if they're not in there yet) with mkvmerge, then use mencoder to change it to an avi, then use ffmpeg to change it to what you want. This is assuming that you have a file with separate subtitle files or perhaps even included. One can also use HandBrakeCLI to convert the mkv to an mp4.

While this has been more consistent for me than other methods, it doesn't always work. For example, sometimes, I've gotten the subtitles, and the music but no other sound, in other words, no dialog. Using ffmpeg, I can use -scodec (for subtitle codec) and encode a file to an mkv, and the subtitles will show up. Using ffmpeg will usually put the subtitles into an mkv container, but won't work if converting to mp4. It seems to be, judging from my experience, and a lot of googling, hit and miss. Here are a few things I've done to get it working--sometimes, at least.

There are various tools to convert to mkvs. One can use HandBrakeCLI among others. Using ffmpeg will also work if the subtitle is an external file, and may or may not work if converting your file (including subtitles) to an mkv.
HandBrakeCLI -i myfile.avi -o myfile.mkv
ffmpeg -i myfile.avi  myfile.mkv

Sometimes, if one downloads a public domain movie with subtitles, they might get the avi and separate subtitle tracks. You will have myfile.avi as well as myfile.sub and myfile.idx. If you want the subs hardcoded into an mkv file, we can use HandBrakeCLI or ffmpeg as described above, then mkvmerge. After converting the file to an mkv, you now have myfile.mkv, myfile.idx and myfile.sub
mkvmerge myfile.mkv myfile.idx -o myfile1.mkv

To find out what files your mkvmerge can work with, you can run mkvmerge -l (a lower case L, as in list). Doing this shows that it can handle idx, ass, and srt subtitle files. In the example, we used the idx/sub combo, but the same would work with srt or others. (You won't include myfile.sub in the command line.)

If we're happy with an mkv movie that has subtitles burned in, we're now done. More typically, the downloaded file has the subtitles already there, and we converted it to make it easier to work with the subtitles.

If you're more comfortable with srt files, there's little tool that will take a sub and idx file and turn them into a nearly perfect srt file, using the command line. It needs tesseract, which I didn't find on CentOS--I wound up using a more current Arch installation. The instructions on the author's site are for Debian and Ubuntu based distributions. If the reader is unfamilar with git, the way to get the program, before doing the configure and build the author mentions, is to run the command
git clone 

This will create a directory called VobSub2SRT in whatever directory you were in when you ran the command. At that point, you can follow the author's instructions. It should be a simple ./configure && make && sudo make install, but the README seems to be updated from time to time, so it's suggested that the reader check the above link for the author's latest information.

Using the program, by, for example, putting mysub.sub and mysub.idx in one directory, then just running vob2srt mysub will produce a file.

It doesn't always give perfect subtitles--for example, I've seen apostrophes come out as & signs, but usually does a pretty good job, though there are other times where the resulting srt file just wasn't usable.

On one or two occasions, I've wound up with a movie that had black subtitles. I suspect the encoders had younger eyes than I do, and wanted a the subtitles to be less intrusive, but to my aging eyes, they were difficult to read. So, first, I exacted the subtitles with mkvextract as mentioned, mkvextract tracks myfile.mkv 3:myfile.sub. This extracts both the idx and the sub file. Then, I edited the idx file. Around the 12th line or so, there's an entry for custom colors. I didn't really know what I was doing, but tried changing all the 000000 entries, which mean black, to ffffff, for white. The idx files use hexadecimal notation for color, as does HTML. Then, I merged the subs back in. With myfile.mkv myfile.sub and the revised myfile.idx, I used mkvmerge -o newfile.mkv myfile.mkv myfile.idx. When I played the movie, the subtitles were white, and much easier to read. I repeat, I wasn't quite sure what I was doing, and it's a good idea to back up your idx file before editing.

One combination that I've used several times (just taken from an idx file where I found the subs easy to read) is

palette: 5f5f5f, e7e7e5, 171717, fdfdfd, 942612, 0732af, f3ff5e, 2a2f6d, fdfdfd, 0732af, f6f6f4, f6f6f4, f5f5f3, f4f4f4, f3f3f1, f2f2f2
custom colors: OFF, tridx: 0000, colors: 000000, 000000, 000000, 000000

The palette: line should be on one line and the custom colors on the next line. This usually goes under the line reading forced subs: OFF (or ON as the case may be).

In the example below, we're going to use the idx/sub combination, but if the subtitle was in srt format the idea is the same.

First use mkvmerge --identify to figure out which track it is.
mkvmerge --identify myfile.mkv

You will get back something like
Track ID 1: video (V_MPEG4/ISO/AVC)
Track ID 2: audio (A_AAC/MPEG4/LC/SBR)
Track ID 3: subtitles (S_VOBSUB)
(Had it been in srt format, it might say (S_TEXT/UTF8) or something similar).

Now you know that track 3 is the subtitle track. You can also do this with ffmpeg -i myfile.mkv. In that case you will get back an error that it needs an output file, but you will also get back information, including

Stream #0:2(eng): Subtitle: dvd_subtitle

In this case, if it was in srt format, it would say Subtitle: text (default). One can also use ffprobe instead of ffmpeg -i.

Generally, the ffmpeg -i stream is one number less than mkvmerge --identify track. Regardless, we now know that to mkvmerge, it's track 3. We can now extract it.
mkvextract tracks myfile.mkv

The mkvextract program is able to determine the subtitle format. In this case, I've told it to extract to a srt file, but if the subtitle track turns out to be the idx/sub combination, rather than extracting it to, it will extract two files, myfile.idx and myfile.sub. So, I have myfile.mkv, myfile.sub, and myfile.idx in one directory. If I do any sort of conversion, and leave the idx and sub file in the same directory as the file, I can use the subs. In other words, ffmpeg -i myfile.mkv myfile.mp4 will, if I play the resulting mp4 file with mplayer, work, as long as the sub and idx files, (or whatever format, such as srt, the subtitle file or files use), are in the same directory as the mp4. By "work," I mean it will play the file with subtitles. Were I to run the above ffmpeg command, the subtitles will not be encoded into the new mp4 file. However, if they have the same name as the mp4 file, and subtitle file or files and mp4 file are in the same directory, mplayer will be able to use the subtitle file.

If I want to hardcode the subs into the file, I've only had it work with mencoder or HandBrakeCLI. With mencoder, I've had very mixed luck doing this. The automate-everything site has a fairly long string to do this and it sometimes works for me, but not always. If the subtitle file is just a srt file, then, using mencoder, with the option -sub may work.
mencoder myfile.mkv -oac pcm -ovc copy -sub -o myfile.mp4J

If not, according to a thread on Ubuntu forums when working with mkv files, use -slang instead.
mencoder myfile.mkv -oac pcm -ovc copy -slang eng -o myfile.mp4

but like the other mencoder options, it hasn't worked consistently for me. The examples use pcm, but one can use any of the available audio options. To find out which ones are supported by your version of mencoder, run the the command
mencoder -oac help

To find out which video options are available the command is mencoder -ovc help.

Another option I've seen, when I already merged the subtitle into an mkv file is a suggestion from 2004, from an mplayer mailing list thread. This one has worked for me on occasion, when others haven't. (And, like the others, at other times, has not worked) Although the post has several other options in there, the ones that I found to be needed for the conversion to work were
mencoder myfile.mkv -oac pcm -ovc lavc myfile.avi

On an mkv container file with srt subtitles, this worked for me when converting. As my version of mencoder doesn't have mp4 as an output file (you can find its available outputs with mencoder -of help), I would make the file into an avi. Now that I had an avi file with the hardcoded subs, I could now use ffmpeg to convert it to an mp4 file and the subs would work.
ffmpeg -i myfile.avi -vcodec libx264 -acodec aac -strict experimental myfile.mp4

In most cases, -strict -2 will also work. As far as I can see, this is the suggestion given with newer versions of ffmpeg.

The new mp4 would have embedded subtitles.

I've had somewhat better luck using HandBrakeCLI with some subtitle options. This took some trial and error for me. I didn't find the help page quite clear. Also, if using srt files (as opposed to idx/sub) this method only works with the somewhat outdated HandBrakeCLI 0.9.5. (Fear not, a solution is below). This syntax, assuming that we only have one subtitle in the mkv file is
HandBrakeCLI -i myfile.mkv --subtitle 1  -o myfile.mp4.  

There is also
HandBrakeCLI -i myfile.mkv --subtitle scan,1 -o myfile.mp4.  

I haven't quite figured this out yet, but the 1 refers to the subtitle number, meaning the first subtitle. If there are multiple subtitle tracks, then one would use --subtitle (or -s) 1,2, and so on. I think the scan option is only for subs of a language different than the main language of the file, though this is untested on my part--I haven't really figured it out. The documentation states, "A special subtitle track named 'scan' will add a Foreign Audio Search pass that attempts to detect and select the track which contains subtitles for foreign audio segments (if any) matching the language of the first audio track or the language defined via --native-language. Best used in conjunction with --subtitle-forced." I have no files where I can test this, but it seems as if when there is a film with a subtitle track in the film's language, and, an additional subtitle track only for a second language, for example, the scene in the Avengers where there is a brief segment of Russian, that would be when to use the scan option.

One can try to hardcode the subtitles in, but I believe this only works with vob subs, the type that, when extracted, will produce two files, a .sub and a .idx file.
HandBrakeCLI -i myfile.mkv --subtitle 1 --subtitle-burn 0 -o myfile.mp4.  

The numbers start at 1, but when using subtitle-burn, start at 0. I have found that with mplayer, when doing this, I have to specify the subtitle. In other words, if I run the command, then try to play myfile.mp4 with mplayer, I won't see anything. However, if I run mplayer -slang en myfile.mp4 I will usually see the subtitles. Other times, I've found that to fail, but it will work with mplayer -sid 0 (or sometimes -sid 1). Still other times, I've found that neither will work, but hitting the letter j, to cycle through available subtitles will work.

In CentOS 6.x, I use HandBrakeCLI 0.9.5, from the Linuxtech repo mentioned in the beginning of this article. So, with CentOS, I can use the above method for srt files as well. Hndowever, with HandBrake-0.9.6 and up, there are problems with .srt subtitles having many garbage characters included in the text. It doesn't seem to affect the sub/idx subtitle files.

When I found an older rpm (on the HandBrake sourceforge site) for 0.9.5, and installed it on Fedora 17, once again srt subtitle encoding worked perfectly. If you run into this, either try to get the older versions from their sourceforge site or, if the srt file is included in the mkv file, extract it with mkvextract then reinsert it with the --srt-file option.
mkvextract tracks myfile.mkv
HandBrakeCLI -i myfile.mkv --srt-file -o myfile.mp4

Be sure to use two dashes. If you use -srt-file, it won't give an error, but it won't work.

It's useful to only test with a small portion of the file, to see if you're getting what you want. Their help file isn't clear to me on this, but after trial and error I found that the syntax is--if, for example, you wanted to get the first two minutes of a file to test it
HandBrakeCLI -i myfile.mkv --start-at duration:0 --stop-at duration:120 -o

If you want the second 5 minutes of a video, the syntax is
HandBrakeCLI -i myfile.mkv --start-at duration:300 --stop-at duration:300
-o myfile.mp4

In other words, fairly similar to the use of ffmpeg's -ss and -t parameters.

You can substitute duration: with frames and use something like --start-at frames:0 --stop-at frames:2500 to get the first 2500 frames.

HandBrake's documentation is often rather obscure to me, and judging from googling results, I'm not the only one. If any HandBrake folks read this, giving some examples would be useful.

As for the older, 0.9.5 version although the sourceforge site said that it was for Fedora 15, the rpm installed without problems on Fedora 17. I wasn't able to get the tarball to build on either Fedora or ArchLinux.

As mentioned, I don't quite understand all the HandBrakeCLI subtitle options, but the above should enable you to include subtitles with your files. If you need to get it onto a DVD, once you've used HandBrakeCLI to include the file, using tovid, as explained above, should get you a DVD with a subtitle track, though the subtitles might be hardcoded--that is, you won't be able to turn them off.

Sometimes, one wants to remove the embedded subtitles. The only way I know to do this is by cropping. The syntax used to be simple with ffmpeg, it had a -cropbottom option, but that's been removed in favor of something that I find rather confusing. As it is, to crop 20 pixels from the bottom, as far as I can tell, you have to re-encode (using copy for acodec and vcodec doesn't seem to work), so the syntax would be
ffmpeg -i myfile.avi -vcodec libx264 -acodec aac -strict experimental -vf crop=in_w:in_h-20:0:0

According to the most recent ffmpeg docs the old options no longer work. The -vf is for video filter, the in_w is for the width of the orginal, the in_h-20 removes 20 pixels from the total height--but as I mentioned above, I'm still confused by this syntax, but the 20 pixels will come from the bottom. If you wanted it to begin at the top, then use in_h-20:0:20. That last 20 refers to the y axis, top to bottom. Archlinux user ronnylov gave a very good explanation in posts 5 and 7 in this archlinux forum thread. At any rate, in one case, where I needed to remove 68 pixels to get rid of some subtitles, using in_h-68:0:0 (the final 0's are for x and y axis, so, leaving them at 0:0 subtracts from the bottom), successfully removed the subtitles and didn't overly crop the film. The user is advised, unless they understand this better than I do, to experiment before making a final re-encode. (And perhaps use ronnylov's suggestion of using avidemux to get the parameters you want.)

I have had occasions where I would pull a VOB file from a DVD that I wanted to back up, and it would play with subtitles. However, if I used HandBrake, I wouldn't get subtitles in the output mkv file. Usually, even if not an mkv file, running mkvmerge --identify will show that there's a separate subtitle track, but in this case, it just showed a video and audio track. However, I was able to get an avi with subtitles by using
mencoder myfile.vob -ovc x264 -oac pcm -o myfile.avi

This gave me an avi file with the subtitles. I was then able to run HandBrakeCLI to create an mkv file, although it still wouldn't show me a separate subtitle track. However, the subs were in there, and I was able to turn them on and off.

If you run the above command with vobsubout it will give you a separate idx and sub file (assuming the original subs were in that format--in this particular case, where none of the normal methods were giving me the subtitle format, I had to guess). The syntax would be vobsubout outputfile, so in the case above, to have the subtitle files separate from the video, I would use
mencoder myfile.vob -ovc x264 -oac pcm -vobsubout myfile -o myfile.avi

At that point, depending upon what I want to do with the file, I can re-encode the avi to an mkv file and use mkvmerge to put the subtitles back in. One example might be if the subtitles were difficult to read, and I wanted to put in the palette and custom color lines mentioned above into the idx file.

One can easily create their own srt files with vi. It's just a textfile. If you look at any srt file, you'll see a pattern of number, time, and the title. For example
00:05:10,000 --> 00:05:14
This is my subtitle

00:05:20,000 --> 00:05:23,000
My second subtitle

The syntax is the number, time start time end and then the text. The time is hours, minutes, seconds, and milliseconds. (The one after the comma), and all seem necessary. It also seems necessary to include the empty line between the end of the subtitle and the number above the next one, as I have between the line saying This is my subtitle and the number 2 above the next subtitle.

Sometimes, the aim is the opposite, to get rid of embedded subtitles. Mplayer has a delogo option which makes somewhat of a blur and tries to blend with the surrounding colors. The syntax is
mplayer myvideo.avi -vf delogo=150:250:400:50:-1

The numbers refer to the X axis (left to right) Y axis (top to bottom), the width and height of the box and the border. The -1 creates a green border around the blur, which is useful when trying to place the blur. To make it more to the right increase the first number, to make it lower on the screen increase the second number. To make it wider, increase the third number and to increase the height, increase the fourth number. As mentioned, the last number is for the border. When you're happy with the placement, change the -1 to 1 and that should take care of the visible border.

Personally, I find that my usual player, mplayer, makes the subtitles a little too big for my taste. By adding the line

to my $HOME/.mplayer/config file, it makes them a little smaller, more to my taste. The default size is 3, so if they were too small for you, you can change the 2 to a 4 and see if that works better for you.


Making an mp4 or avi file from a DVD

The simplest way that I've found to do this is with HandBrakeCLI. If your dvd device is /dev/scd0 then
HandBrakeCLI -i /dev/scd0 -o myfile.mp4

One can use presets if desired, e.g HandBrakeCLI -i /dev/scd0 -o myfile.mp4 -Z "iPad". HandBrake, as we briefly discuss elsewhere has many other options that can be used, but the above should create a usable mp4.

A simple way to create an avi format would be to dump the DVD into a single vob file, as described earlier, either using mplayer or vobcopy. In the example, we'll use vobcopy. Then, run the vob file through ffmpeg. Several options are available. See this thread on for some examples. However, it can be done quite simply and still be watchable, although the quality may not be the best.
mount /dev/scd0 /mnt
vobcopy -i -m /mnt
ffmpeg -i MYVIDEO.vob myvideo.avi

To refresh the reader's memory, the mplayer command would be
mplayer dvd://1 -v -dumpstream -dumpfile dump.vob

While such simplicity might make purists gnash their teeth, it works, and is handy when, for example, one has a home made dvd from a camcorder that they wish to share with friends.


Merging avi or mp4 files (and adding a commentary audio track)

Sometimes, you might have several avi files and want to merge them into one larger file. There are a few tools for this. avimerge does exactly what it says. The syntax is
avimerge -o newfile -i file1.avi file2.avi

My biggest problem with it was that it would often go out of sync with the sound--so that when it neared the end of the merged file there would be silence--the entire sound track from both files had already been done. It does have a -c option, meaning that one should drop video frames, in case audio is off. The explanation from the man page is that some avi files run a little bit short on audio so that when merged avimerge loses sync. So, using the -c option, e.g., avimerge -o newfile.avi -i file1.avi file2.avi -c (judging from the man page--the syntax may be avidmerge -c and then the rest of it but neither worked for me), will, in theory drop enough video frames so that the audio remains in sync. As I said in the previous sentence, however, it didn't work for me. I would still wind up with a merged avi file with sound completely out of sync.

I've had luck with mencoder. I used the syntax from a page by someone named Wilt. The syntax I use, (taken from Wilt's page) is
mencoder -oac copy -ovc copy -noodml -o newfile.avi file1.avi file2.avi

That should be on a single line. The options are explained in the link above, oac and ovc are copy transfer mode for video and audio, noodml means don't write OpenDML index, -o is for the output file. This usually gives me a perfectly synced single avi file.

Sometimes, the audio format might be one that CentOS' version of mencoder won't copy properly, and I'll get an error. Sometimes, the error is specific and says that the audio is an unknown format, other times, it will be a more general error, to the effect that there may be trouble with the parameters. When this happens, I've always been able to fix it by using -oac pcm or other available codec. (See above, use mencoder -oac help to get the available oac options). Using -oac faac will also usually work. Once I've changed the -oac from copy to pcm or faac, it has always completed the command for me without problems.

Using -oac faac won't work on Fedora, Ubuntu, and probably some other distributions. Their versions of mencoder and mplayer don't have faac compiled into the system.

With mp4 files, as opposed to avi, there is MP4Box, part of gpac. The rpmfusion repo has a version for RHEL6. I've not had good luck with using it to merge mp4s, which is probably my own fault. I've had better luck with mkvmerge, merging two mp4s into an mkv.
mkvmerge -o new file.mkv file1.mp4 + file2.mp4

The two files will have to be the same resolution, that is, if you have one mp4 at 540x416 and a second one at 576x304, you will have to resize one of them. This could be done with
ffmpeg -i file2.mp4 -s 540x416 newfile.mp4

Then, the mkvmerge command should work properly.

I've also first converted avis to mkv containers with ffmpeg, e.g. ffmpeg -i myfile.avi -vcodec libx264 -acodec aac -strict experimental myfile.mkv and then used the mkvmerge command, but later learned that it isn't even necessary. One can run mkvmerge -o myfile.mkv myfile1.avi + myfile2.avi and it will work perfectly.

I have used MP4Box successfully to merge in audio files. For example, if one has an mp4 and an additional mp3 commentary track
MP4Box -add myvid.mp4 -add mycommentary.mp3 newfile.mp4

the commentary track should be in sync. I haven't found a program to play both audio tracks simultaneously, but if one wants to listen to the commentary in sync with the video, the above command will produce a properly synced video file. VLC or other players should allow you to choose which audio track to use when playing it. TOC

Working with mkv Files

The mkv format is becoming more and more common. As mentioned in the subtitle section, it's one of the best containers for keeping subtitles in the same container as the video.

Usually, tovid and ffmpeg can deal with them normally. The my-guides site has a good article on converting to avi with VLC.

Sometimes, I have run into issues trying to simply feed an mkv to ffmpeg. However, so far at least, I've always been able to use the -target ntsc-dvd option that I mention in the tovid section, to get reasonable mpg files.

I've also been able to strip out unneeded subtitles. For that one can either use ffmpeg to re-encode to mp4--as mentioned in the subtitle section, ffmpeg doesn't seem able to encode subtitles to mp4 from an mkv file, or use the excellent mkvtoolnix suite of tools.

For CentOS 6, I used the EPEL-testing repo. For information on CentOS repos, see their wiki article. I had to play around with its dependencies though--enabling epel-testing repo gave me an error about libcurl, but downloading the rpm directly, then doing rpm -ivh worked--it needed some boost-filesystem files, which I found usin yum provides */<missing_dependency>, e.g yum provides */ which was one of the errors.

One of the tools in the suite is mkvmerge. To remove subtitles from the mkv, use the -S option. The syntax is (if the original is called file.mkv and you wish the new file to be called newfile.mkv
mkvmerge -S -o newfile.mkv file.mkv

Generally, as ffmpeg already can have issues with subtitles, using ffmpeg -in myfile.mkv -target ntsc-dvd myfile.mpg may automatically strip out the subtitles. I'm not sure that that always works though, so it's handy to know the -S option of mkvmerge.

If such a thing happens, and you want to keep the subtitles, one can then extract them with mkvextract. This was covered in more detail in the subtitle section, but to repeat it, use mkvmerge --identify to get the number of the track--typically, track 1 is video, 2, audio and 3 subtitles.
mkvmerge --identify myfile.mkv
mkvextract tracks myfile.mkv

One problem I have run into with that is on some widescreen files. If you run mplayer myfile.mkv and hit ctl+C shortly afterwards, it might show that the aspect ratio is something like 2.21:1 or 2.50:1. What will happen is that it will create the mpg which is fine.

From there, I used the tovid's suite disc commands. However, I received a series of messages like WARN: unknown mpeg2 aspect ratio 4. When I tested the dvd file, it had squashed the wide screen into a square format, complete with distortion of the picture. The way around it seems to be to use an aspect ratio of 16:9 with
ffmpeg -i myfile.mkv -target ntsc-dvd -aspect 16:9 myfile.mpg

This still seems somewhat square, but it works. I've not yet found a good solution for this problem. Some folks use padding, others use -s as in size rather than -aspect, but I've yet to find the perfect solution for that pesky 2.21:1 (or 2.40 or 2.50) aspect ratio.

A thread with several suggested solutions can be found here, but none were perfect for me.

One handy option for ffmpeg when testing this is the vframes option. If I'm testing an aspect ration, I only need a minute or so of the file. I can run something like
ffmpeg -in myfile.mkv -aspect 16:9 -vframes 2500 myfile.mpg

This way, rather than waiting for the entire file to be converted, it will only work with the first 2500 frames, taking a minute or so. I can then play the mpg file and see if I am happy with the new aspect ratio.

One should also note that the mpg file will usually be smaller than than the mkv file, so that even if one is working with a 7 GB mkv file, the result might be burnable to a standard 4.7 GB DVD. (Of course, using the tovid suite also took care of it, tovid puts all those options in for you. Although I mention the --split option of mkvmerge below, if the reason for using it is to hope to get an mpg file that will fit a normal size DVD, it may be unnecessary. For example, I've had 6.6 GB mkv file, and after running tovid on it, to turn it into an mpg, the mpg was only 1.6 GB.

As for the aforementioned mkvmerge--as it name implies, it can merge files, but it can do several other things. The general syntax is mkvmerge --[various options, such as split] -o (outfile) filename. Despite the merge in its name, it can also split files based on time or size. For example, if you had a 7 GB mkv file that you wished to split into two smaller mkvs, of about 4 GB and 3 GB, you can run
mkvmerge --split size:40000m -o output.mkv myfile.mkv

This will create 2 files output-001.mkv and output-002.mkv. The man page goes into more detail. One can also do it by time, as per the example in the man page. To split after an hour's duration
mkvmerge --split duration:00:60:00.000 -o output.mkv myfile.mkv

The format, according to the man page, must have the form of HH:MM:SS.nnn or be in seconds, e.g. --split 3600s. The man page goes into more detail, also noting that it will split right before the next key frame, so the division might not be exactly what you expected.

The mkvinfo file mentioned above can also be useful for things like removing subtitles, especially if you wanted to use the ffmpeg -map option previously mentioned. Just run mkvinfo myfile.mkv to get various information about the file, including the audio and video and subtitle, if included, track.

I found one other useful mkvmerge trick from an article on I wanted to combine a cd1.avi and cd2.avi. However, they had subtitles. In this case, rather than a srt file, each avi had its respective .idx and .sub files--one needs both in order to get the subtitles working. However, with the trick from this article, I was able to make each avi file into an mkv with the subs hardcoded into the file. With cd1.avi, cd1.sub, and cd1.idx all in one directory, I ran
mkvmerge -o cd1.mkv cd1.avi cd1.idx

I then did the same with cd2 so that I now had cd1.mkv and cd2.mkv. To combine them I used mkvmerge with a + to append rather than add, as the man page puts it.
mkvmerge cd1.mkv + cd2.mkv -o newcd.mkv

However, when I wanted to burn this to a disk, tovid, even using mencoder instead of ffmpeg, didn't do it properly. In the end, I googled various methods of harcoding the subtitles into the mkv using mencoder. As I had mixed results, and didn't keep track of what I was doing, I advise the reader to just google, using a term like hardcode subs with mencoder. If the included subtitles consist of a sub and an idx file, then I've had success with first making it into an mkv as mentioned, then using mencoder with
mencoder -slang eng -of lavf -lavfopts format=mp4 -oac lavc -ovc lavc
-vf harddup file.mkv -o file.mp4

This hardcoded English subs into an mp4 file. From there, I was able to make an mpg with tovid.

One can also try with HandBrakeCLI as discussed in the subtitle section.

If the subtitle file is a single .srt textfile, it can be sometimes be done more simply with something like
mencoder mymovie.avi -sub -o movie_hardsub.avi -oac copy -ovc lavc -lavcopts vbitrate=1200

If the quality is bad, then try playing with different ovc formats. Although mencoder's mencoder -ovc help says that lavc produces the best quality video, I've sometimes had better luck using -ovc x264

To test quality, one can first use the mencoder option -endpos (ending position)to make a 50MB file and play it to see its quality. For example
mencoder mymovie.avi -sub -o movie_hardsub.avi -oac copy
-ovc lavc -lavcopts vbitrate=1200 -endpos 50mb

On occasion, one might find themselves with a collection of mkv files with numerical suffixes, such as file.mkv.001, file.mkv.002, file.mkv.003 and so on. In this case, it's usually been split at the binary level and rather than using mkvmerge to combine them, just use
cat file.mkv* > newfile.mkv

One other useful mkv oriented program is makemkv. It has both a GUI, which I've hardly used, and a commandline version. Its home page is at The Linux version links are given on their forums. The link also gives building instructions. It has a list of packges needed for Ubuntu. The CentOS or Fedora user would need expat-devel and openssl-devel if they aren't already installed. If you get errors that other files aren't found during the attempt to build the file, it will usually say which files are missing, in which case, one can use the yum provides option to find what packages are necessary.

Once installed, one can open the GUI with makemkv or use makemkvcon, which is less intuitive. There are some brief instructions here.

Basically if you want all of the titles (say an instructional dvd that has a few sections), and wants them stored in a directory called mymkvs, if the machine only has one DVD drive then use
makemkvcon mkv disc:0 all mymkvs

The program will then create the various titles as separate mkv files, starting with title00.mkv. I've only needed to use it when I wanted multiple titles from a DVD. If one wants to make it into one file, one can then use mkvmerge as mentioned elsewhere in this article.
mkvmerge -o new.mkv title00.mkv + title01.mkv


Reducing file size of avi and mp4 files

I've seen several methods to do this. The one that works most consistently for me, usually with very little impact on quality is
ffmpeg -i myfile.avi -vcodec libx264 -acodec aac -strict experimental myfile.mp4

I change the video codec to libx264 and the audio codec to aac. I've found that on CentOS 6.x, Fedora 17, and Arch, current as of August 2012, aac requires the -strict experimental option.

In more recent versions, if one forgets to add that, messages say use -strict -2. One can use either -strict -experimental or -strict -2 and the result will be the same.

Here are a few others that I've tried.

This one is directly taken from this Ubuntu blog. I'm afraid it didn't work consistently for me, but the reader may find it useful. For me, it often left me with overly pixelated files.
ffmpeg -i input.avi -vcodec msmpeg4v2 smaller.avi

A suggestion for shrinking mp4 files is to change the acodec to mp2, and in one quick test, that went pretty well.
ffmpeg -i input.mp4 -acodec mp2 smaller.mp4

It reduced a 166MB mp4 file to 98MB with little loss (to a non purist) of quality. The user is advised to judge for themselves whether the lost of quality is a problem for them.

Going back to avi files, I found that converting the avi to mp4 with ffmpeg reduced the size from 176MB to 86MB. In some cases a simple ffmpeg -i file.avi file.mp4 gave me an error of
Error while opening encoder for output stream #0:1 - maybe incorrect
parameters such as bit_rate, rate, width or height

Apparently this was an audio compatibilty issue and using ffmpeg -i file.avi -acodec copy file.mp4 fixed the problem. (In other cases, one might need to use aac -strict experimential). In this case, once the file was converted to mp4, trying to compress it further with the -acodec mp2 command only made it a few megabytes smaller, so I wouldn't bother trying for further reduction in size.

Going back to using libx264, on a 1.1GB avi file using
ffmpeg -i myfile.mp4 -vcodec libx264 -acodec copy outfile.mp4,

the size was reduced to about 880MB, with no noticeable loss in quality. The size difference will depend upon the file, obviously.

Using the -s for frame size option and playing with the size may also help, depending upon what you will be using to watch the video. So changing the size to say, 320x240 will shrink a movie, but, always depending upon the original, may result in an unacceptable loss of quality. If you want to try it, I recommend using vframes, mentioned elsewhere, to test it before shrinking the whole movie.
ffmpeg -i myvideo.mp4 -s 320x240 -acodec aac -strict experimental
-vframes 3000 test.mp4

This only runs through 3000 frames of the movie to give you a sample. The man page, if you search for the frame size section, may give you the acceptable dimensions.

At times, for whatever reason, ffmpeg would come back with an error but mencoder would work. With mencoder, I can get similar results to ffmpeg with
mencoder myfile.avi -ovc x264 -oac faac -o myfile.mp4

I haven't found anything to be completely consistent, but for me, using -vcodec libx264 -acodec aac -strict experimental, and leaving the size alone, gives me (generally) reasonably good results. If you lose volume, you can often gain it back with
ffmpeg -i mynewfile.mp4 -vcodec copy -acodec aac -strict experimental
-vol 512 louder.mp4

(That's on CentOS. If I use -acodec copy, I get an error that one can't use it with the -vol parameter. The default volume is 256, so doing 512 should, in theory, make it twice as loud. In practice, I find that usually I run it once, which makes it slightly louder, then run it again on the new file, which seems to make the volume reasonably loud. Doing it once with -vol 1024 doesn't seem to work as well, but I haven't tested this very much. Just remember 256 is the default volume, so to raise it, use the -vol parameter with multiples of 256. (I suppose they don't have to be multiples, but I've not tried it. The only times I've used the -vol parameter, the thing was much too quiet, so I used 512.)


Downloading Multiple Files from Rapidshare (With a premium account)

As those who have gotten a longterm or short term Rapidshare account know, it doesn't make it all that easy to download a series of files. Sometimes, the uploader might have split their files into several rar files. I came across this tip recently, and thought I'd share. I don't know how one can do it without a premium account. My version is exactly the same as the page I used, on'm simply repeating the instructions here to save the reader a bit of skipping around. (The site has many other useful articles, many of them about working with media files).

This is being used with the very kind permission of the author.

Assume that your Rapidshare username is john and your password is 1234. Make a directory in your home directory, .cookies. (Note the dot before the name, this keeps it a hidden file). Now run the command
wget --save-cookies ~/.cookies/rapidshare --post-data
"login=john&password=1234" --no-check-certificate -0 - > /dev/null

That's all one line (or one can break the line with \ as is done on the original link.)

Note that that is an upper case letter o, not the numeral zero.

Next, make a shell script. (Again, this is exactly the same script that Axel gives at my-guides.)
for url in `cat $1`
 wget -c --load-cookies ~/.cookies/rapidshare $url

Save it somewhere in your $PATH, for example, $HOME/bin, and call it Make it executable with chmod 755

Now, if you have a list of urls, such as, rather than having to go to each url, make a list of all the urls and save them as a file called urls, which might read

(As we all know, the urls are much longer than that, and more of a nuisance to type.) Now, to get your batch of files just type url

Again, this is taken EXACTLY from the and many thanks to Axel, the author, as it was just what I needed.


Working with rar files

If using Rapidshare or other download sites, a large file may be distributed as a group of .rar files. Sometimes, this is because of upload limits, where nothing over 15MB can be uploaded. Although rar is not GPL software, the vast majority of distributions have a package available, if not in their official repos, in some sort of third party repo. For example, in CentOS, both rar and unrar are available from rpmforge.

If, for example, your friend has made a DVD of their child's dance recital, they may have uploaded it as a series of rars. This will usually have a suffix of something like dance.001.rar, dance.002.rar, and so on. They may also appear as dance.r001, dance.r002. They will usually have either an r00 (or 00.rar), or possibly a number starting at 02. (See below when I explain creating rars.) I'm not sure how Windows rar programs do it, but it's usually fairly easy to figure out. There might be a series such as r001, r002 and one file with a suffix of .rar. In any case, figure out the first file--if you guess wrong, you'll probably get an error message. Assuming it was in the format of r001, r002 and one file with a rar suffix, and that that file is called dance.rar, the syntax is
unrar e dance.rar

You will see it gradually decompress the files, and when it finishes, you will have an avi, iso, or whatever the original file's format was. If there is no separate rar file, and they're all listed as 001.rar, 002.rar, then run unrar on the lowest number, e.g., unrar e dance.002.rar.

One important point, at least in CentOS' and FreeBSD's versions of rar and unrar is that the command must be run as shown above. If you run rar -e dance.rar, you'll just get a list of available options. (Note that you don't actually need unrar, as rar e will do the same thing as unrar e.

Sometimes, the sender will have an sfx file. This is a self-extracting executable and you can run unrar on that. In that case, the file names will be something like dance.01.sfx, dance.02.rar. One can run unrar e (or rar e) on either the 01.sfx or 02.rar and it will work, it doesn't seem to matter.

Creating rars

The rar license is listed as try before you buy. Take a look at /usr/share/doc/rar-<version>/license.txt, and if you feel you use it enough to order it, open the order.htm in a browser. (In FreeBSD, it will be in /usr/local/share/doc/rar). A free, as far as I know, alternative is p7zip, which can do the same thing. The Linux version of unrar, to only open rar files, as opposed to creating them, is free as in Free Diet Mountain Dew. I don't make rar files, so I didn't purchase rar, but the last time I looked, I believe the cost was $57.00. One can use p7zip instead of unrar too--rather than use the unrar command to extract files, use 7z with the same options, described below. (That is, 7z a to create several smaller files and 7z e to unrar files).

Much of this depends upon who you might be sharing files with--if they're your family, they might find it easier to work with rar files. The very few times I've done this were to send Linux iso files to someone who was unable to find a download site, so we used p7zip, so I really don't know--I assume, but it's only an assumption, that the rar format is more popular because it's a more common MS format, though p7zip should work with either unrar or the Windows only 7-zip app.

Regardless, to create a rar archive, the simplest method is to first create a directory, as it will create 50 or more files, depending upon the size of the original file. So, we'll create a directory, copy the dance.avi into it, and make a rar archive. Assuming we are in the directory that contains the dancevideo, which we're calling dance.avi
mkdir dancevideo
cd dancevideo
cp ../dance.avi .
rar a -v15m dance

You will see it creating the rar files. The a is for add. Again, note that like the e for extract, there is no leading -. For those less experienced with command line, the cp ../dance.avi . has a space and period after the file name. That single period means current directory, so we are copying the dance.avi to the current directory.

The -v15m means each file will be 15 Megabytes. Oddly, in CentOS, if I then did a du -sh on the individual rar files, they showed as 16 Megabytes---to get a du -sh of 15MB, I had to use -v14m. I don't know why. CentOS is the only Linux I've tried it with so I don't know if it's just one more thing that RedHat doesn't do right or if it's a Linux thing. FreeBSD works as expected, if one uses -v15m each rar is 15 Megabytes.

The p7zip program should be available in most distributions. It should also pull in p7zip-plugins. (The names may differ between distributions--I think Ubuntu calls it p7zip-full which brings in both programs). It provides 2 programs 7z and 7za. 7z handles more formats, 7za is a standalone executable. For our purposes, we can use 7z.

Therefore, the actual command is 7z. So, to use it to create an archive
7z a -v15m dance

This will create files called dance.7z.001, 002, and so on. One would extract them the same way as unrar, 7z e dance.7z.001. As mentioned in the rar section, if someone sends you a rar archive, you can extract it withe 7z e whatever.rar (or r01, or sfx).

7z seems to be a bit faster than rar. I've only benchmarked it very roughly (using the time command to unrar something), so don't take that as a definite fact. Also, once again, in CentOS, using -v15m results in files of 16MB, so once again I use -v14m when making a 7z archive in CentOS.


Using Lightscribe

Lightscribe is an interesting technology that allows you to burn labels or images on a disk. I decided to try it after some (possibly justified) complaints about my sloppy labeling.

LiteOn and LG, to name two, make inexpensive, lightscribe capable burners. Lightscribe capable DVDs are usually available, if you look around, for little more than the cost of normal DVDs.

Once the burner is installed, for rpm or deb based distros, the software can be downloaded from Lightscribe's site. First get the system software. You can then get the simple labeler software as well. This creates a directory in /opt called lightscribeApplications. To run the labling software run /opt/lightscribeApplications/SimpleLabeler/SimpleLabeler. It allows you to enter text--you can choose fonts from your system fonts. It creates a very simple label, both top and bottom text if you desire, that is, on each side of the center hole.

If, when running the application, it says something like no lightscribe drive available, try adding the following at the end of your /etc/lightscribe.rc

Note the semicolons at the end of each line--I missed that and wasted a good deal of time on google. Now try running the application again.

Most of Lightscribe's applications are for Windows and/or OSX. For somewhat fancier labels, you can use LaCie's software. The only way I was able to download the 4L lableling software (the lightscribe driver itself can be downloaded from their site, but it seems to be older than what's available at, was to use the link provided on the fedorasolved site, running the command

However, it may be available in your distribution's repositories.

I've been using the 4L software with the's lightscribe software without problem, as opposed to using LaScrie's lightscribe driver with the 4L software. However, either should work.

After installing the 4L software, you can run it with

This opens a menu that allows you to import image files by clicking (at time of writing) the uppermost left icon. From there, playing with the icons at bottom, you can fit it to the height and/or width of the disk, or manually scale the image. After that, clicking the upper right icon burns the image to disk.

In Linux at least, one can only make a cover in black and white. I usually convert an image to grayscale, using ImageMagick's convert function.
convert -type grayscale foo.jpg foo_bw.jpg

If backing up a movie, one can search for a cover at or similar site.

One last note. On rare occasions, 4L (or SimpleLabeler) might tell you that it doesn't see a LightScribe writeable disk and that you should clean the disk according to the LightScribe documentation. This may be due to a small smudge on the inner ring, around the hole in the DVD. That inner ring has some data used by LightScribe. So, if you get that message and the label side seems clean, try cleaning the inner ring of the DVD. The one time it happened to me, I just wiped it with a dry cloth, and after that, it was fine.


Converting files for iPad

There are a few ways to do this. Many people don't realize that avi is simply a container. Your video may already be a usable mp4. One can find out by running ffmpeg -i myfile.avi. If you then get something like video mpeg4, it's likely that if you rename it to myfile.mp4 it will play on your iPad. It might, however, be relatively small in size.

HandBrake is a nice GUI tool that has both iPod and iPad preformats. It also has a command line version, HandBrakeCLI. The 0.9.5 version has an iPad preformat. In that case, one can run
HandBrakeCLI -i myfile.avi -o myfile.mp4 -Z "iPad"

The -Z is for preset. Sometimes, it's taken much longer than ffmpeg, other times, it's been quicker. I haven't found a pattern, nor can I say one uniformly produces better or worse quality than the other. It depends upon the source.

I usually just compile HandBrakeCLI. I've not had success with recent subversion on CentOS, but did get the latest tarball (0.9.5 at time of writing) to work on CentOS 6.x. On other distros, I get it with subversion.
svn checkout svn:// hb-trunk
cd hb-trunk
./configure --launch --disable-gtk

That's going by the online instructions. However, they tend to not work for me, which might simply be my lack of understanding.

I've had more consistent success with using ./configure --disable-gtk (that is, without using launch) This creates a build directory. Then, chang into the build directory and run make . This actually only makes the build, so when it was done, run make clean. This creates the binary. In other words one might be best off doing
.configure --disable-gtk
cd build
make build  
make clean
sudo make install

(Assuming you've built it as regular user, which you should, and then install it.)

Or, possibly make -j4 build clean. And, sometimes, it's worked perfectly for me to just run ./confgigure --disable-gtk, then cd into build and run make once, creating the binary. I've really gotten no consistency with build attempts on different distributions--all of these methods have sometimes worked and sometimes caused errors, and I've not figured out the reason.

To summarize, sometimes it has worked by following the instructions and doing ./configure --launch --disable-gtk, sometimes it has worked by doing ./configure --disable-gtk;cd build;make, sometimes I have had to, after cd-ing into build, run make twice, sometimes I have had success doing make build clean, and so on. So, I would start by trying the --launch one, if that doesn't work, doing ./configure, cd-ing into build and running make, then running it again if no binary is created. If I ever figure out something that works for me on all distributions, I'll post it here.

So far, on the few movies where I've needed the subtitles, I've first hardcoded them in with tovid (making sure to use mencoder rather than ffmpeg--see the tovid section), then run HandBrakeCLI on the resulting mpg file, or with mkvmerge. (Which is much quicker.) For mkvmerge, the syntax would be
mkvmerge -o newfile.mkv myfile.mkv

On a 30 minute 105MB mkv file, it took about 3 seconds. However, this too has been inconsistent. Although the resulting newfile.mkv had the subtitles showing up with mplayer, when I used HandBrakeCLI to make it into an mp4, the resulting mp4 didn't have the subtitles. So, at this point, it seems that when I do need it for an iPad, I'll stick with tovid mpg -in myfile.mkv -subtitles -out myfile. I suspect I'm missing something, and when I figure it out, I'll post it here.

The trouble with using ffmpeg on this is that you'll have to find a guide that matches your system. One can just do a straight ffmpeg -i myfile.avi myfile.mp4, but while it will be watchable, the format may not be that good. Some guides will say use -acodec aac and then you'll use a different system and find that in that case, aac is unknown. Google, and you'll find that you should use libfaac on that distribution. (Or vice versa). In some cases, libfaac won't work, and if you use aac you are told that you must add strict experimental to the command line. It can be a bit frustrating. If you do get that error, the syntax is ffmpeg -i myfile.avi -acodec aac -strict experimental out.mp4 Another possibility, that I've found this one useful for flv files as well, is use -vcode and -acodec copy, which doesn't re-encode, but does change the format. Thanks to a Learnosity post.

ffmpeg -i myfile.flv -acodec copy -vcodec copy output.mp4

Or, if your distribution has it, libfaac for audio.
ffmpeg -i myfile.flv -vcodec copy -acodec libfaac -aq 200 output.mp4

The -aq 200 is to improve audio quality. That one doesn't work on CentOS 6.x, I get unknown encoder libfaac, although the various faac packages are installed. Note that below I mention using libfaac, that was on CentOS 5.x. As I said, it's often difficult as different distributions and different versions of a distribution will have different names for a particular codec. Lately, however, it seems that in most cases, with ffmpeg, using -acodec aac -strict experimental has been working well for me.

I've had the best results with the conversion matrix. The only thing different was the vpre option. There's is -vpre iPod640, however, on CentOS, one must use ipod rather than iPod. (The -vpre presets are listed in /usr/share/ffmpeg.)
ffmpeg -i myfile.avi -acodec libfaac -ac 2 -ab 160k -s 1024x768 -vcodec libx264 -vpre slow -vpre ipod640 -b 1200k -f mp4 -threads 0 outfile.mp4

That worked with two out of the 3 videos that I played with. If that doesn't work for you, on CentOS, I've also used 19 ffmpeg commands for all needs. I was able to use the following on CentOS 5.6 with success.
ffmpeg -i source_video.avi -acodec libfaac -ab 128kb -vcodec mpeg4 -b
1200kb -mbd 2 out_video.mp4

This usually works--on occasion, it will give an error which will include timebase not supported by mpeg4 in which case, you can usually fix it by adding -r 25 as a parameter. In other words
ffmpeg -i source_video.avi -acodec libfaac -ab 128kb -vcodec mpeg4 -b
1200kb -mbd 2 -r 25 out_video.mp4

The size should be 1024x768, but I find, using this syntax rather than the other one with the -vpre option that if I put -s 1024x768 in the ffmpeg command line, when copying the file to an iPad, iTunes will say it can't be played on this iPad. I haven't found the solution for this.

Either way, it seems more dependendent upon the size and ratio of the original avi. Even when the -s 1024x768 didn't give me an error, (in the first example, using -vpre), it still didn't play full screen. This is quite possibly due to an error on my part, but even using HandBrake, the video didn't come out as 1024x768.

Once the file is converted, you can transfer it to a Mac (or Windows machine with iTunes), add it to your iTunes library, then transfer it to your iPad.

One might have an instructional video dvd with a navigation menu and titles. I've never gotten one of these working successfully with an iPad, even when using its version of VLC. I've only been able to get the entire video on the iPad, without the chapters, but playing them in sequence.

First I mount the DVD and use vobcopy to mirror the disk, then I look at the size of the VOB files, cat them into one large VOB file and use HandBrakeCLI on that file.
mount /dev/scd0 /mnt
vobcopy -m -i /mnt MYVIDEO

In any case when I have done this, there was a only a VIDEO_TS directory, no AUDIO_TS. Next I look at the size of the VOB files. Giving an example from an actual DVD exercise video. Remember, we're already in the MYVIDEO directory.
du -sh *VOB
76K	VTS_01_0.VOB
1.1G	VTS_01_1.VOB
1.1G	VTS_01_2.VOB
1.1G	VTS_01_3.VOB
616M	VTS_01_4.VOB
120K	VTS_02_0.VOB
27M	VTS_02_1.VOB

Anything less than a megabyte is probably spacer. The 27 megabyte file is may be some sort of disclaimer, along the lines of we take no responsibilty if you hurt yourself. The user can check each VOB file with mplayer to confirm what they want. In this case, I know that I want VTS_01_1,2,3, and 4. So, I make one large VOB file which will run the various sections as one large video.
cat VTS_01_1.VOB VTS_01_2.VOB VTS_01_3.VOB VTS_01_4.VOB > mynewvid.VOB

Then I can run HandBrakeCLI on the mynewvid file.
HandBrakeCLI -i mynewvid.VOB -o MyExerciseVid.mp4 -Z "iPad"
and put it on an iPad in the usual way.


A quick note on OSX dmg files

There are various programs to convert OSX dmg files to iso format. I've hard partial success with Acetoneiso. I didn't find a CentOS version, but once again, just ran it in a virtual machine running something more current. I'm not going to go into great detail here, it's a GUI program that is fairly intuitive. To convert an OSX dmg file, the web page has some documentation. One point worth mentioning is that they recommend, rather than burning a dmg directly to an iso, one extracts the dmg to a directory, then makes an iso from the directory. (These are all options in the menu.) The first time one does this, there will be a message suggesting that the user downloads and installs poweriso, which doesn't have a GPL license. Click ok and it will download and extract the necessary binary.

The problem is that it only works on some dmg files. Many times, it will error out, saying it's not a proper dmg file, or something similar. Other times it works like a charm. Your mileage may vary.

As every time I've seen someone post the question about how to burn a dmg on a Linux machine on a forum, someone who doesn't know the answer asks, you shouldn't do that, why are you working with proprietary software on Linux, or something equally only relevant to those who don't use Linux for actual work, let me explain that anyone who works in an environment where both Linux and OSX are used might have a reason to do it. Perhaps the IT department only has Linux and Windows machines, with OSX reserved for customer service, and one has to distribute a properly purchased and licensed program to various users. That's just one example. Sometimes, the Mac users are doing something resource intensive--my own, non-benchmarked impression is that my Linux box uses less resources, and takes less time than using OSX's builtin burning programs. At any rate, there are various reasons it might be easier to do it on the Linux machine,

However, as mentioned, it doesn't always work. One can also try running mkisofs on a dmg, burning it to a DVD and seeing if it works. For example
mkisofs -o myimage.iso myimage.dmg

Then the usual
growisofs -dvd-compat -Z /dev/scd0=myimage.iso

Like acertone, this one doesn't always work.

The poweriso program itself, is another that sometimes works. It can be downloaded here. It's a tar.gz of the binary. Extract it with (version number may change, it's 1.3 at time of writing)
tar xvf poweriso-1.3.tar.gz

This will give you a binary file called poweriso. Move the binary to your $HOME/bin, or /usr/local/bin.
mv poweriso /usr/local/bin

To use it to convert a dmg to a burnable iso file, run
poweriso convert myfile.dmg -o myfile.iso

There are a few other options with the tool. Run poweriso -? for a list.

The easiest way, of course, if one does have a Mac, is to right click on the image and choose burn to disc, but as mentioned above, sometimes, it is simpler to create a DVD on another machine for various reasons.


As mentioned, my main reason for this article is to save myself some time. It is hoped that the reader finds at least some of it to be useful.