Command-line media framework

FFmpeg

FFmpeg can convert, inspect, extract, filter and automate media files. The command line looks harder than it is. Most everyday jobs follow the same pattern: input → options → output.

Before you start

Make sure FFmpeg is available

Open PowerShell, Command Prompt, Terminal, or your shell of choice and run:

ffmpeg -version

If you see version and build information, you are ready. If the shell says FFmpeg is not recognized or not found, install it and make sure the FFmpeg executable is available on your PATH.

Single files

Convert one audio file

For simple conversions, the output extension often does most of the work.

WAV to MP3

ffmpeg -i input.wav output.mp3

FFmpeg chooses a suitable MP3 encoder and default settings from the build you installed.

WAV to FLAC

ffmpeg -i input.wav output.flac

FLAC is lossless. The decoded audio remains the same while the file is compressed.

FLAC to WAV

ffmpeg -i music.flac music.wav

Useful when an editor, game tool or older program wants uncompressed PCM.

WAV to Opus

ffmpeg -i input.wav -c:a libopus -b:a 128k output.opus

This explicitly chooses the Opus encoder and a target audio bitrate.

Quality settings

Choose a codec and quality level

The file extension chooses the container or format. -c:a chooses the audio encoder. Quality or bitrate options control the tradeoff between size and quality.

MP3, high-quality VBR

ffmpeg -i input.wav -c:a libmp3lame -q:a 2 output.mp3

With LAME, lower -q:a values mean higher VBR quality. A value around 2 is a common high-quality starting point.

MP3, fixed bitrate

ffmpeg -i input.wav -c:a libmp3lame -b:a 192k output.mp3

Use a fixed bitrate when you need predictable size or hardware compatibility.

AAC

ffmpeg -i input.wav -c:a aac -b:a 192k output.m4a

The built-in AAC encoder is widely available in normal FFmpeg builds.

Opus

ffmpeg -i input.wav -c:a libopus -b:a 128k output.opus

Opus is efficient at relatively low bitrates. Use a bitrate appropriate for music, speech, or game assets.

FLAC compression level

ffmpeg -i input.wav -c:a flac -compression_level 8 output.flac

Higher FLAC compression generally trades more encoding work for a somewhat smaller file. It does not change decoded audio quality.

Set sample rate and channels

ffmpeg -i input.wav -ar 48000 -ac 2 output.wav

-ar 48000 sets 48 kHz. -ac 2 requests two output channels.

Rule of thumb

If you do not need to change codec, sample rate, channels, loudness, or other audio content, do not re-encode just because you can. Lossy-to-lossy conversion can reduce quality.

Whole folders

Process every file in a folder

FFmpeg itself processes one command at a time. Your shell supplies the loop. That makes batch work flexible, but it also means you are responsible for filenames, output folders, collisions and failures.

Windows PowerShell: convert every WAV to MP3

New-Item -ItemType Directory -Force mp3 | Out-Null
Get-ChildItem -Filter *.wav | ForEach-Object {
    ffmpeg -i $_.FullName -c:a libmp3lame -q:a 2 (Join-Path "mp3" ($_.BaseName + ".mp3"))
}

macOS / Linux shell: convert every WAV to MP3

mkdir -p mp3
for f in *.wav; do
  ffmpeg -i "$f" -c:a libmp3lame -q:a 2 "mp3/${f%.*}.mp3"
done

Start on a copy of a small folder first. Once the command produces the filenames and quality you expect, use it on the larger library.

Video

Extract audio from video

A video file can contain video, one or more audio streams, subtitles and metadata. You can either copy an existing audio stream or decode it and create a new audio file.

Extract and convert to MP3

ffmpeg -i video.mp4 -vn -c:a libmp3lame -q:a 2 audio.mp3

-vn means do not include video in the output.

Extract and convert to WAV

ffmpeg -i video.mp4 -vn audio.wav

FFmpeg decodes the selected audio stream and creates PCM audio in a WAV file.

Copy compatible audio without re-encoding

ffmpeg -i video.mp4 -vn -c:a copy audio.m4a

Stream copy is fast and avoids generation loss, but the output container must support the audio codec that is already inside the video.

Choose a specific audio stream

ffmpeg -i video.mkv -map 0:a:1 -vn audio.flac

This selects the second audio stream from input 0. Stream numbering starts at zero.

Inspect first

See what is inside a file

If a file has multiple audio tracks or you are unsure which codec it uses, inspect it before writing a complicated command.

ffmpeg -i video.mkv

FFmpeg prints the streams it finds. Look for lines labeled Audio, including codec, sample rate, channel layout and stream number. FFmpeg may end with a message about no output being specified. That is expected when you are only inspecting the input.

Common errors

What the error usually means

ffmpeg is not recognized / command not found

FFmpeg is either not installed or your shell cannot find it. Check ffmpeg -version. If necessary, run FFmpeg using its full path or add its executable directory to PATH.

No such file or directory

The input path is wrong, you are in the wrong folder, or the filename needs quoting. Use quotes around paths that contain spaces:

ffmpeg -i "My Music/song one.wav" "output.mp3"

File already exists

FFmpeg normally asks before overwriting. Use -y only when you intentionally want to overwrite without being asked:

ffmpeg -y -i input.wav output.flac

Unknown encoder

Your FFmpeg build does not contain the encoder named in the command, or the encoder name is wrong. Run ffmpeg -encoders and search the list. Different builds can include different optional libraries.

Invalid argument

Often this is a bad option value, an output container that cannot hold the selected codec, or a malformed path. Read the lines immediately above the final error. FFmpeg usually reports the more specific cause there.

Output file is empty or has no audio

Check the input streams and any -map option. If the source has several audio tracks, make sure you selected the one you intended.

Conversion works but sounds worse

Check whether you converted from one lossy codec to another and review bitrate or quality settings. When possible, start from a lossless or original source.

Folder script stopped halfway through

The shell loop and FFmpeg are separate pieces. One bad file, naming collision, permissions problem, or script setting can interrupt a batch. Test small, keep source files untouched, and review the console output for the first failed file.

Useful next commands

A few options worth remembering

-i input-c:a audio codec-b:a audio bitrate-q:a encoder quality-ar sample rate-ac channel count-vn omit video-map select streams-y overwrite-n never overwrite
Where to go deeper

FFmpeg is much larger than audio conversion. Its official manual documents stream selection, codecs, filters, mapping, metadata, hardware acceleration and hundreds of format-specific options.

Read the official FFmpeg manual ↗