ffmpeg

18 Sep 2022

FFmpeg is a free and open-source software project consisting of a suite of libraries and programs for handling video, audio, and other multimedia files and streams. At its core is the command-line ffmpeg tool itself, designed for processing of video and audio files. It is widely used for format transcoding, basic editing (trimming and concatenation), video scaling, video post-production effects and standards compliance (SMPTE, ITU).

FFmpeg also includes other tools: ffplay, a simple media player and ffprobe, a command-line tool to display media information. Among included libraries are libavcodec, an audio/video codec library used by many commercial and free software products, libavformat (Lavf), an audio/video container mux and demux library, and libavfilter, a library for enhancing and editing filters through a Gstreamer-like filtergraph.

FFmpeg is part of the workflow of many other software projects, and its libraries are a core part of software media players such as VLC, and has been included in core processing for YouTube and Bilibili. Encoders and decoders for many audio and video file formats are included, making it highly useful for the transcoding of common and uncommon media files.

You can use Homebrew to install ffprobe (installed along with ffmpeg):

brew install ffmpeg

Else:

Download at:

Commands

Optimise video

06 Jun 2024

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 -preset slow -acodec aac -b:a 128k output.mp4
   -vcodec libx265: Use the H.265 codec.   -crf 28: Constant Rate Factor, lower values mean better quality. 28 is a good starting point.   -preset slow: Encoding speed vs compression ratio. Slower presets result in better compression.   -acodec aac -b:a 128k: Use AAC for audio and set the audio bitrate to 128 kbps.

The crf scale ranges from 0 to 51:

•   crf 0: Lossless encoding (highest quality, very large file size).
•   crf 23: Default value, providing a good balance between quality and file size.
•   crf 51: Lowest quality (smallest file size).

In practice, the following ranges are commonly used:

   18-22: High quality (visually lossless). Suitable for archiving or high-quality viewing.   23-28: Standard quality. Good for general-purpose use, offering a balance between quality and file size.   28-34: Low quality. Useful for scenarios where file size is a more critical factor than quality, such as streaming over limited bandwidth.

To use VBR (Variable Bit Rate) instead of CRF:

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 -preset slow -b:v 1000k -maxrate 1500k -bufsize 2000k -acodec aac -q:a 2 output.mp4

With 73Mb video source file:
- 120Mb at CRF 0
- 4Mb at CRF 28 (but lower quality)
- 6Mb at VBR 1000k (better quality than CRF 28)

Optimise for Powerpoint

ffmpeg -i input.mp4 -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level:v 3.1 -preset slow -crf 30 -maxrate 1000k -bufsize 2000k -acodec aac -b:a 128k -movflags +faststart output.mp4

913Kb file from 11.4Mb!

Remove Audio

ffmpeg -i input.mp4 -an -vcodec copy output.mp4
•   -an tells FFMPEG to remove the audio stream.
•   -vcodec copy tells FFMPEG to copy the video stream without re-encoding it.

Resources

links

social