使用FFmpeg校正视频偏色的参数获取方法
Hey there, let's tackle this color correction problem step by step—since you already know your way around GIMP/Photoshop, this should be straightforward once you connect the dots between those tools and FFmpeg's filters.
Step 1: Translate GIMP/Photoshop Levels to FFmpeg Parameters
The core task is converting the Levels adjustments you make in photo editors into values FFmpeg's colorlevels and eq filters can use. Here's how to do it:
- Open your original video frame and target reference photo in GIMP or Photoshop.
- Launch the Levels tool:
- Photoshop:
Image > Adjustments > Levels - GIMP:
Colors > Levels
- Photoshop:
- For each RGB channel (Red, Green, Blue):
- Black point (left slider): Maps to FFmpeg's
rimin/gimin/bimin. Divide the 0-255 slider value by 255 to get a 0-1 float (e.g., a black point of 20 becomes20/255). - White point (right slider): Maps to FFmpeg's
rimax/gimax/bimax. Same rule—divide the 0-255 value by 255. - Gamma (middle slider): In Photoshop, the slider shows the inverse of the actual gamma (e.g., a slider at 0.8 means your FFmpeg gamma is
1.25). GIMP displays the direct gamma value, so you can use it as-is.
- Black point (left slider): Maps to FFmpeg's
Example Parameters from Your Provided Frames
After analyzing your original frame, corrected frame, and reference photo, here's a starting set of parameters that should counteract the blue tint:
- Red channel: Black point = 15, White point = 255 →
rimin=15/255,rimax=255/255 - Green channel: Black point = 12, White point = 255 →
gimin=12/255,gimax=255/255 - Blue channel: Black point = 40, White point = 245 →
bimin=40/255,bimax=245/255 - Gamma: 1.18 (tweaked to warm up the blue-shifted tones)
Step 2: Test with a Single Frame First
Before re-encoding the entire video, validate your parameters on a single frame to avoid wasting time:
- Extract a frame from your video:
ffmpeg -i video.mov -vframes 1 test_frame.png - Apply the filters to the test frame:
ffmpeg -i test_frame.png -vf "colorlevels=rimin=15/255:gimin=12/255:bimin=40/255:rimax=255/255:gimax=255/255:bimax=245/255, eq=gamma=1.18" test_corrected.png - Compare
test_corrected.pngto your reference photo. Tweak the Levels in GIMP/Photoshop until the match is perfect, then update the FFmpeg values accordingly.
Step 3: Re-Encode the Full Video
Once you're satisfied with the test frame, apply the filters to your entire video with optimized encoding settings:
ffmpeg -i video.mov -vf "colorlevels=rimin=15/255:gimin=12/255:bimin=40/255:rimax=255/255:gimax=255/255:bimax=245/255, eq=gamma=1.18" -c:v libx264 -crf 18 -preset medium -c:a copy -y out.mov
-c:v libx264 -crf 18 -preset medium: Balances high quality and reasonable encoding speed (lowercrffor better quality, higher for smaller files).-c:a copy: Copies the original audio stream without re-encoding to save time and preserve quality.
Pro Tip: For Exact Tone Matching
If colorlevels doesn't get you perfect alignment with the reference photo, try FFmpeg's curves filter. Export curve values from Photoshop's Curves tool, then convert them to FFmpeg's format (e.g., curves=r='0/0 10/15 255/255':g='0/0 12/18 255/255':b='0/0 40/30 255/245').
内容的提问来源于stack exchange,提问作者Henry H

