Master the basic video filters: scale, crop, rotate, fps, trim, and setpts, understand filter syntax with parameters and options, and build filter chains using -vf to process video precisely in a single command.

After mastering video encoding in episode 4 — codec, -crf, bitrate, and GOP — this episode adds one new dimension: filters. If encoding determines how the video is compressed, filters determine what the video looks like before it's compressed.
Remember the pipeline from episode 2: Demux -> Decode -> Filter -> Encode -> Mux. Filters live in the middle, after the video is decoded into raw frames and before it's encoded again. That's where you can resize, crop, rotate, or change speed — all before encoding.
A filter is a single-frame processor: it receives one frame, processes it, and produces one output frame. libavfilter — the library we met in episode 2 — is the engine behind it.
Think of a studio photographer touching each photo one by one before printing: resize, crop, rotate, adjust lighting. FFmpeg does that for thousands of frames per second with a single command.
A filter is written in the form filter_name=options. Options can be:
| Form | Example | Meaning |
|---|---|---|
| Single value | scale=640 | Set the first parameter only |
| Two values | scale=640:360 | Parameters separated by colon |
| Name=value | scale=w=640:h=360 | Options named explicitly |
| Expression | rotate=45*PI/180 | Values can be expressions |
Important
Be careful with two separators that are easy to confuse: colon (:) separates options within one filter, while comma (,) separates filters. Swapping them will make the filtergraph fail to parse.
Filters are attached to the -vf (video filter) option on the output side:
ffmpeg -i sample.mp4 -vf scale=640:360 out-640.mp4This command changes all frames to 640x360 before encoding — regardless of the original resolution.
ffmpeg -i sample.mp4 -vf scale=480:-1 out-480.mp4-1 makes FFmpeg compute the other side so the aspect ratio is preserved: a width of 480 produces a height that follows the video's original ratio. This is far safer than forcing scale=480:360, which would distort the picture.
ffmpeg -i sample.mp4 -vf crop=640:360 out-crop.mp4The format is crop=width:height:x:y. The x:y coordinates mark the top-left corner of the crop area; without coordinates, FFmpeg crops from the center. Cropping is like cutting a photo with scissors — pixels outside the area are discarded.
ffmpeg -i sample.mp4 -vf rotate=PI/2 out-rotated.mp4rotate accepts values in radians — PI/2 equals 90 degrees. The value is an expression that FFmpeg computes, so rotate=45*PI/180 will rotate exactly 45 degrees.
ffmpeg -i sample.mp4 -vf fps=15 out-fps15.mp4The fps filter recomputes the frame rate: frames are duplicated or dropped to match the target. The difference from the -r option in episode 4: -vf fps affects frames before encoding, while -r works at the output stage.
There are two approaches to cutting duration. The quick way uses the input option -ss, the precise way uses the trim filter:
ffmpeg -ss 00:00:00 -t 5 -i sample.mp4 -c copy potong.mp4ffmpeg -i sample.mp4 -vf trim=start=2:end=8,setpts=PTS-STARTPTS potong-presisi.mp4Both change the duration, but in different ways. -ss before -i makes FFmpeg jump directly to second 0 then grab 5 seconds — fast, good for rough cuts. trim processes frames and needs setpts to reset the timestamps after cutting.
ffmpeg -i sample.mp4 -vf setpts=PTS/2,scale=640:-1 out-fast.mp4setpts shifts the frame timestamps. PTS/2 speeds up by 2x (half timestamp = frames appear faster); PTS*2 slows down. This filter almost always appears paired with trim to clean up timestamps.
Filters can be joined with commas — the first filter's output becomes the next filter's input:
ffmpeg -i sample.mp4 -vf scale=480:-1,fps=15,setpts=PTS/2 out-chain.mp4The order is read left to right: resize to 480p, force 15 fps, then speed up 2x. Order matters: resize first then process, so each filter works on frames at the expected size. A filter chain is like an assembly line — each station does one job before passing on.
Tip
Check what filters are available with ffmpeg -filters — the list has hundreds. For now, master the five filters above until they're second nature, because they're the foundation for the complex filtergraphs in later episodes.
In episode 5, you've mastered the basic video filters: filter syntax with parameters and options, six important filters — scale, crop, rotate, fps, trim, and setpts — and building filter chains with -vf.
Key takeaways:
-vf on the output side.scale for sizing, crop for cutting an area, rotate for rotating.trim/-ss cut duration; setpts sets timestamps and speed.In the next episode 6, we'll cover audio processing — audio filters like volume, fade, aecho, and amix, resampling, normalization, and how to swap and combine audio tracks. See you in episode 6!