0

I am trying to add two overlays using ffmpeg as below:

[v0][1:v] overlay=21:24:enable='between(t,0.000, 1.135)' [v1];
[v1][2:v] overlay=120:24:enable='between(t,0.000, 1.135)' " 

These two images [1:v] and [2:v] are below pngs:

enter image description here enter image description here

The first png is 99px wide and I want to place it on x=21

The second png I want to place right behind the first one x=21+99=120

But I am getting the output as below: It seems that there is 1px gap between them and I have no idea where is it coming from.

enter image description here

How can I ensure it is pixel perfect and there is no gap?

Also I noticed that if the image is 98px and I use:

[v0][1:v] overlay=21:24:enable='between(t,0.000, 1.135)' [v1];
[v1][2:v] overlay=119:24:enable='between(t,0.000, 1.135)' " 

then suprisingly it is fine, same for 100px wide and next images x=121

The whole command to give more context (remove newlines to execute):

.\bin\ffmpeg.exe -ss 0 -to 5.681 
-i C:\Users\Radoslaw\Videos\ttt.mp4 
-i .\tempAssets\player1.png 
-i .\tempAssets\serving.png 
-filter_complex 
[0:v] select='between(t,1.247,2.550)+between(t,4.181,5.681)', setpts='PTS-STARTPTS-((gt(T,2.550)*1.630))/TB' [v0]; 
[0:a] aselect='between(t,1.247,2.550)+between(t,4.181,5.681)', asetpts='PTS-STARTPTS-((gt(T,2.550)*1.630))/TB'; 
[v0][1:v] overlay=21:21:enable='between(t,0.000, 2.803)' [v1];
[v1][2:v] overlay=120:21:enable='between(t,0.000, 2.803)' 
Untitled.mp4

@Gyan your answer helped for the mentioned simple scenario but if I change the order:

[v0][2:v] overlay=120:24:enable='between(t,0.000, 1.135)':format=auto,format=yuv444p [v1];
[v1][1:v] overlay=21:24:enable='between(t,0.000, 1.135)' " 

then I get the 1px gap again. Any suggestions?

2
  • 1
    Looks to be related to chroma subsampling of the base video. Share full command.
    – Gyan
    Commented Feb 6, 2023 at 4:25
  • updated the question with the full command
    – RadekJ
    Commented Feb 6, 2023 at 7:30

1 Answer 1

2

Change base video to full chroma sampling and try.

[0:v] select='between(t,1.247,2.550)+between(t,4.181,5.681)', setpts='PTS-STARTPTS-((gt(T,2.550)*1.630))/TB',format=yuv444p[v0];

and

[v0][1:v] overlay=21:21:enable='between(t,0.000, 2.803)':format=auto,format=yuv444p [v1];
[v1][2:v] overlay=120:21:enable='between(t,0.000, 2.803)'
3
  • Yes, that helped. Thanks a lot! Also after experimenting - turns out that it is enough to add :format=auto without specyfing the chroma sampling. Do you think it is enough to add :format=auto to each png overlay or should I add that chroma too?
    – RadekJ
    Commented Feb 7, 2023 at 7:26
  • You shouldn't add auto format to the last overlay. The format after the first overlay may be removed.
    – Gyan
    Commented Feb 7, 2023 at 7:35
  • hmm but if i change the order so [2:v] goes first and then [1:v] and put :format=auto,format=yuv444p on the first one (2:v) then the problem remains as before
    – RadekJ
    Commented Feb 7, 2023 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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