What ffmpeg actually does, every time
Every ffmpeg invocation runs the same five-stage pipeline. Once you can draw it on a napkin, command-line flags stop feeling random.
- Demux — open the input container, split it into raw streams (video, audio, subtitle, data).
- Decode — convert each compressed stream into raw frames or samples.
- Filter — optionally run filters (scale, crop, drawtext, loudnorm, fps, …).
- Encode — compress the raw frames/samples back into a codec.
- Mux — wrap the encoded streams into the output container.
If you skip the encode step (-c copy), you have a remux: the bits go straight from demuxer to muxer with no re-encoding. That's why remuxing is sub-second on a 4K file but a re-encode of the same file takes minutes.
How flags map to stages
The order of flags on the command line is not the order they execute. Position matters: input flags go before -i, output flags go before the output filename. The mental model:
-ss 30before-i= seek (skip to 30s) at demux time — fast.-ss 30after-i= seek by decoding all 30s and discarding — slow but frame-accurate.-c:v libx264before output filename = encoder choice for stage 4.-vf scale=1280:720= stage 3 filter applied to the video stream.