FFmpeg DVD

From Indie IT Wiki
Jump to: navigation, search

Introduction

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

The 3 Movie File Formats

  1. SD 480p XviD MPEG-4 AAC AVI
  2. HD 720p AVC X264 AC3 MP4
  3. FHD 1080p HEVC X265 DTS MKV

Cut Video Based On Start And End Time

ss = start time
t = length

This is 5 minutes...

ffmpeg -ss 00:00:00 -t 00:05:00 -i movie.mp4 -acodec copy -vcodec copy -async 1 cut.mp4

Find Total Time Of Video Files In Folder

find . -maxdepth 1 -iname '*.mp4' -exec ffprobe -v quiet -of csv=p=0 -show_entries format=duration {} \; | paste -sd+ -| bc

Screen Resolutions

'hd480' = 852x480
'hd720' = 1280x720
'hd1080' = 1920x1080
'uhd2160' = 3840x2160

https://ffmpeg.org/ffmpeg-utils.html#Video-size

ffmpeg -s hd720 ...

16:9 aspect ratio resolutions: 640×360, 720x404, 852×480, 1024×576, 1152×648, 1280×720, 1366×768, 1600×900, 1920×1080, 2560×1440 and 3840×2160.

Video Resolutions

Video Track Copy And Encode Multiple Audio Tracks

From this...

Stream #0.0(und): Video: h264, yuv420p, 720x424, 911 kb/s, 25 fps, 25 tbr, 90k tbn, 180k tbc
Stream #0.1(eng): Audio: ac3, 48000 Hz, 5.1, fltp, 448 kb/s

To this...

Stream #0.0(und): Video: h264, yuv420p, 720x424, 911 kb/s, 25 fps, 25 tbr, 90k tbn, 180k tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, fltp, 160 kb/s
Stream #0.2(eng): Audio: ac3, 48000 Hz, 5.1, fltp, 448 kb/s

Using this...

ffmpeg -i INPUT -map 0:0 -map 0:1 -map 0:1 -codec:0 copy -codec:1 libfdk_aac -b:1 160k -ar:1 48k -ac:1 2 -codec:2 copy OUTPUT

Many thanks - https://forum.handbrake.fr/viewtopic.php?f=10&t=34844&p=163056#p163060

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/

Blu-ray Copying Transcoding

Usual Routine

Check which track to rip (look for correct duration and chapters)...

makemkvcon --robot --minlength=1000 info disc:0

Make the file...

makemkvcon --minlength=1000 mkv disc:0 0 /tmp/

Transcode the file...

HandBrake bla bla bla

Tricky Disc

If you have a disc that will not complete the 'usual routine' above, then you have to take a backup of the entire disc, get information on the disc, join the correct files together in the correct order, extract specific tracks and then create the mkv file ready for HandBrake or ffmpeg transcoding...

  1. makemkv disc backup
  2. makemkv info save to text file
  3. cat join tracks
  4. ffmpeg copy specific tracks
  5. ffmpeg x265

Backup Disc

Create a directory for the disc contents...

mkdir -p ~/Videos/Movie

Backup the entire disc to that directory...

makemkvcon backup disc:0 ~/Videos/Movie

You will end up with the following folders...

|-- BDMV
|   |-- AUXDATA
|   |-- BACKUP
|   |   |-- BDJO
|   |   |-- CLIPINF
|   |   |-- JAR
|   |   `-- PLAYLIST
|   |-- BDJO
|   |-- CLIPINF
|   |-- JAR
|   |   |-- 00010
|   |   |-- 00011
|   |   |-- 00012
|   |   |-- 04518
|   |   |-- 09709
|   |   |-- 15631
|   |   `-- 18912
|   |-- META
|   |   `-- DL
|   |-- PLAYLIST
|   `-- STREAM
|-- CERTIFICATE
|   `-- BACKUP
`-- MAKEMKV
    |-- AACS
    |   `-- DUPLICATE
    `-- CMAP

Get Information

Find out which tracks are used and what files are used for those tracks...

 makemkvcon --robot --minlength=1000 info disc:0 > ~/Videos/Movie/makemkv_info.txt

Join Correct Tracks

Find the correct order for the files for a track...

grep '26,0' ~/Videos/Movie/makemkv_info.txt
TINFO:1,26,0,"1,4,9,10,11,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37"

Change to the directory which stores the many video files...

cd ~/Videos/Movie/BDMV/STREAM

Now join the files together (tab is your friend here) using the list order above, into one big M2TS file...

cat 00001.m2ts 00004.m2ts 00009.m2ts ... 00036.m2ts 00037.m2ts > allparts.m2ts

