FFmpeg Basics

Basic Syntax

ffmpeg [-y] -i INPUT_FILE [PARAMETER] [-f FORMAT] OUTPUT_FILE

FFmpeg, what can you do?

  • List containers: -formats
    File formats:
      D. = Demuxing supported
      .E = Muxing supported
    			
  • List codecs: -codecs / -encoder / -decoder
    Codecs:
      D..... = Decoding supported
      .E.... = Encoding supported
      ..V... = Video codec
      ..A... = Audio codec
      ..S... = Subtitle codec
      ...I.. = Intra frame-only codec
      ....L. = Lossy compression
      .....S = Lossless compression
    			

Rewrap

ffmpeg -i INPUT_FILE -c copy OUTPUT_FILE

Check result file

in Mediainfo / VLC

Codec

  • Videocodec: -c:v CODEC
  • Audiocodec: -c:a CODEC
  • Copy both, A + V as-is: -c copy

Transcode

ffmpeg -i INPUT_FILE -c:v ffv1 -c:a pcm_s24le OUTPUT_FILE

ffmpeg -i INPUT_FILE -c:v ffv1 -c:a pcm_s16le OUTPUT_FILE

pix_fmt?

  • yuv422p = YUV 4:2:2 planar
  • yuv420p

  • yuv422p10le
  • yuv420p10le

  • yuva422p

  • Keep-or-die: -pix_fmt +

 

Show list: -pix_fmts

Change subsampling

ffmpeg -i INPUT_FILE -c:v ffv1 -pix_fmt yuv422p OUTPUT_FILE

(CAUTION: re-encoding required)

Audio encoding

  • Audiocodec: -c:a CODEC
  • Samplerate: -ar SAMPLERATE
  • Channels: -ac CHANNELS
  • Bitrate: -b:a BITRATE{k,M}

Video encoding

  • Bitrate: -b:v BITRATE{k,M}
  • Bitrate (min): -minrate BITRATE
  • Bitrate (max): -maxrate BITRATE
  • GOP size: -g FRAMES

Transcoding II

FFV1

FFV1, which stands for "FF video codec 1", is a lossless intra-frame video codec.

 

  • Codec: -c:v ffv1
  • Version: -level {1,3}
  • Coder: -coder {0=golomb,1=range}
  • Context: -context {0=small,1=large}
  • Slices: -slices {4,6,9,12,16,24,..}
  • CRC: -slicecrc {0,1}

 

Source: Wikipedia: FFV1, ffv1.info

FFV1

ffmpeg -i INPUT_FILE -an -c:v ffv1 -level 3 -slices 24 -slicecrc 1

H.264

"x264 H.264/MPEG-4 AVC encoder wrapper. [...]
libx264 supports an impressive number of features, [...]"

 

  • Codec: -c:v libx264
  • Bitrate: -b:v BITRATE{k,M}
  • CRF: -crf 0 (lossless) - 51 (worst)
  • Presets: -preset:v {ultrafast,superfast,veryfast,faster,fast,medium(*),slow,slower,veryslow}
  • Finetuning: -tune {film,animation,grain,...}

 

Sources/Links FFmpeg Wiki, FFmpeg docs

H.264

ffmpeg -i INPUT_FILE -an -c:v libx264 -preset:v superfast -crf 22

Links