PUBLICATION_DATE: 2021.12.05

Useful FFmpeg commands

DOMAIN: Media/Video

« BACK TO NOTES

FFmpeg is a powerful command-line tool for video and audio processing. I find myself reusing these commands frequently.

Extract LPCM Audio Track

Extracts an audio track from a fully muxed input file.

ffmpeg -i stream_file.m2ts -map 0:a:0 audio.wav
  • -i specifies the input file
  • -map 0:a:0 selects the first audio stream
  • Output format determined by file extension
Extract a Video Track

Extracts a video track from a muxed input file without re-encoding.

ffmpeg -i stream_file.m2ts -c copy -an vid_only.mp4
  • -c copy copies the stream without re-encoding
  • -an removes audio streams
Convert Video Format

Convert between video formats while maintaining quality.

ffmpeg -i input.mov -c:v libx264 -crf 23 -c:a aac output.mp4
  • -c:v libx264 uses H.264 video codec
  • -crf 23 sets quality (lower = better, 18-28 is typical)
  • -c:a aac uses AAC audio codec
Resize Video

Resize video to specific dimensions.

ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
  • -vf scale=1280:720 sets width and height
  • Use -1 for auto: scale=1280:-1 maintains aspect ratio
Extract Frames as Images

Extract video frames as individual images.

ffmpeg -i input.mp4 -vf fps=1 frame_%04d.png
  • fps=1 extracts 1 frame per second
  • %04d creates numbered sequence (0001, 0002, etc.)
Combine Audio and Video

Merge separate audio and video files.

ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac output.mp4
  • First -i is video source
  • Second -i is audio source
  • -c:v copy keeps original video encoding
Learn More

Full documentation available at ffmpeg.org.