FFmpeg Commands for Conversion, Trimming, and Filters
Most useful FFmpeg commands start with an input, an explicit job, and a different output filename. Inspect the streams first, then decide whether you need to re-encode or can copy them unchanged.
A basic conversion looks like this:
ffmpeg -i input.avi converted.mp4
The .mp4 extension chooses a container. FFmpeg may choose codecs automatically, so use explicit codec settings when the result needs a predictable playback format.
Start FFmpeg commands with the file you actually have
Install FFmpeg from a maintained source listed on the official download page. On macOS with Homebrew already installed, its package is an option; use your distribution’s packages or a maintained build on other systems.
Check the available executable:
ffmpeg -version
Inspect a video without starting another conversion:
ffprobe -v error -show_streams -show_format input.mp4
The report identifies the video and audio streams, codecs, dimensions, and container details. A filename alone cannot tell you which codecs are inside.
The FFmpeg manual describes option placement. Input options belong before the relevant -i; output options belong before the output filename. Moving an option across those boundaries can change what it affects.
Convert with an explicit quality choice
For an H.264/AAC MP4:
ffmpeg -i input.avi -c:v libx264 -crf 23 -preset medium -pix_fmt yuv420p -c:a aac -b:a 192k -movflags +faststart compressed.mp4
libx264 selects the video encoder and aac selects the audio encoder. Your build must include those encoders; the command’s spelling cannot add one that is missing.
With x264, a lower CRF requests higher quality and generally produces a larger file. The preset changes the encoding-time and compression trade-off, rather than acting as a simple quality slider. The encoder documentation describes those controls.
yuv420p is a deliberate pixel-format choice for this example. +faststart moves MP4 metadata toward the beginning for progressive download; it does not make a large video small or replace an adaptive streaming setup.
I would change one setting at a time and compare the result on the intended device. A lower file size is not useful if the text in a screen recording becomes unreadable.
Copy streams when only the container needs to change
If the existing codecs fit the destination container, remux them:
ffmpeg -i input.mov -c copy remuxed.mp4
Stream copy avoids another encode. It cannot apply a video filter, resize the picture, or make an incompatible codec fit the new container.
If remuxing fails, inspect the streams and the error before replacing copy with random encoder options. The missing decision is often which output format the consumer actually supports.
Choose between a quick trim and an accurate cut
A quick ten-second segment starting around thirty seconds:
ffmpeg -ss 00:00:30 -i input.mp4 -t 10 -c copy clip-copy.mp4
Stream copying is constrained by the source’s seek points and packet boundaries. Do not use that command as a promise of frame-exact cuts.
For a cut that decodes and re-encodes the selected segment:
ffmpeg -i input.mp4 -ss 00:00:30 -t 10 -c:v libx264 -crf 23 -c:a aac clip-accurate.mp4
The second command puts the seek after the input and encodes new output. Check both the picture and sound around the cut; timestamps and source characteristics still matter.
The commands use distinct output names so you can compare the results without replacing the original file.
Extract an audio file deliberately
To create a stereo MP3 at 44.1 kHz:
ffmpeg -i input.mp4 -vn -ar 44100 -ac 2 -b:a 192k audio.mp3
-vn excludes video, -ar sets the sample rate, and -ac requests two audio channels. The 192k suffix makes the intended audio bitrate explicit.
This converts the audio. If preserving the original encoded audio is the goal, choose a compatible audio container and investigate stream copying instead.
The older example used -ab 192; keeping the unit explicit with -b:a 192k is clearer and avoids carrying an ambiguous old spelling into another script.
Scale before adding a complicated filter graph
A fixed output width with a derived, even height:
ffmpeg -i input.mp4 -vf "scale=1280:-2" -c:v libx264 -crf 23 -c:a copy scaled.mp4
The scale filter documents the negative dimension values. This command requests a width of 1280, so it can upscale a smaller source as well as reduce a larger one.
Audio is copied here because scaling affects the video. The destination still needs to support that audio codec.
For a complete blur example:
ffmpeg -i input.mp4 -vf "boxblur=2:2" -c:v libx264 -crf 23 -c:a copy blurred.mp4
A video filter requires video decoding and encoding. Combining a filter with -c:v copy asks for incompatible operations.
Give every branch of a filter graph a name
An earlier fragment in this article selected frames, blurred one branch, and interleaved the results. A complete version needs input and output labels:
ffmpeg -i input.mp4 -filter_complex "[0:v]select='if(gt(random(0),0.2),1,2)':n=2[clean][to_blur];[to_blur]boxblur=2:2[blurred];[clean][blurred]interleave=nb_inputs=2[v]" -map "[v]" -map '0:a?' -c:v libx264 -crf 23 -c:a aac mixed-blur.mp4
The select and interleave filter documentation explains the branching and timestamp ordering. The random expression sends frames to one of two outputs; one branch is blurred before the streams are combined again.
Treat this as an intentionally variable visual effect, not a repeatable privacy redaction. For a normal resize or blur, the earlier single-filter commands are much easier to maintain.
Batch only after one conversion works
For a POSIX-style shell, write batch outputs to a separate directory:
mkdir -p converted
for file in ./*.avi; do
[ -f "$file" ] || continue
ffmpeg -n -i "$file" -c:v libx264 -crf 23 -c:a aac "converted/$(basename "${file%.avi}").mp4"
done
The existence check handles an unmatched pattern without feeding it to FFmpeg. Quoting keeps spaces in filenames together, and -n prevents an existing output from being overwritten.
Keep the originals until you have inspected the output streams and played representative sections. A successful exit status is useful, but it cannot decide whether the crop, sound, or visual quality matches the job.
Filed under Tools on
Last updated on