FFmpeg Master Tricks

Published on 16 Aug 2020

A collection of tricks to become more productive with FFmpeg.

Trim Track

If I am too lazy to open Audacity to trim songs I downloaded from YouTube:

ffmpeg -i "track.mp3" -ss 00:00:00 -t 00:00:08 -c:a libopus -b:a 96k "output.ogg"

The time is in hh:mm:ss format. With -ss and -t, specify the start time and duration. By replacing -t with -to, user can specify start time and end time.

Pipe From PV

pv is a terminal-based tool to monitor progress of data being sent through a pipe. It is a great tool to visualize an encoding progress. A minimal working example is shown below:

pv input.ext | ffmpeg -i pipe:0 -c:v hevc -c:a libopus output.ext

Making FFmpeg Less Verbose

I frequently encode videos into HEVC format. It gets noisy, especially when running from bash script to perform encoding over a bulk of files. To suppress verbosity for both ffmpeg and hevc, here is the minimal working example:

ffmpeg -i input.ext -v warning -c:v hevc -x265-params log-level=warning output.ext

The -v flag tells ffmpeg to reduce its verbosity to show all warnings and errors. FFmpeg has other loglevels too such as quiet and info.

The -x265-params is for sending user-defined parameters to the x265 encoder itself, which in this case telling the encoder to be less verbose with log-level=warning.

How Long Did It Take

To know the duration of an encoding, excute /usr/bin/time (do not confuse with time shell builtin).

/usr/bin/time --format='took %e seconds' \
    ffmpeg -i input.ext -c:v hevc output.ext

The command above will output took n seconds after the encoding is done. Definitely useful, but to make it more useful for data collection purposes, let’s write the output into a file.

/usr/bin/time --format='took %e seconds' -a -o output.time.txt

-a flag tells it to append, -o is to specify the output.