Answers.Body: <p>Solution: using <code>-pix_fmt rgb24</code> and adding <code>-c:v libx264rgb</code> to all commands fixes it:</p>
  <pre><code>ffmpeg -hide_banner -y -t 2 -f lavfi -i color=c=blue:s=160x120 -tune stillimage -c:v libx264rgb -pix_fmt rgb24 00_empty.mp4
  ffmpeg -hide_banner -y -i 00_empty.mp4 -vf &quot;drawtext=text=string1:y=h/2:x=w-t*w/2:fontcolor=white:fontsize=60&quot; -c:v libx264rgb -pix_fmt rgb24 01_text.mp4
  ffmpeg -hide_banner -y -t 2 -f lavfi -i color=c=gray:s=160x120 -tune stillimage -c:v libx264rgb -pix_fmt rgb24 02_gray.mp4
  ffmpeg -hide_banner -y -i 01_text.mp4 -i 02_gray.mp4 -i 02_gray.mp4 -filter_complex &quot;[0][1][2]displace=edge=mirror&quot; -c:v libx264rgb -pix_fmt rgb24 03_displaced_text.mp4
  </code></pre>
  <p>Thanks to <a href="https://forum.videohelp.com/threads/406269-%5BSOLVED%5D-Ghost-image-issues-with-ffmpeg-filter_complex-displace#post2661776" rel="nofollow noreferrer">poisondeathray's answer in a post at forum.videohelp.com</a>:</p>
  <blockquote>
  <p>the real reason is the 8it RGB to YUV gray conversion for 02_gray.mp4 becomes YUV 126,128,128 (loss of accuracy from the 8bit conversion)
  <a href="https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/vf_displace.c" rel="nofollow noreferrer">https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/vf_displace.c</a><br />
  If you supply a true gray YUV 128,128,128 video it works ok too</p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-05T14:15:17.667Z
Answers.LastActivityDate: 2022-07-05T14:15:17.667Z
Answers.UserDisplayName: raul.vila
Body: <p>I've (almost) been able to apply a displacement based on 2 animated gaussian noise videos, but I'm having issues with a ghost image. <a href="https://i.sstatic.net/EDbrB.png" rel="nofollow noreferrer">A picture is worth a thousand words</a>.</p>
  <p>Here you have a script to replicate the issue:</p>
  <pre><code>ffmpeg -y -t 2 -f lavfi -i color=c=blue:s=160x120 -c:v libx264 -tune stillimage -pix_fmt rgb24 00_empty.mp4
  ffmpeg -y -i 00_empty.mp4 -vf &quot;drawtext=text=string1:y=h/2:x=w-t*w/2:fontcolor=white:fontsize=60&quot; 01_text.mp4
  ffmpeg -y -t 2 -f lavfi -i color=c=gray:s=160x120 -c:v libx264 -tune stillimage -pix_fmt rgb24 02_gray.mp4
  ffmpeg -y -i 01_text.mp4 -i 02_gray.mp4 -i 02_gray.mp4 -filter_complex &quot;[0][1][2]displace=edge=mirror&quot; 03_displaced_text.mp4
  </code></pre>
  <p>It creates a test video with a scrolling text and a gray dummy video. Then it applies a displacement based on the gray video. If I understand correctly, because the gray video is 100% gray, it should leave the video unchanged (or maybe displace everything by a fixed ammount of pixels), but <a href="https://i.sstatic.net/ODRVl.png" rel="nofollow noreferrer">it creates a &quot;shadow&quot;</a>. I tried with 3 different pixel formats (yuv420p, yuv444p, rgb24) because I found this question on stackoverflow talking about that:</p>
  <ul>
  <li><a href="https://stackoverflow.com/a/43820170">Why are Cb and Cr planes displaced differently from lum by the displace complex filter in ffmpeg?</a></li>
  </ul>
  <p>ffmpeg version 5.0.1-full_build-www.gyan.dev</p>
  <p>Any idea will be welcome.<br />
  Thanks!</p>
  
Tags: <ffmpeg>
Title: Ghost image issues with ffmpeg -filter_complex displace
UserDisplayName: raul.vila
ThreadText: # Ghost image issues with ffmpeg -filter_complex displace
  
  (Asked by: username_0 on 2022-07-05)
  
  I've (almost) been able to apply a displacement based on 2 animated gaussian noise videos, but I'm having issues with a ghost image. [A picture is worth a thousand words](https://i.sstatic.net/EDbrB.png).
  
  Here you have a script to replicate the issue:
  
  ```
  ffmpeg -y -t 2 -f lavfi -i color=c=blue:s=160x120 -c:v libx264 -tune stillimage -pix_fmt rgb24 00_empty.mp4
  ffmpeg -y -i 00_empty.mp4 -vf "drawtext=text=string1:y=h/2:x=w-t*w/2:fontcolor=white:fontsize=60" 01_text.mp4
  ffmpeg -y -t 2 -f lavfi -i color=c=gray:s=160x120 -c:v libx264 -tune stillimage -pix_fmt rgb24 02_gray.mp4
  ffmpeg -y -i 01_text.mp4 -i 02_gray.mp4 -i 02_gray.mp4 -filter_complex "[0][1][2]displace=edge=mirror" 03_displaced_text.mp4
  
  ```
  
  It creates a test video with a scrolling text and a gray dummy video. Then it applies a displacement based on the gray video. If I understand correctly, because the gray video is 100% gray, it should leave the video unchanged (or maybe displace everything by a fixed ammount of pixels), but [it creates a "shadow"](https://i.sstatic.net/ODRVl.png). I tried with 3 different pixel formats (yuv420p, yuv444p, rgb24) because I found this question on stackoverflow talking about that:
  
  * [Why are Cb and Cr planes displaced differently from lum by the displace complex filter in ffmpeg?](https://stackoverflow.com/a/43820170)
  
  ffmpeg version 5.0.1-full\_build-www.gyan.dev
  
  Any idea will be welcome.  
  Thanks!
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-07-05. Score: 1
  
  Solution: using `-pix_fmt rgb24` and adding `-c:v libx264rgb` to all commands fixes it:
  
  ```
  ffmpeg -hide_banner -y -t 2 -f lavfi -i color=c=blue:s=160x120 -tune stillimage -c:v libx264rgb -pix_fmt rgb24 00_empty.mp4
  ffmpeg -hide_banner -y -i 00_empty.mp4 -vf "drawtext=text=string1:y=h/2:x=w-t*w/2:fontcolor=white:fontsize=60" -c:v libx264rgb -pix_fmt rgb24 01_text.mp4
  ffmpeg -hide_banner -y -t 2 -f lavfi -i color=c=gray:s=160x120 -tune stillimage -c:v libx264rgb -pix_fmt rgb24 02_gray.mp4
  ffmpeg -hide_banner -y -i 01_text.mp4 -i 02_gray.mp4 -i 02_gray.mp4 -filter_complex "[0][1][2]displace=edge=mirror" -c:v libx264rgb -pix_fmt rgb24 03_displaced_text.mp4
  
  ```
  
  Thanks to [poisondeathray's answer in a post at forum.videohelp.com](https://forum.videohelp.com/threads/406269-%5BSOLVED%5D-Ghost-image-issues-with-ffmpeg-filter_complex-displace#post2661776):
  
  > the real reason is the 8it RGB to YUV gray conversion for 02\_gray.mp4 becomes YUV 126,128,128 (loss of accuracy from the 8bit conversion)
  > <https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/vf_displace.c>  
  > If you supply a true gray YUV 128,128,128 video it works ok too
  
  
  ---
  
  