Skip to content

ffmpeg Basics

A starting point to get the most out of ffmpeg to convert and transcode video formats and image sequences.

Authors: David Hecker

Created: 12 Oct 2024 Last updated: 24 Jun 2025


Purpose

ffmpeg is a command line tool used for performing various actions on video files and images. These include converting files between formats, joining files together, splitting audio tracks out from videos, adjusting keyframe intervals, etc.

Install ffmpeg

Download ffmpeg builds for your operating system from here: https://ffmpeg.org/download.html

Windows 10

Windows instructions: https://www.wikihow.com/Install-FFmpeg-on-Windows

Mac OS X

Alternatively, install using the command line on Mac OS X: Install Homebrew:

/bin/bash -c "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>)"

Once Homebrew is installed, tell it to install ffmpeg:

brew install ffmpeg

To update an existing ffmpeg install:

brew update && brew upgrade ffmpeg

Basic ffmpeg Commands

Get info about a file

ffmpeg -i video.mp4
ffprobe video.mp4

Convert image format, adjust size

ffmpeg -i in.jpg -vf scale=320:-1 out.png

Encode to MP4 using h264 video, MP2 audio

ffmpeg -i in.mov -vcodec h264 -acodec mp2 out.mp4

Convert to MP4, adjust size, maintaining proportions

ffmpeg -i in.mov -vf scale=960:-1 out.mp4

Encode folder of items, output retains original filename

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

Convert to MP4, specify keyframe interval

ffmpeg -i in.mov -vcodec libx264 -x264-params keyint=20:scenecut=0 -acodec copy out.mp4

Export audio only

ffmpeg -i in.mkv -vn out.mp3

Add audio silence to an audio file

Both of these methods transcode the file, so formats can be changed if required. Replace 1 in each example with the required duration in seconds.

  • Add silence to the start of a file:
ffmpeg -i input.wav -af "adelay=1s:all=true" output.wav
  • Add silence to the end of a file:
ffmpeg -i input.wav -af "apad=pad_dur=1" output.wav

Export video as frames

ffmpeg -i in.mp4 -r 30 out_%05d.png
  • -r 30 sets the frame rate

Export parts of video as frames

This example will export only the frames between 2-6 seconds and 15-24 seconds

ffmpeg -i in.mp4 -vf select='between(t,2,6)+between(t,15,24)' -vsync 0 out%d.png

Create thumbnails at set intervals

  • Output one image every second:
ffmpeg -i input.mp4 -vf fps=1 out%d.png
  • Output one image every minute:
ffmpeg -i test.mp4 -vf fps=1/60 thumb%04d.png

Convert image sequence to video

ffmpeg -r 60 -f image2 -s 1920x1080 -i in%04d.png -vcodec libx264 -crf 25 out.mp4
  • -r sets the frame rate
  • -s sets the size
  • in%04d.png specifies the filenames and padding
  • -crf sets the quality (lower is better)

Advanced ffmpeg Commands

Convert a top/bottom alpha-packed MP4 to HAP Alpha

ffmpeg -i in.mp4 -filter_complex "[0:v]pad=width=456:height=4320:x=1:y=0[a];[a]split=2[in1][in2];[in1]crop=in_w:in_h/2:0:0[top];[in2]crop=in_w:in_h/2:0:in_h/2[bottom];[top][bottom]alphamerge" -c:v hap -format hap_alpha -compressor snappy -chunks 4 -an -movflags faststart out.mov

Batch Processing

Multiple files in a folder can be batch processed using the following commands.

macOS/Linux

for file in *.mp4 ; do ffmpeg -i ${file} -crf 16 -c:v libx264 -c:a aac outfolder/basename ${file} .mp416.mp4 ; done

Windows (using PowerShell)

Get-ChildItem *.mp4| ForEach -Process {ffmpeg -i $_  -crf 16 -c:v libx264 -c:a aac ('./Output/'$_.BaseName + '-16' + '.mp4')}

Documentation

Online help: https://ffmpeg.org/ffmpeg.html

Terminal help: ffmpeg -h

GUI Alternatives

ffworks

https://www.ffworks.net/download.html

Handbrake

Only use this if you're really desperate or lazy and you don't need as much manual control over the compression.

https://handbrake.fr/