Scale Video to 4K Using FFmpeg Neighbor Algorithm
Upscaling lower-resolution videos to 4K while maintaining sharp,
pixel-perfect details is a common requirement for retro game footage,
pixel art, and screencasts. This article provides a straightforward
guide on how to use FFmpeg and the neighbor (nearest
neighbor) scaling algorithm to upscale your videos to 4K (3840x2160)
resolution without introducing unwanted blur or interpolation
artifacts.
To upscale a video to 4K using the nearest neighbor algorithm in
FFmpeg, you must use the video filter (-vf) argument,
specify the target resolution, and set the scaling flag to
neighbor.
The FFmpeg Command
Run the following command in your terminal or command prompt:
ffmpeg -i input.mp4 -vf "scale=3840:2160:flags=neighbor" -c:a copy output.mp4Command Breakdown
-i input.mp4: Specifies the path to your source video file.-vf "scale=3840:2160:flags=neighbor": Applies the scaling filter.3840:2160defines the standard 4K UHD resolution.flags=neighborforces FFmpeg to use the nearest neighbor interpolation method. This simply multiplies the existing pixels, preserving sharp, blocky edges instead of blending them.
-c:a copy: Stream copies the audio without re-encoding, saving processing time and preserving original audio quality.output.mp4: The filename for your newly generated 4K video.
Maintaining the Aspect Ratio
If your input video is not in a standard 16:9 aspect ratio, forcing
it to 3840x2160 will stretch the image. To maintain the original aspect
ratio while scaling to a 4K width, use -1 for the height
parameter:
ffmpeg -i input.mp4 -vf "scale=3840:-1:flags=neighbor" -c:a copy output.mp4FFmpeg will automatically calculate the correct height relative to the 3840-pixel width, keeping the output crisp and perfectly proportioned.