Create MKV File

There will be about 10 tracks in that big file, and we only want 2 - one video track and one audio (preferably DTS) track.

Use ffmpeg to list the tracks...

ffmpeg -i allparts.m2ts

Input #0, mpegts, from 'allparts.m2ts':
 Duration: 02:27:59.44, start: 4198.000000, bitrate: 31651 kb/s
 Program 1 
   Stream #0:0[0x1011]: Video: vc1 (Advanced) (VC-1 / 0x312D4356), yuv420p(bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc
   Stream #0:1[0x1100]: Audio: dts (DTS-HD MA) ([134][0][0][0] / 0x0086), 48000 Hz, 5.1(side), s32p (24 bit)
   Stream #0:2[0x1101]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 640 kb/s
   Stream #0:3[0x1102]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 640 kb/s
   Stream #0:4[0x1103]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 640 kb/s
   Stream #0:5[0x1200]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:6[0x1201]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:7[0x1202]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090), 1920x1080
   Stream #0:8[0x1203]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:9[0x1204]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:10[0x1205]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:11[0x1206]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:12[0x1207]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:13[0x1208]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:14[0x1209]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)

Use ffmpeg's copy track feature to create an MKV file with only 2 tracks.

This command uses the first video track with the first audio track and removes subtitle tracks...

ffmpeg -y -i allparts.m2ts -map 0:v:0 -map 0:a:0 -acodec copy -vcodec copy -sn allparts.mkv

Transcode

1080p X265 DTS MKV...

ffmpeg -y -i "allparts.mkv" -hide_banner -nostats -loglevel quiet -map 0:v:0 -map 0:a:0 -vcodec libx265 -crf 26 -preset slow -acodec dca -b:a 1509k -map_metadata -1 -metadata title="Movie" -metadata:s:a:0 language=eng -map_chapters -1 -sn -strict -2 "Movie.mkv"

720p X264 AC3 MP4...

ffmpeg -y -i "allparts.mkv" -hide_banner -nostats -loglevel quiet -map 0:v:0 -map 0:a:0 -s hd720 -aspect 16:9 -vcodec libx264 -crf 23 -preset veryslow -tune film -profile:v high -level 4.1 -acodec ac3 -ab 384k -ac 6 -map_metadata -1 -metadata title="Movie" -metadata:s:a:0 language=eng -map_chapters -1 -sn "Movie.mp4"

Copy to Plex

cp -av "Movie.mp4" "Movie.mkv" /path/to/Plex/Movies/

Enjoy

Turn the lights down, turn the surround sound up and enjoy your movie in Plex - make sure you choose "Play Version" :-)

Converting From One Format To Another

HVC X265 - https://trac.ffmpeg.org/wiki/Encode/H.265

Test file, 5 minutes long, CFR of 25, audio of DTS surround at 1509 Kbps...

ffmpeg -ss 00:00:00 -t 00:05:00 -i input.mkv -c:v libx265 -crf 25 -c:a dca -b:a 1509k -strict -2 output.mkv

Test file, 5 minutes long, CFR of 28, audio of AC3 surround at 384 Kbps...

ffmpeg -ss 00:00:00 -t 00:05:00 -i input.mkv -c:v libx265 -crf 28 -c:a ac3 -b:a 384k output.mp4

Test file, 5 minutes long, CFR of 22, audio of AAC, 6 channels at 160 Kbps...

ffmpeg -ss 00:00:00 -t 00:05:00 -i input.mkv -c:v libx265 -crf 22 -c:a libfdk_aac -b:a 160k -ac 6 output.mp4

WEBM - https://trac.ffmpeg.org/wiki/Encode/VP8

ffmpeg -i input-file.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output-file.webm

Using HandBrake...

MKV - https://trac.ffmpeg.org/wiki/Encode/H.264

HandBrakeCLI --input input_file.vob --title 1 --markers --encoder x264 --x264-preset veryslow --x264-tune animation --audio 1 --aencoder copy --subtitle 1 --output output_file.mkv

Using ffmpeg...

MKV

ffmpeg -y -i input_file.mkv -s hd720 -f matroska -vcodec libx264 -profile:v main -level 41 -preset veryslow -tune film -crf 22 -threads 0 -b 1152k -metadata title="Movie Title" -metadata:c title="" -metadata:s title="" -acodec ac3 -ab 384k -ac 6 -ar 48000 -sn output_file.mkv

AVI

...

Command line to convert a MKV file to a smaller xVid AVI file, by reducing the video bit rate and audio quality...

