Answers.Body: <p>The default pixel format for <code>testsrc</code> filter is <code>rgb24</code>, which gets converted to <code>yuv444p</code> for encoding to H264. The default pixel format for color is <code>yuv420p</code>, which is kept as-is.</p>
  
  <p>The blend filter requires both inputs to have the same pixel format, and will, where possible, convert the pixel format of the 2nd input to match that of the first. When <code>red.mp4</code> is the first input, the frames from <code>pattern.mp4</code> are converted to <code>yuv420p</code>. In <code>yuv420p</code>. the chroma planes are half the width (and height) of the luma plane, so in this case, 640x360.</p>
  
  <p>Your blend expression, which is applied to all planes is, <code>if(lt(X\,600)\,A\,B)</code>. For the chroma planes of a 1280x720 frame in yuv420p format, <code>X = 600</code> is at ~6% from the right edge, hence the result you're seeing. You can modify the expr to <code>if(lt(X\,SW*600)\,A\,B)</code> to get the expected result. <code>SW</code> is the scale factor for the processed plane and represents the ratio of the current plane to the luma plane.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-08T16:28:58.080Z
Answers.LastActivityDate: 2019-03-08T16:28:58.080Z
Answers.UserDisplayName: Gyan
Body: <p>I generate two test videos (the first a test pattern, the second solid red) with </p>
  
  <pre><code>ffmpeg -f lavfi -i testsrc=duration=5:size=1280x720:rate=30 pattern.mp4
  ffmpeg -f lavfi -i color=c=red@0.2:duration=5:size=1280x720:r=10 red.mp4
  </code></pre>
  
  <p>If I blend these together with the solid red as background, I see the expected output: left half test pattern, right half solid red. </p>
  
  <pre><code>ffmpeg -i pattern.mp4 -i red.mp4 -filter_complex "[0:v][1:v]blend=all_expr=if(lt(X\,600)\,A\,B)" output.mp4 
  </code></pre>
  
  <p>However, when blending in the opposite order, the output is not as expected, with the solid red "bleeding" over the entire image.</p>
  
  <pre><code>ffmpeg -i red.mp4 -i pattern.mp4 -filter_complex "[0:v][1:v]blend=all_expr=if(lt(X\,600)\,A\,B)" output.mp4
  </code></pre>
  
  <p>Why is the "A" video leaking into the "B" zone?</p>
  
Tags: <ffmpeg><filter>
Title: Color leakage effects with ffmpeg blend=all_expr
UserDisplayName: Eric Marsden
ThreadText: # Color leakage effects with ffmpeg blend=all_expr
  
  (Asked by: username_0 on 2019-03-08)
  
  I generate two test videos (the first a test pattern, the second solid red) with
  
  ```
  ffmpeg -f lavfi -i testsrc=duration=5:size=1280x720:rate=30 pattern.mp4
  ffmpeg -f lavfi -i color=c=red@0.2:duration=5:size=1280x720:r=10 red.mp4
  
  ```
  
  If I blend these together with the solid red as background, I see the expected output: left half test pattern, right half solid red.
  
  ```
  ffmpeg -i pattern.mp4 -i red.mp4 -filter_complex "[0:v][1:v]blend=all_expr=if(lt(X\,600)\,A\,B)" output.mp4 
  
  ```
  
  However, when blending in the opposite order, the output is not as expected, with the solid red "bleeding" over the entire image.
  
  ```
  ffmpeg -i red.mp4 -i pattern.mp4 -filter_complex "[0:v][1:v]blend=all_expr=if(lt(X\,600)\,A\,B)" output.mp4
  
  ```
  
  Why is the "A" video leaking into the "B" zone?
  
  **Tags:** ffmpeg, filter
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-08. Score: 4 | Accepted answer
  
  The default pixel format for `testsrc` filter is `rgb24`, which gets converted to `yuv444p` for encoding to H264. The default pixel format for color is `yuv420p`, which is kept as-is.
  
  The blend filter requires both inputs to have the same pixel format, and will, where possible, convert the pixel format of the 2nd input to match that of the first. When `red.mp4` is the first input, the frames from `pattern.mp4` are converted to `yuv420p`. In `yuv420p`. the chroma planes are half the width (and height) of the luma plane, so in this case, 640x360.
  
  Your blend expression, which is applied to all planes is, `if(lt(X\,600)\,A\,B)`. For the chroma planes of a 1280x720 frame in yuv420p format, `X = 600` is at ~6% from the right edge, hence the result you're seeing. You can modify the expr to `if(lt(X\,SW*600)\,A\,B)` to get the expected result. `SW` is the scale factor for the processed plane and represents the ratio of the current plane to the luma plane.
  
  
  ---
  
  