<p>Since your total duration is 3 seconds, there is no frame <em>at</em> 3 seconds. The last frame is at 3 seconds - <em>1/framerate</em> seconds.</p>
<p>The default framerate of image inputs is 25, so you should interpolate to the final position at 2.96 seconds.</p>
<p>i.e.</p>
<p><code>if(between(t\\,2.2\\,3.0)\\, lerp(200.0\\,0.0\\,round((t-2.2)/0.76*100)/100))</code></p>

CC BY-SA 4.0
2023-11-02T18:41:09.713Z
Thank you, that's working. Can you tell me why "The last frame is at 3 seconds - 1/framerate seconds"? (Is this a FFmpeg limitation?)
antoox
CC BY-SA 4.0
2023-11-03T03:47:09.473Z
No. Each frame has a presentation time and a duration. For 25 fps videos, duration is 1/25 = 40ms. If there was a frame at 3s, then total video duration would be 3s40ms.
Gyan
CC BY-SA 4.0
2023-11-03T08:50:46.023Z
oh that makes perfect sense! thank you
antoox
CC BY-SA 4.0
2023-11-02T04:01:28.597Z
2023-11-02T04:01:28.597Z
Gyan
<p>I am trying to move a shape (an image) over a background image to each corner. <a href="https://local-banners.s3.eu-west-1.amazonaws.com/video/video-with-shape-overlay-issue.mp4" rel="nofollow noreferrer">Here is the video example</a> I generated with ffmpeg.</p>
<p>As you can see from the example, at the end of the video the shape is not positioned on the top right corner as it should be:</p>
<p><a href="https://i.sstatic.net/C7INV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/C7INV.png" alt="last frame shape positionning issue" /></a></p>
<p>Here is the ffmpeg command I use:</p>
<pre><code>ffmpeg -i background.jpeg -loop 1 -i logo.png -filter_complex &quot;[0]scale=300:250[s0];[1]format=gbrap[s4];[s0][s4]overlay=x=if(between(t\\,0.0\\,0.8)\\,lerp(0.0\\,240.0\\,round((t-0.0)/0.8*100)/100)\\,if(between(t\\,0.8\\,2.2)\\,lerp(240.0\\,0.0\\,round((t-0.8)/1.4*100)/100)\\,if(between(t\\,2.2\\,3.0)\\,lerp(0.0\\,240.0\\,round((t-2.2)/0.8*100)/100)))):y=if(between(t\\,0.0\\,0.8)\\,lerp(0.0\\,200.0\\,round((t-0.0)/0.8*100)/100)\\,if(between(t\\,0.8\\,2.2)\\,lerp(200.0\\,200.0\\,round((t-0.8)/1.4*100)/100)\\,if(between(t\\,2.2\\,3.0)\\,lerp(200.0\\,0.0\\,round((t-2.2)/0.8*100)/100))))[s5]&quot; -map &quot;[s5]&quot; -c:v libx264 -crf 0 -pix_fmt yuv420p -t 3.0 video.mp4 
</code></pre>
<ul>
<li>video is 300x250</li>
<li>logo.png is the blue shape (width=60px, height=50px)</li>
<li>the coordinates are set as follow: 0s: x=0,y=0 / 0.8s: x=240px,y=200px / 2.2s: x=0,y=200px / 3s: x=240px,y=0</li>
</ul>
<p>I am using <code>lerp</code> to retrieve the right position depending on the current time <code>t</code>.
It seems like the last frames are not played.</p>
<p>I tried to:</p>
<ul>
<li>set a framerate (30 &amp; 100) to the logo.png input,</li>
<li>round the value given by lerp,</li>
<li>use setpts to define a number of frames.</li>
</ul>
<p>But I do not understand the problem I am facing, could you help me?</p>
<p><strong>UPDATE 1</strong>: If I extend the video duration to 4s, the shape position at 3s is the right one</p>
<p><strong>UPDATE 2</strong>: I added <code>-framerate 100</code> as option the logo.png input and <code>fps=24</code> just after the <em>scale</em> filter. The problem is still present. I extracted every frame as png (as expected there are 72 frames) &amp; 17 were generated between 2.2s &amp; 3s.</p>
<p><strong>UPDATE 3</strong>: The problem is resolved by settings a <code>fps</code> of <em>100</em>. However the generated video file is too big. Is there any other way to get it to work at 24fps?</p>

