<p>Change base video to full chroma sampling and try.</p>
<p><code>[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];</code></p>
<p>and</p>
<pre><code>[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)'
</code></pre>

CC BY-SA 4.0
2023-02-07T07:26:02.563Z
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
CC BY-SA 4.0
2023-02-07T07:35:58.680Z
You shouldn't add auto format to the last overlay. The format after the first overlay may be removed.
Gyan
CC BY-SA 4.0
2023-02-07T07:56:36.587Z
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
CC BY-SA 4.0
2023-02-07T07:02:38.480Z
2023-02-07T07:02:38.480Z
Gyan
<p>I am trying to add two overlays using ffmpeg as below:</p>
<pre><code>[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)' &quot; 
</code></pre>
<p>These two images [1:v] and [2:v] are below pngs:</p>
<p><a href="https://i.sstatic.net/kXIua.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kXIua.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/BFXBf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BFXBf.png" alt="enter image description here" /></a></p>
<p>The first png is 99px wide and I want to place it on x=21</p>
<p>The second png I want to place right behind the first one x=21+99=120</p>
<p>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.</p>
<p><a href="https://i.sstatic.net/IinpP.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/IinpP.png" alt="enter image description here" /></a></p>
<p>How can I ensure it is pixel perfect and there is no gap?</p>
<p>Also I noticed that if the image is 98px and I use:</p>
<pre><code>[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)' &quot; 
</code></pre>
<p>then suprisingly it is fine, same for 100px wide and next images x=121</p>
<p>The whole command to give more context (remove newlines to execute):</p>
<pre><code>.\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
</code></pre>
<p>@Gyan your answer helped for the mentioned simple scenario but if I change the order:</p>
<pre><code>[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)' &quot; 
</code></pre>
<p>then I get the 1px gap again. Any suggestions?</p>

CC BY-SA 4.0
2023-02-06T04:25:57.270Z
Looks to be related to chroma subsampling of the base video. Share full command.
Gyan
CC BY-SA 4.0
2023-02-06T07:30:27.687Z
updated the question with the full command
RadekJ
<ffmpeg>
ffmpeg - inacurate overlay position
RadekJ
# ffmpeg - inacurate overlay position

(Asked by: username_0 on 2023-02-05)

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:


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.

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

@username_1 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?

**Tags:** ffmpeg

> **Comments:**
> **username_1**: Looks to be related to chroma subsampling of the base video. Share full command.  
> **username_0**: updated the question with the full command  

---

## 1 answers

### Answer by username_1 on 2023-02-07. Score: 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)'

> **Comments:**
> **username_0**: 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?  
> **username_1**: You shouldn't add auto format to the last overlay. The format after the first overlay may be removed.  
> **username_0**: 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  

---

