· FabLab Westharima Team · Documentation  · 6 min read

FFmpeg Installation, Usage, Options, and Commands

Explaining usage of FFmpeg, a powerful tool that can execute video/audio conversion, compression, extraction, and concatenation via command line. Basic command structure and practical recipes without confusion even for beginners.

目次

FFmpeg is a powerful tool that can execute video/audio conversion, compression, extraction, concatenation, etc. via command line. This article aims to “avoid confusion even for first-timers” by summarizing basic command structure and frequently used options in tables with usage examples. Also includes practical recipes ready for copy-paste.


Installation

  • macOS (Easy to use Homebrew):
  1. Install Homebrew (only if you haven’t)

  2. Install ffmpeg (execute following command from terminal) brew install ffmpeg

  3. Check version ffmpeg -version

  • Windows:

    • Official distribution or choco install ffmpeg (Chocolatey), etc.

    • Check with ffmpeg -version after installation.

  • Linux:

    • Use distribution’s package manager (e.g., sudo apt install ffmpeg).

Basic Command Structure (Most Important)

FFmpeg basic form is below. Conceptually it’s flow of “input → processing → output”.

ffmpeg [global options] [input options] -i [input file] [output options] [output file]

Role of Each Part

Part NameRole/DescriptionExample/Notes
Global OptionsOptions affecting entire ffmpeg-y (overwrite output file without confirmation)
Input OptionsSpecifications for input file-ss 60 (start from 60 seconds of input), -f mp4 (explicitly specify input format)
Input FileSpecify file to convert/edit-i input.mp4
Output OptionsSpecify output format and encoding method-c:v libx264 (video codec), -c:a aac (audio codec), -crf 23 (quality specification), -vf scale=1280:720 (resize)
Output FileSpecify file name after conversion/editoutput.mp4

Points (Order is Important)

  • For most options, “which output it affects” is determined by position. In principle, options written “before” output filename are applied to that output.

  • Specify input with -i, then line up codec, bitrate, filters (-vf/-af), etc., and write output filename at end.

  • Multiple outputs possible in single command (place options right before each output).

Command Example

ffmpeg -y -i input.mp4 -c:v libx264 -crf 23 -c:a aac -b:a 128k -vf "scale=1280:720" output.mp4

Command Example Breakdown Image

ffmpeg \
  [global] \            # -y (overwrite output file without confirmation)
  -i input.mp4         # Input (container: MP4, contains video/audio streams) \
  -c:v libx264 -crf 23    # Video codec settings (libx264) and quality (CRF) \
  -c:a aac -b:a 128k      # Audio codec (AAC) and audio bitrate \
  -vf scale=1280:720      # Video filter (e.g., resize) \
  output.mp4              # Output

Terminology Memo (For Beginners)

TermMeaning/DescriptionExample/Notes
CodecMethod to compress/decompress data. “Internal format” of video or audio.Video: H.264, Audio: AAC
ContainerFormat of “container” that stores video, audio, subtitles, etc. together.MP4, MKV, etc.
BitrateAmount of data per second. Higher tends to better image/sound quality.2M = 2 megabits/second
Frame RateNumber of frames (images) displayed per second.24fps, 30fps, 60fps, etc.
ResolutionScreen vertical/horizontal size (number of pixels).1920x1080, etc.
CRFQuality target index (Constant Rate Factor). Smaller is higher quality.0=lossless, 18-28 is guideline, around 23 is standard
CFR/VFRConstant Frame Rate (CFR) / Variable Frame Rate (VFR). Use according to application.Switch for editing or streaming

Frequently Used Options Quick Reference (With Usage Examples)

OptionRole/MeaningCommon Use CasesUsage ExampleNotes
-iSpecify input fileStarting point of conversion/edit-i input.mp4Multiple possible (line up -i).
-c:vSpecify video codecSelect H.264/H.265/VP9, etc.-c:v libx264H.264 (libx264) for compatibility priority.
-c:aSpecify audio codecAAC/MP3/Opus, etc.-c:a aacAAC is safe for general MP4.
-b:vVideo bitrateABR or CBR specification-b:v 2MRoughly controls file size. Not recommended with CRF.
-b:aAudio bitrateAudio quality adjustment-b:a 128k128k often sufficient for talk-centered content.
-crfQuality index (variable bitrate)Quality-priority compression-crf 23Smaller number is higher quality. 18-28 guideline for H.264.
-presetEncode speed/compression ratio adjustmentAdjust speed keeping quality same-preset slowultrafastplacebo. Slower = higher compression = smaller.
-vfVideo filterResize/crop/rotate, etc.-vf scale=1280:720Connect multiple with ,.
-afAudio filterVolume adjustment/normalize, etc.-af volume=1.5Can also write as -filter:a.
-filter_complexComplex filter graphConcatenation/PIP, etc.-filter_complex "[0:v][1:v]hstack"Supports multiple inputs/branching.
-ssStart positionTrimming/thumbnail extraction-ss 00:01:00Before input=fast/approximate, after=precise.
-tDuration (seconds/time)Specify clip length-t 30-to is end time. Avoid combining (later written takes priority).
-toEnd timeSpecify up to 2 minutes, etc.-to 00:02:00Use with -ss for section extraction too.
-rOutput frame rate24/30/60fps, etc.-r 30Used when changing input fps.
-sOutput resolutionStandardize to 720p, etc.-s 1280x720Mostly same as -vf scale. -vf recommended for filter chain.
-mapStream selectionOnly specific video/audio/subtitle-map 0:v:0 -map 0:a:0Controls automatic selection. Important with multiple inputs.
-anNo audioMute video-anDon’t output audio track.
-vnNo videoAudio extraction-vnDon’t output video track.
-snNo subtitlesRemove subtitles-snDon’t output subtitles.
-pix_fmtPixel formatEnsure compatibility-pix_fmt yuv420pEffective for old playback devices.
-movflags +faststartMove MP4 moov to frontFast web playback-movflags +faststartStreaming starts quickly.
-shortestMatch to shortest streamBGM is short, etc.-shortestEnd early matching shortest stream.
-yAllow overwriteAutomation-yOverwrite existing file without confirmation.
-nProhibit overwritePrevent accidental overwrite-nFail if exists.
-fSpecify formatExplicitly state raw PCM, etc.-f wavUse when automatic detection errors.

