Home / Alt manpages / ffmpeg(1)

  • ffmpeg(1)
  • User command
  • linux

Convert, Trim and Inspect Media with ffmpeg

ffmpeg will convert almost any media file into almost any other format, but only once you tell it exactly which streams you mean. This walkthrough inspects a file, converts it, cuts a short clip, picks streams explicitly and applies a resize filter. The examples match ffmpeg 8.0.1 installed here from the ffmpeg package.

Allow about fifteen minutes. You need a shell, an input media file and enough free space for a second copy. The commands only read your input and write new files, but an output path can still overwrite existing media if you tell it to.

1. Check the installed command

Confirm which executable will run and which version it reports:

$ command -v ffmpeg
/home/linuxbrew/.linuxbrew/bin/ffmpeg
$ ffmpeg -version | head -1
ffmpeg version 8.0.1 Copyright (c) 2000-2025 the FFmpeg developers

This is an ordinary read-only check. Package versions and available encoders vary between machines, so do not assume an example using a named encoder is portable just because the command itself is.

Checkpoint

Set a shell variable to the real input file, quoted, especially if the path contains spaces:

INPUT='/path/to/input.mkv'
test -f "$INPUT" && printf 'input found: %s\n' "$INPUT"

2. Inspect streams before choosing an output

Ask ffmpeg to read the input and stop before writing anything. The first few lines identify the container, streams, codecs, dimensions and duration:

$ ffmpeg -hide_banner -i "$INPUT"
At least one output file must be specified

That final error is expected: ffmpeg has already inspected the input, it just has nowhere to write. Read the lines above it. A file may hold several video, audio, subtitle, attachment or data streams, and both input indices and stream indices start at zero.

  • Do not assume stream 0 is audio. Do not assume every input has one video stream either.
  • Use -map for a precise choice. Automatic selection guesses; -map does not.

3. Make a first conversion without overwriting

Let the output extension choose the format, and use -n as a safety boundary:

$ ffmpeg -hide_banner -n -i "$INPUT" output.mp4

With no codec options, ffmpeg decodes and re-encodes the selected streams using defaults suitable for the output format. Exact codecs and quality depend on the build and format. If output.mp4 already exists, -n refuses to overwrite it and exits immediately.

Check the result by inspecting it again:

$ ffmpeg -hide_banner -i output.mp4
At least one output file must be specified

Warning

If you need to replace a file deliberately, -y overwrites without asking. Treat that as a destructive action: verify the path first, and prefer a new filename until the result is confirmed. There is no ffmpeg undo; recover by restoring the original from a backup or recreating the output.

4. Copy streams when no re-encoding is needed

For a container change that suits the existing streams, stream copy skips decoding and encoding entirely:

$ ffmpeg -hide_banner -n -i "$INPUT" -map 0 -c copy copied.mkv

-map 0 manually includes every stream from the first input. -c copy copies packets instead of re-encoding them. This is fast and preserves the encoded data exactly, but the destination container still has to support those streams. It is not a way to change one codec into another.

Checkpoint

Rerun the inspection command on copied.mkv. The stream list should match the input, subject to what the Matroska container accepts.

5. Trim a clip and resize it

To make a one-minute clip starting at 30 seconds, put the input seek before -i and the output duration before the output name:

$ ffmpeg -hide_banner -n -ss 00:00:30 -i "$INPUT" -t 00:01:00 \
    -vf 'scale=1280:-2' -c:v libx264 -c:a aac clip.mp4

-ss seeks in the input, -t limits the output duration, and -vf applies a video filter. The height -2 keeps the aspect ratio while making the computed value encoder-friendly. Video and audio get re-encoded here because filtering needs decoded frames, and the chosen encoders must exist in your build.

Check duration and streams with the same no-output inspection command:

$ ffmpeg -hide_banner -i clip.mp4
At least one output file must be specified

Input placement matters: an input -ss seeks before decoding, while an output -ss decodes and discards data until the requested position. Seeking may land near a keyframe, especially with stream copy. For an accurate re-encoded clip, test the start and end rather than trusting the filename.

6. Select one stream explicitly

To extract the first video stream as one PNG frame, map it and disable audio:

$ ffmpeg -hide_banner -n -i "$INPUT" \
    -map 0:v:0 -an -frames:v 1 frame.png

The selector means input 0, video stream 0. -an disables audio output, and -frames:v 1 stops after one video frame. Replace 0:v:0 only after checking the stream list; a subtitle or attached-picture stream is not interchangeable with the main video.

Prefer explicit maps in scripts when the input is not fully under your control. Automatic selection chooses streams based on what the output format accepts, which changes the result the moment a file gains an extra audio language or subtitle track.

Common traps

  • Output already exists. Use a new path, or inspect it before choosing between -n and the destructive -y.
  • Unknown encoder. Run ffmpeg -encoders and pick a codec this build actually lists.
  • Wrong stream selected. Inspect first, then add -map and stream specifiers such as -c:v or -c:a.
  • Timing looks off. Check whether -ss, -t and -to are input or output options; the manpage says -t takes priority if both -t and -to are supplied.
  • Missing file or permission error. Check the path and directory permissions. sudo ffmpeg does not repair a bad path or codec choice.

Done means

  • Confirmed the installed version. You know which ffmpeg build is running.
  • Inspected before selecting. Streams were checked before any -map was written.
  • Produced a real output. A conversion, stream copy or filtered clip exists under a new filename.
  • Protected existing files. -n was used for examples that must not overwrite anything.
  • Verified and can recover. You checked the output again and know how to undo an unwanted result.