2

When executing the following code:

ffmpeg -i input.mov -c:v libx264 -preset veryslow -pix_fmt yuv420p -filter_complex "drawtext=fontfile=font.ttf:fontcolor=white@1:fontsize=h/6:x=(w-text_w)/2:y=(h-text_h)/2:text='Henk de Vries'[watermark];[0][watermark]blend=all_mode=difference:all_opacity=1" output.mp4

The output file has a green overlay. When using other blend modes, results vary with some modes displaying correct colors and others green and pink.

I know that the input file has yuv420p colorspacing. I think the blend filter only supports rgba modes but I am not sure.

How can I avoid the green overlay and get the original colors? (e.i. what the original input video looks like)

d1che
  • 23
  • 6

1 Answers1

3

You're blending a video with a nearly identical copy in difference mode, so most of the pixels will be zero-ed out. In YUV encoding, a 0-valued pixel in both the chroma channels represents green. The luma channel (Y) isn't a pure representation of luminance, and so a value of luma 0 along with both chroma as 0 results in a green colour being rendered.

Rotem's answer is on the right lines but no intermediate files are required. Simply convert to RGB space beforehand.

ffmpeg -i input.mov -c:v libx264 -preset veryslow -pix_fmt yuv420p -filter_complex "[0]format=gbrp,split=2[text][orig];[text]drawtext=fontfile=font.ttf:fontcolor=white@1:fontsize=h/6:x=(w-text_w)/2:y=(h-text_h)/2:text='Henk de Vries'[watermark];[orig][watermark]blend=all_mode=difference:all_opacity=1" output.mp4

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • This doesn't work for me. I still get the same output. What I am trying to accomplish is that the text I overlay is a negated version of the underlying video. Am I even using the right approach for this? – d1che Jun 11 '19 at 18:03
  • Tested and corrected; blend supports a limited set of RGB formats. – Gyan Jun 11 '19 at 18:17
  • Awesome, now I have the text which is the inverted result of the underlying video. I expanded your command to actually filter out the black with lumakey and overlay it on top of the original video: `ffmpeg -i input.mov -c:v libx264 -preset veryslow -pix_fmt yuv420p -filter_complex "[0]format=gbrp,split=3[text][blend][orig];[text]drawtext=fontfile=font.ttf:fontcolor=white@1:fontsize=h/6:x=(w-text_w)/2:y=(h-text_h)/2:text='Henk de Vries'[watermark];[blend][watermark]blend=all_mode=difference:all_opacity=1,lumakey=16:0:0[colortext];[orig][colortext]overlay" output.mp4` – d1che Jun 11 '19 at 19:37