How to reduce the size of a video dramatically with ffmpeg ?

About

This article shows you how to reduce the size of video with ffmpeg.

Size parameters

The following parameters have an important on the size:

  • the codec: the codec is the algorithm that encodes the picture into the video format. The better, the algorithm, the lower is the size
  • the bitrate
  • the frame per second: lower is your number of frame per second, lower is your size (a human eye perceive motion from 15 fps)
  • the size of your video (the lower are your width and dimension, the lower is the size of your video)
  • the number of colors (a grayscale video will have a lowest size than a full color)
  • the number of pixels (or resolution)

Example

Filter

Below is a ffmpeg filter that:

crop=576:478:0:148, fps=20, scale=400:trunc(ow/a/2)*2

Codec and bitrate

The best codec nowadays is H.265 1) that is much better in term of compression without losing quality than H.264 2).

You can push the compression and minimize the bitrate further by increasing the CRF (Constant Rate Factor) value (decreasing the bitrates). A reasonable value would be between 24 and 30.

Command

After having installed ffmpeg, you can execute the below command to execute this filter pipeline::

ffmpeg.exe \
    -i input.mp4 \
    -v \
    -f "crop=576:478:0:148, fps=20, scale=400:trunc(ow/a/2)*2"  \
    -vcodec libx265 -crf 34  \
    output.mp4

where libx265 is the ffmpeg code for H.265


Powered by ComboStrap