Skip to content

ffmpeg#

Installation#

Windows builds#

https://oss.netfarm.it/mplayer/

Get and extract:

  • FFmpeg-x86_64 git N-....7z
  • frei0r-plugins-x86_64-....7z
  • libfdk-aac-x86_64-....7z

General examples#

Downscales and encodes a subbed animation video using AAC HEv2 and h265:

-c:a libfdk_aac -afterburner:a 1 -vbr:a 2 -profile:a aac_he_v2 -c:v libx265 -threads 1 -preset:v slower -crf:v 28 -profile:v main -tune animation -filter:v "scale=720:-2:flags=lanczos" -map 0 -c:s copy

Webcast transcode HE-AACv2, do not touch video:

ffmpeg -i input.mp4 -c:a libfdk_aac -afterburner:a 1 -vbr:a 1 -profile:a aac_he_v2 output.mp4

Webcast transcode to HE-AACv2:

ffmpeg -i input.mp4 -c:a libfdk_aac -vbr:a 1 -profile:a aac_he_v2 -c:v hevc_nvenc -crf:v 31 -profile:v main output.mp4

ffmpeg -i input.mp4 -c:a libfdk_aac -vbr:a 1 -profile:a aac_he -c:v libx265 -crf:v 26 -profile:v main -preset:v slow -filter:v "scale=720:-2:flags=lanczos" -x265-params "level-idc=31:repeat-headers=1:aud=1:hrd=1" -map 0 output.mp4

ffmpeg -i input.mp4 -c:a libfdk_aac -vbr:a 1 -profile:a aac_he -c:v libx265 -crf:v 31 -profile:v main -preset:v slow -filter:v "scale=1280:-2:flags=lanczos" -x265-params "level-idc=41:repeat-headers=1:aud=1:hrd=1" -vsync vfr -map 0 output.mp4

Audio#

Page on Audio Channel Manipulation

FDK-AAC#

HydrogenAdio Wiki Page on Fraunhofer FDK AAC

Downmix to stereo and transcode AAC-LC:

-c:a libfdk_aac -vbr:a 4 -profile:a aac_low -ac 2 -filter:a "volume=3.5" -cutoff 20000

Transcode to AAC-HEv2:

-c:a libfdk_aac -vbr:a 2 -profile:a aac_he_v2

List of supported profiles:

  • Low Complexity AAC (LC): aac_low
  • High Efficiency AAC (HE-AAC): aac_he
  • High Efficiency AAC version 2 (HE-AACv2): aac_he_v2
  • Low Delay AAC (LD): aac_ld
  • Enhanced Low Delay AAC (ELD): aac_eld

Tips and tricks#

Cropping and scaling#

-filter:v "crop=width:height:x:y,scale=width:height:flags=lanczos"

x and y position compared to the top left corner (0, 0).

Sane values:

  • For 4:3 aspect ratio SD: -filter:v "scale=576:-2:flags=lanczos"
  • For 16:9 aspect ratio SD: -filter:v "scale=720:-2:flags=lanczos"
  • For 16:9 aspect ratio HD 720p: -filter:v "scale=1280:-2:flags=lanczos"

Turn video#

-filter:v "transpose=x"

Replace x with one of the following values:

  • 0 = 90 degrees counter clockwise and vertical flip (default)
  • 1 = 90 degrees clockwise
  • 2 = 90 degrees counter clockwise
  • 3 = 90 degrees clockwise and vertical flip

Presentation Slideshows#

ffmpeg -i input.mp4 -c:a libfdk_aac -vbr:a 1 -profile:a aac_he_v2 -c:v libx265 -crf:v 31 -profile:v main -preset:v slow -filter:v "scale=1280:-2:flags=lanczos" -x265-params "level-idc=41:repeat-headers=1:aud=1:hrd=1" -vsync vfr -map 0 output.mp4

metadata copy#

Copy metadata using the following parameters:

  • Global metadata: -map_metadata 0

If the source is .mov then this flag needs to be added:

-movflags use_metadata_tags

Mix VobSub#

ffmpeg -i input.mkv -i vobsub.idx -i vobsub.sub -c copy -map 0 -map 1 output.mkv

Examples#

Video file from smartphone#

Copy audio, scale and recode video using lanczos:

-c:a copy -c:v libx265 -preset:v slower -crf:v 26 -profile:v main -filter:v scale=-2:1080:flags=lanczos -map_metadata 0

DRM#

More#