Ubuntu / Linux news and application reviews.

This is a guide on how to encode audio / video in which you will find some tips & tricks for using FFmpeg and other tools.

Video Size and Aspect Ratio


iPhone:


Name Size Aspect
Wide 16:9 480x270 4:3
Old TV 4:3 427x320 16:9
Wide 16:9 /16 480x272 480:272
Old TV 4:3 /16 432x320 432:320

DV NTSC video


Name Size Aspect
Wide 16:9 720x480 16:9
Old TV 4:3 720x480 4:3

Upload to Youtube and Vimeo


Name Size Aspect
SD 4:3 640:480 4:3
HD 16:9 1280x720 16:9

HD, Blu-Ray, AVCHD


Name Size Aspect
720p 1280x720 16:9
1080p/i Anamorphic 1440x1080 16:9
1080p/i 1920x1080 16:9

Frames Per Second


Name Standard Fps FFmpeg
Movies NTSC 23.976 24000/1001
Movies QuickTime N/A 29.976 10000000/417083
TV vídeo NTSC 29.97 30000/1001
Movies PAL 25 25
TV vídeo PAL 30 30

Video encoding with FFmpeg



Config for X264


default fastfirstpass lossless_ultrafast lossless_slower
baseline slowfirstpass lossless_fast lossless_max
normal hq lossless_medium ipod320
main max lossless_slow ipod640

Location of presets in Windows:
C:\usr\share\ffmpeg

Location of presets on Linux:
\usr\share\ffmpeg

High Quality 2 Pass


ffmpeg -y -i INPUT -r 30000/1001 -b 2M -bt 4M -vcodec libx264 -pass 1 -vpre fastfirstpass -an output.mp4ffmpeg -y -i INPUT -r 30000/1001 -b 2M -bt 4M -vcodec libx264 -pass 2 -vpre hq -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

iPod iPhone-width 320


ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -vpre ipod320 -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

iPod iPhone-width 640


ffmpeg -i INPUT -s 640x480 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -vpre ipod640 -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

High quality, 2 pass without preconfiguration


ffmpeg -y -i input -r 24000/1001 -b 6144k -bt 8192k -vcodec libx264 -pass 1 -flags +loop -me_method dia -g 250 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 16 -b_strategy 1 -i_qfactor 0.71 -cmp +chroma -subq 1 -me_range 16 -coder 1 -sc_threshold 40 -flags2 -bpyramid-wpred-mixed_refs-dct8x8+fastpskip -keyint_min 25 -refs 1 -trellis 0 -directpred 1 -partitions -parti8x8-parti4x4-partp8x8-partp4x4-partb8x8-an output.mp4
ffmpeg -y -i input -r 24000/1001 -b 6144k -bt 8192k -vcodec libx264 -pass 2 -flags +loop -me_method umh -g 250 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 16 -b_strategy 1 -i_qfactor 0.71 -cmp +chroma -subq 8 -me_range 16 -coder 1 -sc_threshold 40 -flags2 +bpyramid+wpred+mixed_refs+dct8x8+fastpskip -keyint_min 25 -refs 4 -trellis 1 -directpred 3 -partitions +parti8x8+parti4x4+partp8x8+partb8x8-acodec libfaac -ac 2 -ar 44100 -ab 128k output.mp4

iPod, iPhone 320 off, without preconfiguration


ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -coder 0 -bf 0 -flags2 -wpred-dct8x8 -level 13 -maxrate 768k -bufsize 3M-acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

iPod, iPhone 640 off, without preconfiguration


ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 coder 0 -bf 0 -refs 1 -flags2 -wpred-dct8x8 -level 30 -maxrate 10M -bufsize 10M-acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

iPod, iPhone, custom 2 pass


ffmpeg -y -i input -r 30000/1001 -s 480x272 -aspect 480:272 -vcodec libx264 -b 512k -bt 1024k -maxrate 4M -flags +loop -cmp +chroma -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq "blurCplx^(1-qComp)" -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -coder 0 -refs 1 -bufsize 4M -level 21 -partitions parti4x4+partp8x8+partb8x8 -subq 5 -f mp4 -pass 1 -an -title "Title" output.mp4
ffmpeg -y -i input -r 30000/1001 -s 480x272 -aspect 480:272 -vcodec libx264 -b 512k -bt 1024k -maxrate 4M -flags +loop -cmp +chroma -me_range 16 -g 300 keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq "blurCplx^(1-qComp)" -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -coder 0 -refs 1 -bufsize 4M -level 21 -partitions parti4x4+partp8x8+partb8x8 -subq 5 -f mp4 -pass 2 -acodec libfaac -ac 2 -ar 44100 -ab 128k -title "Title" output.mp4

DV Video


To DV


ffmpeg -i input -target ntsc-dv -aspect 4:3 -y output.dv

Audio



AAC Stereo High Quality


-acodec libfaac -ac 2 -ar 48000 -ab 192k

AAC Stereo Standard Quality


-acodec libfaac -ac 2 -ar 44100 -ab 128k

High Quality AAC 5.1


-acodec libfaac -ac 6 -ar 48000 -ab 448k

Low Quality AAC 5.1


-acodec libfaac -ac 6 -ar 44100 -ab 224k

AAC AC3 (Recommended: use AviSynth for mapping channel)


ffmpeg -i intput.aac -vn -acodec ac3 -ac 6 -ar 48000 -ab 448k

AC3 to M4V (Mux to be open in another application)


ffmpeg -i input.ac3 -vn -acodec copy output.m4v

AC3 to AAC (does not work as expected)


ffmpeg -i input.ac3 -vn -r 30000/1001 -acodec libfaac -ac 6 -ar 48000 -ab 448k output.aac

Eac3To



AC3 5.1 channel mapping correction


eac3to true_hd.ac3 fixed_true_hd.ac3 -blu-ray -448

AAC to AC3


  1. Open AAC in Audacity or SoundBooth
  2. Export To Wav
  3. Remux the Wav to Wav using FFmpeg:
    ffmpeg -i audio.wav –vn -acodec copy audio-out.wav
  4. Convert to AC3 using EAC3to
    eac3to.exe audio.wav Main.ac3 -448

Other FFmpeg options


-threads thread count
-y overwrite output files
-ss time_off set the start time offset
-t duration record or transcode "duration" seconds of audio/vídeo
-ildct Interlaced


Windows builds:


http://ffmpeg.arrozcru.com/autobuilds
http://sourceforge.net/project/showfiles.php?group_id=205275&package_id=248632


X264 encoding guide in English by Robert Swain:


http://rob.opendot.cl/index.php/useful-stuff/ffmpeg-x264-encoding-guide

[Credits: Rodrigo Polo]