FFMPEG An Intermediate Guide/h.264

From Wikibooks, open books for an open world
Jump to: navigation, search

FFMPEG: Encoding, Decoding, Video Full Name: Web sites: Description:

h.264 is arguably the cutting edge of video compression codecs. Unfortunately it is copyright protected. It is currently being used in formats such as blu-ray, mp4, flash (f4v), html5 and most modern portable devices.

It is heavier on encoding and decoding than preceding formats but results in much higher picture quality from smaller files.

Its not natively supported in ffmpeg, so you will need to build ffmpeg with support for the external library, x264.

Before using this in a production system please obtain the necessary licenses, you are warned!

Tests have shown this library functions comparatively if not more efficiently than apples compressor or episode, although both these programs have powerful features that ffmpeg does not have.

Basic ffmpeg call[edit]

To trans-code a file using ffmpeg:

ffmpeg -i "input_file" -vcodec libx264 "output.mov"

output extensions include: .mov .flv .f4v .avi

Presets[edit]

There is a great set of preset files that come with x264 codec in ffmpeg, possibly making it the most powerful and easy to use codec in ffmpeg. Codecs include are: (only x264 currently has default presets)

  • libx264-slowfirstpass.ffpreset
  • libx264-fastfirstpass.ffpreset


  • libx264-ipod320.ffpreset
  • libx264-ipod640.ffpreset


  • libx264-default.ffpreset
  • libx264-normal.ffpreset
  • libx264-main.ffpreset
  • libx264-baseline.ffpreset
  • libx264-hq.ffpreset
  • libx264-max.ffpreset


  • libx264-lossless_ultrafast.ffpreset
  • libx264-lossless_fast.ffpreset
  • libx264-lossless_medium.ffpreset
  • libx264-lossless_slow.ffpreset
  • libx264-lossless_slower.ffpreset
  • libx264-lossless_max.ffpreset


Note: recent releases of ffmpeg have a different preset system for libx264.
e.g. instead of "-vpre medium" you are now supposed to use "-preset medium".
This way ffmpeg uses libx264's own preset system. Setting a preset in the new
way is also important because if you don't set any preset ffmpeg will ignore
the "-crf float" setting.[1]


This is a quick grouping to quide you in quality of output. Note! Video/audio output can only be as good as the video/audio input. If your source is lossy so is your output. and are best used in a two pass environment.

ffmpeg -i "input_file" -pass 1 -vcodec libx264 -vpre fastfirstpass -threads 0 -passlogfile "2passlog" "temp.mov"

ffmpeg -i "input_file" -pass 2 -vcodec libx264 -vpre hq -threads 0 -passlogfile "2passlog" "output_file.mov"

(run the first line, then the second line)

Speed of encoding to quality are relative; the longer it takes to encode the better the output quality to size ratio.

In truth to really guide you we should write a paragraph on each of the above encoding methods, but for now this must suffice.

Audio[edit]

Audio is heavily affected by what your intended output is: web, ipod, offline/online editing.

For heavily compressed formats, you should use acc, or mp3. Otherwise, read more in the audio section.

Useful links[edit]

x264-ffmpeg-mapping

[[1]]

Notes[edit]

-h[edit]

  mmco                    .DV.. memory management control operations (H.264)
  wpred                   E.V.. weighted biprediction for b-frames (H.264)
  dct8x8                  E.V.. high profile 8x8 transform (H.264)
  fastpskip               E.V.. fast pskip (H.264)
  aud                     E.V.. access unit delimiters (H.264)

-crf <float> E.V.. enables constant quality mode, and selects the quality (x264) -keyint_min <int> E.V.. minimum interval between IDR-frames (x264)

formats[edit]

  mmco                    .DV.. memory management control operations (H.264)
  wpred                   E.V.. weighted biprediction for b-frames (H.264)
  dct8x8                  E.V.. high profile 8x8 transform (H.264)
  fastpskip               E.V.. fast pskip (H.264)
  aud                     E.V.. access unit delimiters (H.264)

-crf <float> E.V.. enables constant quality mode, and selects the quality (x264) -keyint_min <int> E.V.. minimum interval between IDR-frames (x264)