Hi, noob here
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:
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: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 "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
- Why are Cb and Cr planes displaced differently from lum by the displace complex filter in ffmpeg?
Windows 10
ffmpeg version 5.0.1-full_build-www.gyan.dev
EDIT: Thanks to @poisondeathray for the solution, using -pix_fmt rgb24 and adding -c:v libx264rgb fixes it. This works:
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 "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
Any idea will be welcome.
Thanks!
+ Reply to Thread
Results 1 to 7 of 7
-
Last edited by Crul; 5th Jul 2022 at 09:11. Reason: Solution added
-
you tried rgb24, but probably didn't specify libx264rgb (or another RGB format), so it converts to yuv 4:2:0 , this causes subsampled chroma planes (1/2 width, 1/2 height)
Code:ffmpeg -y -t 2 -f lavfi -i color=c=blue:s=160x120 -c:v libx264rgb -tune stillimage -pix_fmt rgb24 04_empty.mp4 ffmpeg -y -i 00_empty.mp4 -vf "drawtext=text=string1:y=h/2:x=w-t*w/2:fontcolor=white:fontsize=60" -c:v libx264rgb 05_text.mp4 ffmpeg -y -t 2 -f lavfi -i color=c=gray:s=160x120 -c:v libx264rgb -tune stillimage -pix_fmt rgb24 06_gray.mp4 ffmpeg -y -i 05_text.mp4 -i 06_gray.mp4 -i 06_gray.mp4 -filter_complex "[0][1][2]displace=edge=mirror" -c:v libx264rgb 07_displaced_text.mp4
-
Actually, looking at the code, 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 -
you tried rgb24, but probably didn't specify libx264rgb (or another RGB format), so it converts to yuv 4:2:0
Anyway, with you444p it should work, but....
Actually, looking at the code, the real reason is the 8it RGB to YUV gray conversion for 02_gray.mp4 becomes YUV 126,128,128
Thank you very much! -
Confirmed, this works:
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 "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
-
And that's the actually the expected YUV value (Y=126) for gray RGB (RGB 128,128,128) to YUV using a (standard) limited range conversion. If you specified full range, you would get YUV 128,128,128 and it would work too in YUV
Another way would be to use -vf lutyuv to force the y value to 128. I don't think ffmpeg has a YUV color generator where you can specify Y,U,V values directly -
All these options are confusing, but I'm learning... slowly.
Thanks for the info.
Similar Threads
-
Using ffmpeg and image-based subtitle tracks
By the_steve_randolph in forum Newbie / General discussionsReplies: 23Last Post: 13th Jul 2021, 03:06 -
Incorporate Avisynth Scripts into FFMPEG issues
By rgia in forum Newbie / General discussionsReplies: 43Last Post: 1st Jun 2020, 09:21 -
Batch produce Image Videos with FFMpeg
By daigo99 in forum EditingReplies: 3Last Post: 16th Jan 2020, 17:24 -
Image issues Capturing VHS tapes, can't find the cause
By digitalize_it in forum Capturing and VCRReplies: 4Last Post: 1st Dec 2018, 11:49 -
FFmpeg croma ghost problem
By marcorocchini in forum Newbie / General discussionsReplies: 7Last Post: 11th Jul 2017, 17:27