ffmpeg
Convert, record, and stream multimedia
TLDR
Extract the sound from a video and save it as MP3
Transcode a FLAC file to Red Book CD format (44100kHz, 16bit)
Save a video as GIF, scaling the height to 1000px and setting framerate to 15
Combine numbered images (frame_1.jpg, frame_2.jpg, etc) into a video or GIF
Trim a video from a given start time mm:ss to an end time mm2:ss2 (omit the -to flag to trim till the end)
Convert AVI video to MP4. AAC Audio @ 128kbit, h264 Video @ CRF 23
Remux MKV video to MP4 without re-encoding audio or video streams
Convert MP4 video to VP9 codec. For the best quality, use a CRF value (recommended range 15-35) and -b:v MUST be 0
SYNOPSIS
ffmpeg [global_options] {[input_options] -i input_url} ... {[output_options] output_url} ...
This syntax indicates that ffmpeg can take multiple input files and produce multiple output files. Options can be global, specific to an input, or specific to an output.
PARAMETERS
-i
Specifies the input file or stream URL. This option can be used multiple times for multiple inputs.
-f
Forces the input or output file format.
-c[:stream_specifier]
Selects an encoder/decoder for a specific stream (e.g., -c:v libx264 for video, -c:a aac for audio).
-b[:stream_specifier]
Sets the bitrate for a stream (e.g., -b:v 2M for 2 Megabits/second video bitrate).
-s
Sets the frame size (resolution) for video output (e.g., -s 1280x720).
-r
Sets the frame rate for video output (e.g., -r 30).
-ss
Seeks to a specific position in the input file (e.g., -ss 00:01:30 for 1 minute 30 seconds). Can also be used before -i for faster seeking.
-t
Specifies the duration to transcode (e.g., -t 60 for 60 seconds).
-vf
Applies video filters (e.g., -vf "scale=640:-1,crop=640:360").
-af
Applies audio filters (e.g., -af "atempo=1.25").
-map
Selects specific streams from input files to be included in the output.
-y
Overwrites output files without asking.
-n
Does not overwrite output files; exits if output file exists.
-preset
Sets an encoding preset for certain codecs (e.g., -preset slow for H.264, affecting encoding speed and compression efficiency).
-crf
Specifies the Constant Rate Factor for quality-based encoding (e.g., -crf 23 for H.264/H.265, lower is better quality).
DESCRIPTION
ffmpeg is a powerful, open-source command-line tool and multimedia framework that can decode, encode, transcode, mux, demux, stream, filter, and play virtually any multimedia file or stream. It supports a vast array of formats and codecs, making it an indispensable tool for video and audio manipulation. Comprising a suite of libraries (like libavcodec for codecs, libavformat for formats, and libswscale for scaling) and command-line programs (ffmpeg, ffplay, ffprobe), it serves as the backend for many popular multimedia applications and services. From converting video formats and extracting audio to live streaming and sophisticated video editing tasks, ffmpeg provides unparalleled flexibility and control over digital media.
CAVEATS
While incredibly powerful, ffmpeg's vast array of options and codecs can make it steep for beginners. Incorrectly specified options can lead to unexpected output or errors. Performance is heavily dependent on hardware, especially for high-resolution video encoding, which is CPU-intensive. Users should also be aware of potential licensing complexities for certain codecs, although the ffmpeg project itself is open-source under LGPL/GPL.
STREAM SELECTION AND MAPPING
ffmpeg offers granular control over which streams (video, audio, subtitle, data) from inputs are processed and included in outputs. The -map option allows users to specify exactly which streams to use, enabling complex scenarios like combining audio from one file with video from another, or selecting specific language tracks.
COMPLEX FILTERGRAPHS
Beyond simple operations, ffmpeg supports intricate filtergraphs that enable sophisticated audio and video manipulations. These can range from simple scaling and cropping to complex overlays, picture-in-picture effects, concatenation of multiple videos, and advanced audio processing, all defined within a single command.
LIVE STREAMING AND DEVICE INTERACTION
ffmpeg is not just for local file conversion; it excels at live streaming by supporting various network protocols (e.g., RTMP, HLS, DASH, RTSP). It can also interact directly with hardware devices, allowing for screen recording, webcam capture, and microphone input, making it a versatile tool for broadcasting and content creation.
HISTORY
ffmpeg was initiated by Fabrice Bellard in 2000, with its name standing for "Fast Forward MPEG." From its inception, it aimed to provide a comprehensive solution for multimedia handling. Over the years, it has evolved significantly, incorporating support for new codecs, formats, and technologies as they emerged. Despite a notable fork in 2011 that led to the creation of the Libav project (which has since largely merged back or faded in prominence), the ffmpeg project has remained the dominant and most actively developed open-source multimedia framework. Its continuous development and robust capabilities have made it an essential component of countless media applications, streaming services, and professional workflows worldwide.