Search code examples
videofilterffmpegcolorsvideo-processing

FFmpeg apply color filter on video


I'm new to FFmpeg and I want to apply a color filter to my video. I searched a lot and according to what I found here This command seems to be applying color from the RGBA matrix. ex :

colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131

But running with the full command :

" -i $videoPath
-i $waterMarkPath
-filter_complex [1:v]scale=iw*$scale:-1[v1],[0:v][v1]overlay=0:0[mark],
colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131
-pix_fmt yuv420p
-map [mark]
-preset ultrafast  -crf 23
-y $outputPath " 

I have this error :

Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_colorchannelmixer_2

ERROR ON EXPORT VIDEO (CODE 1)
  • What am I doing wrong here and why?
  • Is it the right way to apply color filters on video? There are another ways to do it?
  • How can I apply the filter only on the video or only on the watermark?

Thanks for any help


Solution

  • What am I doing wrong here and why?

    Your filter labels are messed up. You're asking ffmpeg to output [mark] to the video file. But that leaves the output from colorchannelmixer orphaned. All filter outputs must be consumed by other filters or sent to an output file.

    You can do this instead:

    " -i $videoPath
    -i $waterMarkPath
    -filter_complex [1:v]scale=iw*$scale:-1[v1];[0:v][v1]overlay=0:0,colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131[mark]
    -pix_fmt yuv420p
    -map [mark]
    -preset ultrafast -crf 23
    -y $outputPath " 
    

    Or rely on the default stream selection behavior:

    " -i $videoPath
    -i $waterMarkPath
    -filter_complex [1:v]scale=iw*$scale:-1[v1];[0:v][v1]overlay=0:0,colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131
    -pix_fmt yuv420p
    -preset ultrafast -crf 23
    -y $outputPath " 
    

    See FFmpeg Filtering Intro for an overview of how to make a filtergraph.

    Is it the right way to apply color filters on video?

    Yes, if you want to use colorchannelmixer.

    There are another ways to do it?

    Yes, there are many filters related to color.

    How can I apply the filter only on the video or only on the watermark?

    It depends on the order of the filters and which inputs you provide to the filters.

    colorchannelmixer on main video only:

    " -i $videoPath
    -i $waterMarkPath
    -filter_complex [0:v]colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131[main];[1:v]scale=iw*$scale:-1[v1];[main][v1]overlay=0:0
    -pix_fmt yuv420p
    -preset ultrafast -crf 23
    -y $outputPath "
    

    colorchannelmixer on watermark only:

    " -i $videoPath
    -i $waterMarkPath
    -filter_complex [1:v]scale=iw*$scale:-1,colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131[v1],[0:v][v1]overlay=0:0
    -pix_fmt yuv420p
    -preset ultrafast -crf 23
    -y $outputPath "