<ffmpeg>
ffmpeg - overlay position at the end of the video is wrong
antoox
# ffmpeg - overlay position at the end of the video is wrong

(Asked by: username_0 on 2023-11-01)

I am trying to move a shape (an image) over a background image to each corner. Here is the video example I generated with ffmpeg.
As you can see from the example, at the end of the video the shape is not positioned on the top right corner as it should be:

Here is the ffmpeg command I use:
ffmpeg -i background.jpeg -loop 1 -i logo.png -filter_complex "[0]scale=300:250[s0];[1]format=gbrap[s4];[s0][s4]overlay=x=if(between(t\\,0.0\\,0.8)\\,lerp(0.0\\,240.0\\,round((t-0.0)/0.8*100)/100)\\,if(between(t\\,0.8\\,2.2)\\,lerp(240.0\\,0.0\\,round((t-0.8)/1.4*100)/100)\\,if(between(t\\,2.2\\,3.0)\\,lerp(0.0\\,240.0\\,round((t-2.2)/0.8*100)/100)))):y=if(between(t\\,0.0\\,0.8)\\,lerp(0.0\\,200.0\\,round((t-0.0)/0.8*100)/100)\\,if(between(t\\,0.8\\,2.2)\\,lerp(200.0\\,200.0\\,round((t-0.8)/1.4*100)/100)\\,if(between(t\\,2.2\\,3.0)\\,lerp(200.0\\,0.0\\,round((t-2.2)/0.8*100)/100))))[s5]" -map "[s5]" -c:v libx264 -crf 0 -pix_fmt yuv420p -t 3.0 video.mp4 


video is 300x250
logo.png is the blue shape (width=60px, height=50px)
the coordinates are set as follow: 0s: x=0,y=0 / 0.8s: x=240px,y=200px / 2.2s: x=0,y=200px / 3s: x=240px,y=0

I am using lerp to retrieve the right position depending on the current time t.
It seems like the last frames are not played.
I tried to:

set a framerate (30 & 100) to the logo.png input,
round the value given by lerp,
use setpts to define a number of frames.

But I do not understand the problem I am facing, could you help me?
UPDATE 1: If I extend the video duration to 4s, the shape position at 3s is the right one
UPDATE 2: I added -framerate 100 as option the logo.png input and fps=24 just after the scale filter. The problem is still present. I extracted every frame as png (as expected there are 72 frames) & 17 were generated between 2.2s & 3s.
UPDATE 3: The problem is resolved by settings a fps of 100. However the generated video file is too big. Is there any other way to get it to work at 24fps?

**Tags:** ffmpeg


---

## 1 answers

### Answer by username_1 on 2023-11-02. Score: 0 | Accepted answer

Since your total duration is 3 seconds, there is no frame *at* 3 seconds. The last frame is at 3 seconds - *1/framerate* seconds.

The default framerate of image inputs is 25, so you should interpolate to the final position at 2.96 seconds.

i.e.

`if(between(t\\,2.2\\,3.0)\\, lerp(200.0\\,0.0\\,round((t-2.2)/0.76*100)/100))`

> **Comments:**
> **username_0**: Thank you, that's working. Can you tell me why "The last frame is at 3 seconds - 1/framerate seconds"? (Is this a FFmpeg limitation?)  
> **username_1**: No. Each frame has a presentation time and a duration. For 25 fps videos, duration is 1/25 = 40ms. If there was a frame at 3s, then total video duration would be 3s40ms.  
> **username_0**: oh that makes perfect sense! thank you  

---

