eq, hue, and colorbalance, you can correct lighting issues, fix white balance errors, and improve overall visual appeal directly in the command line without external editing software.
Understanding FFmpeg Filter Chains
FFmpeg processes video through a filter graph, where each filter modifies the stream before passing it to the next. The syntax for applying filters involves the -vf (video filter) flag followed by a comma-separated list of filter expressions. This modular approach allows you to combine multiple adjustments into a single processing pass, which is more efficient than running separate commands for each adjustment.
For instance, if you need to brighten a dark video while simultaneously correcting its color temperature, you can chain these operations together. The general structure looks like this: ffmpeg -i input.mp4 -vf "filter1=opts1,filter2=opts2" output.mp4. Understanding how these filters interact is crucial because some operations depend on the pixel format or color space of the previous step.
Adjusting Brightness and Contrast
The most common enhancements involve correcting exposure issues. The eq filter is the primary tool for this, allowing precise control over brightness, contrast, gamma, and saturation. To increase brightness, you adjust the brightness parameter, which accepts values between -1.0 and 1.0. A value of 0.5 makes the video significantly brighter, while negative values darken it.
Contrast is controlled by the contrast parameter, with a default value of 1.0. Increasing this value above 1.0 makes the difference between light and dark areas more pronounced, while decreasing it below 1.0 flattens the image. For example, to make a video brighter and increase contrast slightly, you would use:
ffmpeg -i input.mp4 -vf "eq=brightness=0.2:contrast=1.2" output.mp4
This command applies a moderate boost to brightness and a slight increase in contrast. It is important to test small increments first, as large changes can clip highlights or crush shadows, resulting in loss of detail. You can also adjust the gamma parameter to affect mid-tones independently of the brightest and darkest parts of the image.
Correcting Color Balance and Hue
Color accuracy is often compromised by poor lighting conditions or camera sensor limitations. The hue filter allows you to shift the hue angle, adjust saturation, and modify brightness specifically for colors. The s parameter controls saturation, where values greater than 1.0 increase color intensity and values less than 1.0 desaturate the video. The b parameter adjusts the brightness of the colors independently of the luminance.
For more complex color corrections, the colorbalance filter provides sliders for red, green, and blue offsets. This is particularly useful for fixing white balance issues where an image appears too warm (yellow/red) or too cool (blue). For example, to reduce excessive redness in a video, you can apply a negative offset to the red channel:
ffmpeg -i input.mp4 -vf "colorbalance=rs=-0.1" output.mp4
Combining hue and colorbalance gives you granular control over the final look. If your video looks dull, increasing saturation with hue=s=1.5 can make it pop, but be careful not to oversaturate skin tones, which can look unnatural. For a deeper dive into handling specific video formats during enhancement, you might find converting videos for iPhone compatibility relevant, as codec choices can affect filter performance.
Sharpening and Noise Reduction
Beyond basic adjustments, enhancing sharpness and reducing noise are critical for professional-looking results. The unsharp filter is used to sharpen the video by adjusting the luma and chroma sharpness parameters. It works by comparing adjacent pixels and enhancing edges. However, excessive sharpening introduces artifacts, so it should be used sparingly.
Noise reduction can be achieved using the hqdn3d filter, which reduces spatial and temporal noise. While not strictly a color or brightness filter, cleaning up noise often improves the perceived quality of brightness and color adjustments. Applying noise reduction before other enhancements ensures that the algorithm does not mistake noise for detail.
Optimizing Performance During Enhancement
Applying multiple filters increases CPU load and processing time. To mitigate this, ensure you are using hardware acceleration if available. For NVIDIA GPUs, you can use the h264_nvenc encoder, though you may occasionally encounter errors like 'Failed to query nvenc max version' if the driver or library versions are mismatched. Checking your system's GPU support and updating drivers can resolve such issues.
Additionally, consider resizing the video before applying heavy filters if the source resolution is very high. Processing 4K footage requires significantly more resources than 1080p. If you are working on Linux Mint and dealing with large files, stabilizing the video might be a prerequisite step before enhancement, as described in stabilizing large videos with Linux Mint and ffmpeg.
Frequently Asked Questions
How do I preview filters before rendering?
You can use ffplay to preview filters in real-time without encoding the file. Use the command ffplay -vf "eq=brightness=0.2" input.mp4 to see the result instantly. This saves significant time compared to full render cycles.
Can I reset all filters to default settings?
To revert to original quality, simply omit the -vf flag or set filter parameters to their neutral values. For eq, this means setting brightness, contrast, and gamma to 0 or 1 respectively. No explicit "reset" command exists; you just don't apply the modification.
Why does my video look washed out after enhancement?
This usually happens when saturation is reduced too much or contrast is lowered excessively. Check your hue=s and eq=contrast values. Increasing saturation or contrast slightly often restores vibrancy. Ensure your output container supports the color profile you are using.
Do filters affect audio streams?
No, video filters specified with -vf only affect the video track. Audio remains untouched unless you explicitly use audio filters with -af. If you need to sync audio after processing, verify timestamps, especially if you dropped frames during filtering.
Is there a limit to how many filters I can chain?
There is no hard limit, but performance degrades with complexity. Chaining more than five heavy filters may cause stuttering or long encode times. It is best practice to group simple adjustments and test them individually before combining them into a final chain.