The -2 rule of scale for changing resolution, the more precise zscale, and fps for changing the frame count. Plus how scale affects color range.
Chapter 1 covered how resolution and frame rate affect file size (Pixels, resolution, and frame rate). Here we look at how to actually change them with FFmpeg, and the traps you hit when you do.
scale=width:height changes the resolution. Using -1 on one side calculates it automatically to match the original aspect ratio, while `-2` matches the ratio and also rounds the result to a multiple of 2. With 4:2:0 chroma subsampling (Chroma subsampling) the chroma planes are half the width and height, and H.264-family encoders often can't accept odd dimensions, so -2 is effectively the default.
ffmpeg -i input.mp4 -vf "scale=-2:720" -c:v libx264 -crf 20 -c:a copy out.mp4
# Choose the algorithm: for downscaling, bicubic (the default) or lanczos are common
ffmpeg -i input.mp4 -vf "scale=-2:720:flags=lanczos" -c:v libx264 -crf 20 -c:a copy out.mp4
# Never larger than the source: wrap the comma inside the expression in single quotes
ffmpeg -i input.mp4 -vf "scale='min(1280,iw)':-2" -c:v libx264 -crf 20 -c:a copy out.mp4scale is bicubic (per the FFmpeg documentation). With flags= you can pick bilinear, lanczos, spline, and others.zscale is the same filter we used for HDR tone mapping in Chapter 14 (Tone mapping). It uses the libzimg library, so your FFmpeg build must include libzimg. It lets you handle color primaries, transfer function, matrix, and range conversion precisely in a single filter, and it can resize too.
ffmpeg -i input.mp4 -vf "zscale=w=1280:h=720:filter=lanczos,format=yuv420p" -c:v libx264 -crf 20 -c:a copy out.mp4For adjusting the resolution of ordinary SDR video, scale is enough. Use zscale when color conversion of HDR or 10-bit video is involved, or when you need to handle color tags precisely. Which one "looks better" depends on the source and the algorithm, and this site has no measured values for it, so for important work, render both and compare by eye.
fps=30 drops or duplicates frames so the output runs at 30 frames per second. It does not create new frames by interpolation (interpolation is the job of a separate filter such as minterpolate). For example, going from 60 fps to 30 fps skips every other frame and reduces file size, while going from 24 fps to 30 fps duplicates some frames, which can make the motion look uneven (judder). Fractional frame rates are written as fractions (fps=24000/1001).
ffmpeg -i input.mp4 -vf "fps=30" -c:v libx264 -crf 22 -c:a copy out.mp4
# The output option -r 30 does a similar job. If you want to control the order inside a chain, use the fps filter.Brightness values in video are stored in one of two ranges: limited (TV, 16–235 at 8-bit) or full (PC, 0–255) (for the basics of color representation, see From RGB to YCbCr). The trouble starts when the two ranges get mixed. The scale filter has in_range/out_range options that let you instruct a range conversion.
ffmpeg -i input.mov -vf "scale=in_range=full:out_range=limited,format=yuv420p" \
-c:v libx264 -crf 20 -c:a copy out.mp4Options like -color_range only attach a tag to the file and do not change the pixel values. To properly fix a video whose range is off, you need to convert it with a filter as above; if you only set the tag wrong, the player interprets the video in a way that shows blacks that look lifted (gray instead of true black) or excessive contrast. The symptoms and diagnosis are in the same family as Why colors look washed out.
FFmpeg's basic resolution-changing filter. -1 and -2 keep the aspect ratio, flags selects the algorithm, and in_range/out_range sets the range.
A libzimg-based filter. Beyond resizing, it precisely handles color primaries, transfer function, matrix, and range conversion. Requires libzimg in the build.
A filter that sets the output frame rate by dropping or duplicating frames. It does not create new frames.
The range that holds brightness values. There are limited (TV, 16–235 @8-bit) and full (PC, 0–255).
You want to shrink a 1920×1080 video to 720 tall, with the width following the aspect ratio and rounded to an even number. Which filter is right?
Which is correct about what happens when you raise a 24 fps video to 30 fps with fps=30?