I have concatenated 9 pictures that all have exactly same dimension, 320x562 each. They are placed in a single horizontal row, which results in a file that is 2880x562.

Now I want to make a blank screen of 320x562 as a background, and move this big flat file from right to left as an overlay to generate the sliding effect.

This is the command I used after a bit of experimenting:

ffmpeg -loop 1 -i result.jpg -filter_complex "nullsrc=size=320x562 [background];[0:v] setpts=PTS-STARTPTS [catalog]; [background][catalog] overlay=shortest=1:x='if(gte(t,4)*lte(x, 2880), -(t-4)*165)'" -t 24 -y out.mp4

It puts the overlay image with the same position with background as starting point.

Although it looks to be doing kind of what I wanted to do, I'm having trouble understanding the expressions used for calculating the overlay's X value.

  • I wanted to make the overlay start floating where t>4 and x<=2560, so even though t increases, the slide should stop where the overlay's top-right position meets with the background's top-right position. Timing seems to be working but position restriction does not. How can I reference the current X?

  • Having an error about -(t-4)*144 part of the expression. Total duration is given to be 24. The overlay starts sliding after the 4th second. So, the video should show sliding of 9 * 320 pixels (2880) over 20 seconds. But it is giving 144 as result of 2880 / 20 makes the overlay exhausted after around ~22 seconds, and some garbage pixels appear after that. What is the best way to make the overlay end exactly when it comes to end?

1 Answer 1


Since you are sliding the catalog image from right to left and wish to stop when the 9th image is coincident upon the background, you need the overlay's x to be -8*320 = -2560. But since you're stopping the overlay when that happens, you just need to calculate the speed, which is 2560/20 = 128.


ffmpeg -loop 1 -t 24 -i result.jpg
       -y out.mp4

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .