FFmpeg Command Line Tool
FFmpeg: Powerful Multimedia File Transcoding and Conversion
FFmpeg is a free and open-source software project consisting of a vast suite of libraries and programs for handling video, audio, and other multimedia files and streams. It includes libavcodec, a library of codecs that encodes and decodes audio and video, and libavformat, a container format library. FFmpeg is widely used for transcoding, conversion, and manipulation of multimedia files. This page provides examples of common FFmpeg commands for developers.
Basic File Conversion
Convert a file from one format to another based on file extensions. FFmpeg intelligently determines the input and output formats.
# Convert IN_FILE to OUT_FILE, based on its extension. So, if your IN_FILE has
# the `.mp3` extension and your OUT_FILE has the `.ogg` extension, then your
# file will be converted -- but original kept in-tact -- to an OGG file.
ffmpeg -i IN_FILE OUT_FILE
Convert and Remove Original File
After a successful conversion, you can automatically remove the original input file using shell commands.
# Remove the original upon successful completion of ffmpeg(1).
ffmpeg -i IN_FILE OUT_FILE && rm -v IN_FILE
Batch Conversion of Audio Files
This example demonstrates how to convert all MP3 files in the current directory to OGG format, deleting the originals upon successful conversion. This is a common task for managing audio libraries.
# Convert all MP3s in the CWD to OGGs, deleting the originals when successfully
# converted. This will be a huge time-saver! Note that this is Bash syntax.
# By the way, this example works non-recursively.
for File in *.mp3; { [ -f "$File" ] || continue; ffmpeg -i "$File" "${File%.mp3}.ogg" && rm -v "$File"; }
Image Format Conversion
FFmpeg is not limited to audio and video; it can also handle image conversions.
# Obviously ffmpeg(1) works with audio files, but it can also work on images.
# This example will convert a JPEG image to the PNG format.
ffmpeg -i ImageFile.jpg ImageFile.png
Controlling FFmpeg Verbosity
FFmpeg can be very verbose by default. You can control the amount of output information displayed.
# By default, ffmpeg(1) is really verbose, so shut it up, displaying only the
# more important information, by using the `-v` flag, followed by its `0`
# argument; this argument means that only 'panic' messages will be shown. Refer
# to the ffmpeg(1) man page for more information on these levels of logging.
ffmpeg -v 0 -i IN_FILE OUT_FILE
Displaying Real-time Statistics
To monitor the progress of a conversion or transcoding process, you can use the `-stats` flag to display ongoing statistics.
# If you want to see ongoing but not over-the-top statistics for the file on
# which ffmpeg(1) is currently working, you can make use of the `-stats` flag.
ffmpeg -stats -i IN_FILE OUT_FILE