求助:FFmpeg去除视频闪烁、裁剪保画质及4K upscale方案
Hey there, I feel your pain—spending a full day debugging FFmpeg commands can be so frustrating, but let's break down your problems and fix them one by one.
1. Cropping While Preserving Original Quality
You’re right that FFmpeg won’t let you use -c:v copy alongside video filters (since filters require decoding the video first), but we can replicate your original MPEG-2 parameters as closely as possible to minimize quality loss. Your source is 720x576, 25fps, 4224kbps total bitrate—so we’ll match those settings explicitly:
Command for Cropping + Near-Lossless Quality
ffmpeg -i testinput.mpg -filter:v "crop=468:374:(720-468)/2:(576-374)/2" -c:v mpeg2video -b:v 4224k -r 25 -c:a copy test_cropped_highqual.mpg
- What this does:
- The
cropfilter uses calculated offsets(720-468)/2and(576-374)/2to target the center of your video (instead of the default top-left corner). - We force the video codec to
mpeg2video(matching your source) and set the bitrate to4224k—this keeps visual quality nearly identical to the original. -c:a copyskips re-encoding the audio, saving time and preserving audio quality.
- The
2. Fixing Flickering + Upscaling to 4K/HD
The flickering you’re seeing is almost certainly from your source being an interlaced MPEG-2 video (standard for old标清 broadcasts). Adjusting brightness/contrast won’t fix this—we need to deinterlace first. For upscaling, we’ll use a high-quality scaling algorithm to avoid pixelation on big screens.
Combined Command: Deinterlace + Crop + 4K Upscale
We’ll use yadif (a reliable deinterlacing filter) and lanczos (a high-quality scaling filter) for the best results. I recommend outputting to MP4 with H.264 (more efficient for 4K and better supported by modern TVs) instead of MPEG-2:
ffmpeg -i testinput.mpg -filter:v "yadif=1:1:0,crop=468:374:(720-468)/2:(576-374)/2,scale=3840:2160:flags=lanczos" -c:v libx264 -crf 18 -preset medium -c:a aac -b:a 192k test_4k_fixed.mp4
- Key details:
yadif=1:1:0: This deinterlaces the video and outputs progressive frames, eliminating that flicker on large screens.scale=3840:2160:flags=lanczos: Scales your cropped video to 4K using the Lanczos algorithm, which preserves sharpness better than basic scaling.libx264 -crf 18: H.264 encoding with a CRF (Constant Rate Factor) of 18 gives near-lossless quality while keeping file sizes manageable.preset medium: Balances encoding speed and compression efficiency—adjust toslowfor better compression (orfastif you need speed).- If you must output MPEG-2 (.mpg), replace the video codec part with
-c:v mpeg2video -b:v 20M(MPEG-2 is less efficient, so you’ll need a much higher bitrate to maintain 4K quality).
Quick Notes
- If you prefer HD (1080p) instead of 4K, change the
scalevalue to1920:1080. - Test the deinterlacing first with a short clip to confirm it fixes the flickering—you can tweak the
yadifparameters if needed (e.g.,yadif=0:0:0for simpler deinterlacing).
内容的提问来源于stack exchange,提问作者Sabha

