FFmpeg DVD

Introduction
This page will show how to create a DVD and converting different popular video file formats.

Converting File Formats
ffmpeg -i film.avi -target pal-dvd dvd.mpg

DVD Authoring
Make dvd files without menu in a dvd/ folder...

dvdauthor -o dvd/ -t dvd.mpg

Create the table of contents...

dvdauthor -o dvd/ -T

DVD Burning
Now burn the DVD...

growisofs -Z /dev/dvd -dvd-video dvd/

Converting From One Format To Another
Command line to convert a large HD (1280x720) video at 1Gb into a smaller 350Mb video...

ffmpeg -y -i input_file.m4v -s 640x360 -aspect 16:9 -f avi -vcodec mpeg4 \ -qscale 3 -acodec libmp3lame -ab 128k -ac 2 -ar 44100 output_file.avi

Command line to convert a Full HD mkv video at 17Gb into a smaller HD avi video at 2Gb but keeping excellent quality...

ffmpeg -y -i input_file.mkv -s hd720 -f avi -vcodec libx264 -vpre hq -crf 22 \ -threads 0 -b 1152k -acodec libmp3lame -ab 128k -ac 2 -ar 44100 output_file.avi

Before and after (the 4 hours of re-encoding [on a Quad-Core with 8Gb of RAM])...

-rw-r--r-- 1 paully paully 17G 2010-08-31 22:43 input_file.mkv -rw-r--r-- 1 paully paully 2.1G 2010-09-01 05:12 output_file.avi

Using Mplayer On An ISO To Produce A VOB File
mplayer dvd://1 -dvd-device mydvd.iso -chapter 1-1 -dumpstream -dumpfile mydvd-1.vob

Extract Just The Audio Track From A Video File
This command will jump to a specific point in the video then only get 30 seconds of mp3 audio...

ffmpeg -i input_file.avi -ss 00:03:51 -t 00:00:30 -acodec libmp3lame -ab 128k -ac 2 -ar 44100 output_file.mp3

Installing the SVN Release of Ffmpeg in Ubuntu Linux
Uninstall and Install the necessary software...

sudo apt-get remove ffmpeg x264 libx264-dev sudo apt-get update sudo apt-get install build-essential subversion git-core checkinstall yasm texi2html libfaac-dev \ libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libvorbis-dev \ libx11-dev libxfixes-dev libxvidcore-dev zlib1g-dev

Create the necessary new application install directories...

sudo mkdir /usr/local/include sudo mkdir /usr/local/lib/pkgconfig sudo mkdir /usr/local/share/man

Install x264 first...

cd sudo rm -rf x264/ git clone git://git.videolan.org/x264.git cd x264 ./configure --enable-static make sudo checkinstall --pkgname=x264 --pkgversion "svn`date +%Y%m%d`+`git rev-list HEAD -n 1 | head -c 7`" --backup=no --default cd which x264 x264 --version echo x264 hold | sudo dpkg --set-selections

Then install ffmpeg... (old way using svn now deprecated - "svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg")

cd sudo rm -rf ffmpeg/ git clone git://git.ffmpeg.org/ffmpeg.git ffmpeg cd ffmpeg ./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac \ --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvorbis \ --enable-libx264 --enable-libxvid --enable-x11grab --enable-pthreads make sudo checkinstall --pkgname=ffmpeg --pkgversion "svn`date +%Y%m%d`+`git rev-list HEAD -n 1 | head -c 7`" --backup=no --default cd which ffmpeg ffmpeg echo ffmpeg hold | sudo dpkg --set-selections

Cropping The Black Bars
You would not believe the lack of SIMPLE, clear documentation with _examples_ on the internet for this!

It took me over 2 hours of mucking around to get this right...

Basically, you resize your picture, crop from the top, and then state your finished picture size.

The magic formula was scaled height - cropped height divided by 2 e.g. 720 - 544 / 2 = 88