Note: For H.264/H.265 quality priority, -crf+-preset is basic. Only consider -b:v (2pass recommended) when there’s clear target size.

Note 2: -r has different meaning on input side and output side. -r placed before input is specification “consider input frame rate as this”, unnecessary for normal MP4 etc. Output side -r specifies “output target fps”.


Ready-to-Use Commands (Copy-Paste OK)

1) MOV→MP4, CRF 25 specification

ffmpeg -i input.mov -crf 25 output1.mp4

2) Video trimming (30 seconds from 1-minute point)

ffmpeg -i input.mp4 -ss 00:01:00 -t 30 -c:v libx264 -crf 22 -c:a aac -b:a 128k output_clip.mp4

Memo: Placing -ss “after” input improves frame accuracy (speed slightly decreases).

3) Fast rough trimming (keyframe basis)

ffmpeg -ss 60 -i input.mp4 -t 30 -c copy output_fast.mp4

Memo: Place -ss “before” input, no re-encoding with -c copy. Cut point becomes approximate.

4) Mute audio (video re-encoded)

ffmpeg -i input.mp4 -an -c:v libx264 -crf 23 output_noaudio.mp4

5) Extract only audio (WAV or MP3)

# WAV (uncompressed)
ffmpeg -i input.mp4 -vn -c:a pcm_s16le -ar 48000 -ac 2 output.wav

# MP3 (compressed)
ffmpeg -i input.mp4 -vn -c:a libmp3lame -b:a 192k output.mp3

6) Resize to 1280x720 resolution

ffmpeg -i input.mp4 -vf scale=1280:720 -c:v libx264 -crf 22 -c:a aac -b:a 128k output_720p.mp4

7) Export with target bitrate (2Mbps)

ffmpeg -i input.mp4 -c:v libx264 -b:v 2M -c:a aac -b:a 128k output_2m.mp4

Example: -b:v 2M. “Video quality is not guaranteed. Try with your desired bitrate.”

8) Quality priority (CRF basis)

ffmpeg -i input.mp4 -c:v libx264 -crf 20 -preset medium -c:a aac -b:a 160k output_crf20.mp4

9) Concatenate multiple videos (assuming same codec/resolution/frame rate)

# 1) Create list file (e.g., files.txt)
# file 'part1.mp4'
# file 'part2.mp4'
# file 'part3.mp4'

# 2) Concatenate with concat demultiplexer
ffmpeg -f concat -safe 0 -i files.txt -c copy merged.mp4

10) Burn in subtitles (SRT)

ffmpeg -i input.mp4 -vf subtitles=subs.srt -c:v libx264 -crf 22 -c:a copy output_subbed.mp4

11) Rotate 90 degrees (clockwise)

ffmpeg -i input.mp4 -vf "transpose=1" -c:a copy output_rotated.mp4

12) Convert frame rate to 30fps

ffmpeg -i input.mp4 -r 30 -c:v libx264 -crf 22 -c:a aac -b:a 128k output_30fps.mp4

Specifying -r 30 is common. However, “frames are not interpolated, they are thinned/duplicated”


Common Questions/Troubleshooting

Error/PhenomenonSolution/Explanation
Unknown encoder ‘libx264’Build without H.264 encoder. macOS Homebrew version usually includes it. Use different distribution source or reinstall.
At least one output file must be specifiedForgot to write output filename. Explicitly state output.mp4 etc. at end.
Non-monotonous DTSTimeline goes back and forth in trimming or stream concatenation. May resolve with -fflags +genpts or re-encoding.
Web playback slow to startMove moov to front with -movflags +faststart.
Low compatibility/can’t play in some casesAdd -pix_fmt yuv420p, also consider adjusting level/profile for H.264.


Above summarizes FFmpeg’s “basic template”, “standard options”, and “ready-to-use recipes”. First try running samples with copy-paste, then adjust parameters as needed.

Back to Blog

Related Posts

View All Posts →
ImageMagick v7 Installation, Commands, and Options List

ImageMagick v7 Installation, Commands, and Options List

Explaining usage of ImageMagick, a powerful tool that can batch process image conversion, compression, resize, composition, etc. via command line. Comprehensively summarizing from installation methods to practical command examples for beginners.