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.

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". I tried with 3 different pixel formats (yuv420p, yuv444p, rgb24) because I found this question on stackoverflow talking about that:

ffmpeg version 5.0.1-full_build-www.gyan.dev

Any idea will be welcome.

1 Answer 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:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.