ffmpeg -y -i input_file.mkv -s 640x360 -aspect 16:9 -f avi -vcodec mpeg4 -vtag xvid -b 1152k -mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300 -acodec mp2 -ab 128k -ac 2 -ar 44100 -threads 1 output_file.avi

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 A DVD To Produce A VOB File

mplayer dvd://1 -dumpstream -dumpfile mydvd.vob

Using Mplayer On An ISO To Produce A VOB File

Extract whole film...

mplayer dvd://1 -dvd-device mydvd.iso -dumpstream -dumpfile mydvd.vob

Extract just one chapter...

mplayer dvd://1 -dvd-device mydvd.iso -chapter 1-1 -dumpstream -dumpfile mydvd-1.vob

Extract The Subtitles From a VOB File

mencoder mydvd.vob -nosound -ovc copy -o /dev/null -vobsubout mydvd -sid 0 -vobsuboutindex 0 -vobsuboutid en

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...

(The -vn helps because it tells ffmpeg to ignore the video stream)

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

Convert M4A To MP3

for f in *.m4a; do ffmpeg -i "$f" -acodec libmp3lame -ab 320k "${f%.m4a}.mp3"; done

Convert FLAC To MP3

for f in *.flac; do ffmpeg -i "$f" -acodec libmp3lame -ab 320k "${f%.flac}.mp3"; done

Installing the LATEST Release of ffmpeg in Ubuntu Linux

NEW NOTES

  1. nasm
  2. x264
  3. x265 (Release Notes)
  4. fdk-aac
  5. ffmpeg
sudo apt-get remove ffmpeg x264 libx264-dev yasm nasm
cd ~/Downloads
wget https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/nasm-2.13.03.tar.gz
tar -xzvf nasm-2.13.03.tar.gz
cd nasm-2.13.03/
./configure
make
sudo make install
sudo ldconfig
which nasm
nasm --version
cd ~/Downloads
git clone git://git.videolan.org/x264
cd x264/
git pull
./configure --enable-shared
make
sudo make install
sudo ldconfig
which x264
x264 --version
cd ~/Downloads
sudo apt-get install cmake cmake-curses-gui
git clone https://github.com/videolan/x265.git
cd x265/
git pull
cd build/linux/
./make-Makefiles.bash  (press c, then e, then g)
make
sudo make install
sudo ldconfig
which x265
x265 --version
cd ~/Downloads
sudo apt-get install autoconf
git clone https://github.com/mstorsjo/fdk-aac.git
cd fdk-aac/
git pull
./autogen.sh
./configure
make
sudo make install
sudo ldconfig
cd ~/Downloads
git clone git://git.videolan.org/ffmpeg
cd ffmpeg/
git pull
./configure --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265
make
sudo make install
sudo ldconfig
which ffmpeg
ffmpeg --version

https://bitbucket.org/multicoreware/x265/wiki/Home

OLD NOTES

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...

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

HEVC H.265 X265

https://trac.ffmpeg.org/wiki/Encode/H.265

  • Choose a CRF. The default is 28, and it should visually correspond to libx264 video at CRF 23, but result in about half the file size. Other than that, CRF works just like in x264.
  • Choose a preset. The default is medium. The preset determines how fast the encoding process will be – at the expense of compression efficiency. Put differently, if you choose ultrafast, the encoding process is going to run fast, but the file size will be larger when compared to medium. The visual quality will be the same. Valid presets are ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow and placebo.
  • Choose a tune. By default, this is disabled, and it is generally not required to set a tune option. x265 supports the following -tune options: psnr, ssim, grain, zerolatency, fastdecode. They are rexplained in the H.264 guide.

Example #1 X265: First chapter (3 minutes) of the Wall-E Blu-ray, 1080p MKV to 1080p MP4 with CRF 25, FDK AAC Surround Sound, edited Metadata and NO chapter markers...

ffmpeg -ss 00:00:00 -t 00:03:36 -i "input.mkv" -c:v libx265 -crf 25 -c:a libfdk_aac -b:a 384k -ac 6 -map_metadata -1 -metadata title="Wall-E (2008)" -map_chapters -1 "output.mp4"

FILE SIZE = 40Mb

Example #2 X264: For size comparison...

ffmpeg -ss 00:00:00 -t 00:03:36 -i "input.mkv" -c:v libx264 -crf 22 -c:a libfdk_aac -b:a 384k -ac 6 -map_metadata -1 -metadata title="Wall-E (2008)" -map_chapters -1 "output.mp4"

FILE SIZE = 80Mb

Remove Chapter Markers

-map_chapters -1

Thanks - https://video.stackexchange.com/questions/20270/ffmpeg-delete-chapters#20324

