Some Useful ffmpeg Commands

Published: 2021-12-18
Last Updated: 2022-04-06

ffmpeg is an incredibly useful CLI tool that I use to modify video files. Below are some of my favorite and frequently used commands.

Resize Resolution of Video File

For this example, I'm converting a 1080p video to 720p, but you can update the values after scale such as 1920x1080 (if you're reducing from a 4K video) or 960x540 if you want something smaller than 720p. Note that "input.mp4" will be the name of the video file you're converting, whereas "output.mp4" is the name of the new file being created.

ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4

I've found that if I'm downsizing a 4K to 1080p, it helps to encode it using crf=18 and add the slow parameter to keep the video high quality. Note that adding the slow parameter basically means that it will be encoded much more slower. In my case, I downsized a 2 hour long 4k video which took all night.

ffmpeg -i input.mp4 -vf scale=1920:1080 -preset slow -crf 18 output.mp4

Convert From One Video Format to Another

Personally, I try to avoid using video file formats other than mkv or mp4s as they're much easier to work with and have more support.

ffmpeg -i input.avi -c copy output.mkv

Convert All Video Files in a Directory to Different Format

This command is handy when I need to convert multiple video files in a directory. For this example, I'm converting all files ending in ".avi" to ".mp4".

for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done

Convert A Single Audio From Flac to Ogg

I wrote a short how-to about converting multiple Flac files to Ogg, but I occasionally run into issues. Alternatively, you can convert single flac files to ogg with the following command, where "9" is roughly a bitrate of 320kpbs.

ffmpeg -i input.flac -c:a libvorbis -q:a 9 output.ogg

Get Information on a File

Using the "-i" option alone is useful for displaying a files metadata, bitrate, resolution, duration, etc.

ffmpeg -i input.ogg

 

Thanks for reading. Feel free to send comments, questions, or recommendations to hey@chuck.is