It makes perfect sense now, but why has no-one provided examples for dummies by now?!

ffmpeg -y -i input_file.mkv -s 1280X720 -vf crop=0:88:1280:544 -f avi -vcodec libx264 -vpre hq \ -crf 22 -threads 0 -b 1152k -acodec libmp3lame -ab 128k -ac 2 -ar 44100 output_file.avi

-s the scaled picture size to start cropping -vf the video filter to use crop=pixels_from_left:pixels_from_top:final_picture_width:final_picture_height

xVid Compatible AVI
ffmpeg -y -i Title_S01E09.vob -f avi -vcodec mpeg4 -vtag xvid -b 1152k -mbd rd -flags +mv4+aic \ -trellis 2 -cmp 2 -subcmp 2 -g 300 -pass 1/2 -acodec libmp3lame -ab 128k Title_S01E09.avi

x264 Presets
These are the new main x264 presets. In a nutshell, the slower the encoding produces a better quality and smaller size file.


 * ultrafast
 * superfast
 * veryfast
 * faster
 * fast
 * medium (32 fps)
 * slow (16 fps)
 * slower (8 fps)
 * veryslow (4 fps)
 * placebo (2 fps)

** UPDATE - Monday, April 25 2011 **

You call the x264 presets with ffpmpeg differently now.

(OLD METHOD)  -vcodec libx264 -vpre veryslow (NEW METHOD)  -vcodec libx264 -preset veryslow -tune film

MKV To AVI Script
# # # # # INPUTFILE="$1" X264PRESET="veryslow"   # (superfast,veryfast,faster,fast,medium,slow,slower,veryslow,placebo) OUTPUTFILE="$2" if [ ! $# == 2 ]  then echo "Usage: ./mkvtoavi.sh input.file output.file" else time ffmpeg -y -i "$INPUTFILE" -s hd720 -f avi -vcodec libx264 -preset "$X264PRESET" -crf 22 -threads 0 -b 1152k -acodec libmp3lame -ab 128k -ac 2 -ar 44100 "$OUTPUTFILE" fi
 * 1) !/bin/bash
 * 1)    mkvtoavi.sh
 * 1)    Description: convert a really big Full HD Matroska video file into a much smaller Standard HD Audio Video Interleave file.
 * 1)    Details: Conversion will take 4 x length of movie using the X264 codec at 'veryslow' preset.
 * 2)             For an average movie this will mean about 8 hours - so leave it running overnight!
 * 1)    Usage: ./mkvtoavi.sh input.file output.file

Example #1
Create an XviD .avi video of the 5th chapter of the 3rd title of a DVD ISO file, reducing the picture size to 640x360, whilst keeping the 16:9 aspect ratio...

transcode -i ~/Videos/Being_Human_S01D01.iso -T 3,5 -Z 640x360 -y xvid4,tcaud -o ~/Videos/Being_Human_S01E01-5.avi

-i = input filename. -T = title and chapter. -Z = resize video. -y = output format. -o = output filename.

Example #2
Create an XviD .avi video of a MythTV recording, using mplayer to probe for video and audio types, just use the first 2 streams for video and audio, reducing the picture size to 640x360, whilst keeping the 16:9 aspect ratio...

transcode -q 0 -i 7335_20110329090000.mpg --mplayer_probe -S 0,0-1 -Z 640x360 -y xvid4,tcaud -o /var/lib/mythtv/exports/test.avi

-q = debug level - quiet. --mplayer_probe = use mplayer. -S = stream and channel(s). -i = input filename. -T = title and chapter. -Z = resize video. -y = output format. -o = output filename.

Troubleshooting
Error...

[export_xvid4.so] warning: Usage of this module for audio encoding is deprecated. [export_xvid4.so] warning: Consider switch to export_tcaud module.

Fix...

-y xvid4,tcaud

Full example...

trancode - i /dev/dvd -y xvid4,tcaud -o /path/to/filename.avi