FFmpeg cheatsheet
Written by masteryeti on .FFmpeg is ideal for processing video (and audio). If you are dealing with video files, FFmpeg is likely a useful tool. The documentation of FFmpeg is very limited. This cheatsheet lists some common usage of FFmpeg. DISCLAIMER: May contain errors and/or misconceptions, always check the documentation and thoroughly test the result.
General usage
FFmpeg takes input and processes it into an output, and has the following general usage:
ffmpeg [INPUT OPTIONS] -i <INPUT> [OUTPUT OPTIONS] <OUTPUT>
<INPUT>: For example,/dev/video0for webcam;pipe:0to read from stdin (standard input); or/path/to/file.mp4to read from a file.<OUTPUT>: For example,/path/to/file.mp4to write to a file;pipe:1to write to stdout (standard output).
The order of the input and output options is usually not important.
Input options
-
-re: Prevent reading from input as fast as possible, but limit reading speed to the realtime framerate of the output (optionally use with the-routput option to set a custom framerate). -
-f v4l2: Default for any /dev/video* device.
-f video4linux2: Alias for v4l2.-
-input_format: The pixelformat of the device: mjpeg, yuyv422, etc. FFmpeg will try to change the device's output pixelformat automatically, which succeeds as long as the device supports the given format. To discover formats, try:ffmpeg -f video4linux2 -list_formats all -i /dev/video0.
-
-
-f rawvideo: Take raw video frames input (without container).-pixel_format yuv420p: Pixel format: yuv420p, rgb24, gray8, etc.-video_size 1280x720: Resolution: 1280x720, 1920x1080, etc.-framerate 15: Framerate: 15, 25, 30, etc.
Output options
-
-y: Force overwrite<OUTPUT>without interactive prompt (answer y to prompt). -
-r 15: Set a custom framerate for the output. This will skip/drop frames if input is faster, and duplicate frames if input is slower. -
-f rawvideo: Output raw video frames (without container).-pix_fmt yuv420p: Pixel format: yuv420p, rgb24, gray8, etc.-s 1280x720: Resolution: 1280x720, 1920x1080, etc.-r 15: Framerate: 15, 25, 30, etc.
Examples
List all possible values for the input_format input option that the given webcam supports:
ffmpeg -f video4linux2 -list_formats all -i /dev/video0
This is the FFmpeg-interpreted equivalent of v4l2-ctl --list-formats-ext -d /dev/video0.
Note that FFmpeg will try to negotiate an input format based on your input options with the input device.