Set Audio Metadata Language

-metadata:s:a:0 language=eng

Thanks - https://ffmpeg.org/ffmpeg.html

Set Movie Title

-metadata title="Movie Name (YEAR)"

Allow DTS

-acodec dca -strict -2 "/path/to/output.mkv"

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 -acodec libmp3lame -ab 128k Title_S01E09.avi

ffmpeg: How To Strip Metadata

-map_metadata -1
ffmpeg -i input.mkv -map_metadata -1 -vcodec copy -acodec copy output.mp4

Android and Playstation 3 Compatible MP4

The Sony Playstation 3 is fussy about what video files it can play.

  • Container: MP4
  • Video: H264 AVC Profile Main Level 3.1
  • Audio: AAC
nice -19 ffmpeg -y -i ~/Videos/Film/Film.mkv -map_metadata -1 -s 960x540 -f mp4 -vcodec libx264 -profile:v main -level 31 -preset veryslow -tune film -crf 22 -threads 0 -b 1152k -metadata title="Film" -acodec libvo_aacenc -ab 160k -ac 2 -ar 44100 ~/Videos/Film/Film.mp4

Android Compatible AVI

Don't use this, use the MP4 above.

This will create an .avi movie file suitable for playing with MX Player on HD Android devices.

Example #1 - film, medium speed

ffmpeg -y -i ~/Videos/Film/Film.mkv -s hd720 -f avi -vcodec libx264 -preset medium -tune film -crf 22 -threads 0 -b 1152k -acodec libmp3lame -ab 128k -ac 2 -ar 44100 ~/Videos/Film/Film.avi

Example #2 - animation, slower, clearing stream metadata, forcing profile main and level 3.1

ffmpeg -y -i ~/Videos/Film/Film.mkv -s hd720 -f avi -vcodec libx264 -profile:v main -level 31 -preset slower -tune animation -crf 22 -threads 0 -b 1152k -metadata:s title="" -acodec libmp3lame -ab 128k -ac 2 -ar 44100 ~/Videos/Film/Film.avi

Example #3 - film, very slow, profile main, level 3.1, setting and clearing metadata, plus nice value

nice -19 ffmpeg -y -i ~/Videos/Film/Film.mkv -s hd720 -f avi -vcodec libx264 -profile:v main -level 31 -preset veryslow -tune film -crf 22 -threads 0 -b 1152k -metadata title="Film" -metadata:c title="" -metadata:s title="" -acodec libmp3lame -ab 128k -ac 2 -ar 44100 ~/Videos/Film/Film.avi

ALSO - you can use cpulimit to stop frying your processor when transcoding...

sudo cpulimit -b -e ffmpeg -l 80

Why do this? You do this because the slower it takes, the better the result. You also finish with a smaller sized file!

If you do this correctly, a 32Gb FullHD MKV movie can come right down to 1Gb.

** This will take about 12 hours so leave it running overnight :-) **

You can read more about the x264 settings here:-

http://mewiki.project357.com/wiki/X264_Settings

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 - Thursday, May 5 2016 **

http://dev.beandog.org/x264_preset_reference.html

** 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

MythTV To AVI Script

Transcode a MythTV recording into an xvid .avi with the title and subtitle as filename.

Put this in /usr/local/bin/ and create a new MythTV User Job called 'Export to AVI' with the command input line:

myththto.sh %FILE%

Latest version: 2012-08-11: http://wiki.indie-it.com/images/5/5f/Mythtvto.sh

MKV To AVI Script

#!/bin/bash
#
#    mkvtoavi.sh
#
#    Description: convert a really big Full HD Matroska video file into a much smaller Standard HD Audio Video Interleave file.
#
#    Details: Conversion will take 4 x length of movie using the X264 codec at 'veryslow' preset.
#             For an average movie this will mean about 8 hours - so leave it running overnight!
#
#    Usage: ./mkvtoavi.sh input.file output.file
#
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

Mencoder

UPDATE: 2013-05-16

  1. http://www.axllent.org/code/divxcalc/
  2. http://quadpoint.org/projects/simplerip/

Check the correct tile track of a DVD...

lsdvd

Two pass encode with target size of 700Mb...

mencoder dvd://1 -alang en -vobsub 999 -ovc xvid -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=1 -o /dev/null
mencoder dvd://1 -alang en -vobsub 999 -ovc xvid -oac mp3lame -lameopts cbr:br=128 -xvidencopts pass=2:bitrate=-700000 -o output.avi

Two pass encode with black bar cropping of a 2.35:1 Widescreen UK PAL 720x576 picture and fixed bitrate for smaller final size...

mplayer dvd://1 -chapter 3 -vf cropdetect
mencoder dvd://1 -vf crop=720:416:0:80,scale=640:256 -ovc xvid -xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=1 -oac copy -o /dev/null
mencoder dvd://1 -vf crop=720:416:0:80,scale=640:256 -ovc xvid -xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=2 -alang en -oac mp3lame -lameopts br=96:cbr:vol=6 -o output.avi

Same, but for a 16:9 Widescreen UK PAL 720x576 picture...

mencoder dvd://1 -alang en -vf crop=720:410:0:80,scale=720:400 -vobsub 999 -ovc xvid -oac mp3lame -lameopts cbr:br=96:vol=6 -xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=1 -o /dev/null
mencoder dvd://1 -alang en -vf crop=720:410:0:80,scale=720:400 -vobsub 999 -ovc xvid -oac mp3lame -lameopts cbr:br=96:vol=6 -xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=2 -o output.avi 

Same, but for a 4:3 Standard Definition UK PAL picture...

mencoder dvd://1 -alang en -vf crop=688:560:18:8,scale=640:480 -vobsub 999 -ovc xvid -oac mp3lame -lameopts cbr:br=96:vol=6 -xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=1 -o /dev/null
mencoder dvd://1 -alang en -vf crop=688:560:18:8,scale=640:480 -vobsub 999 -ovc xvid -oac mp3lame -lameopts cbr:br=96:vol=6 -xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=2 -o output.avi 

http://ubuntuguide.org/wiki/Video_Conversion

http://www.axllent.org/docs/video/mencoder-dvd-to-mpeg4

Transcode

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

ffmpeg Audio Channel Layouts

-channel_layout
7.1: Front: L C R, Surround: L R, Back: L R, LFE
6.1: Front: L C R, Surround: L R, Back: C, LFE
5.1: Front: L C R, Surround: L R, LFE 
layout_map[] = {
   {  1, CHANNEL_LAYOUT_MONO                                 , "mono"        },
   {  2, CHANNEL_LAYOUT_STEREO                               , "stereo"      },
   {  4, CHANNEL_LAYOUT_QUAD                                 , "quad"        },
   {  6, CHANNEL_LAYOUT_5POINT1                              , "5.1"         },
   {  8, CHANNEL_LAYOUT_5POINT1|CHANNEL_LAYOUT_STEREO_DOWNMIX, "5.1+downmix" },
   {  8, CHANNEL_LAYOUT_7POINT1                              , "7.1"         },
   {  8, CHANNEL_LAYOUT_7POINT1_WIDE                         , "7.1(wide)"   },
   { 10, CHANNEL_LAYOUT_7POINT1|CHANNEL_LAYOUT_STEREO_DOWNMIX, "7.1+downmix" },
   {  0 }

Join MKV Files Together

sudo apt-get install mkvtoolnix
mkvmerge -o output.mkv input1.mkv +input2.mkv

Join MP4 Files Together

Install GPAC first, easily from ubuntu repository:

sudo apt-get install gpac

Then using one of GPAC's tool, named MP4Box, we can join or merge multiple mp4 files by concatenating into one file. With concatenating we save a huge amount of processing time which is usually spent for rendering/re-encoding.

MP4Box -cat file1.mp4 -cat file2.mp4 -cat file3.mp4 OutputFile.mp4

HOWTO: FIX: ERROR: ffmpeg: libmp3lame not found

sudo apt-get install libavcodec-extra-53

HOWTO: Install Latest ffmpeg In Ubuntu Linux

Ubuntu seems to be straying behind again, and the latest Ubuntu build is version 9.

However, the libav developers are up to version 11 now.

This is the latest daily build for Ubuntu. Things may break, but they might not. So, you'll be fine.

It will give you version 12. Which means that youtube-dl won't complain anymore :)

sudo add-apt-repository ppa:motumedia/libav-daily
sudo aptitude update
sudo aptitude -y safe-upgrade
which ffmpeg
ffmpeg -version

Now you need to move the old FFMPEG out of the way, and make it a symlink to the new ffmpeg.

sudo mv /usr/bin/ffmpeg /usr/bin/ffmpeg.old
sudo ln -s /usr/bin/ffmpeg /usr/bin/ffmpeg

Thanks - https://launchpad.net/~motumedia/+archive/ubuntu/libav-daily

HOWTO: Screenshots

ffmpeg -ss 1 -i <input_filename>.ts -f image2 -vf "select='eq(pict_type,I)'" -vframes 1 -vsync 2 <output_filename>.png