Celeb Glow
news | March 12, 2026

How to crop moving an (overlayed) image across a video in ffmpeg?

I want to crop moving an image. The crop must move with the time to make a translation effect. I tried with this following command:

 ffmpeg -y -i video.mp4 -filter_complex "movie=filename=image.jpg:loop=1[pip:v];[pip:v]trim=start=0.0:duration=5,setpts=PTS-STARTPTS+0/TB[pip:v];[pip:v]scale='if(gte(ih,iw),384,-1):if(gte(ih,iw),-1,216)',crop=384:216:exact=1[pip:v];[pip:v]scale=iw*(1.3):ih*(1.3)[pip:v];[pip:v]crop=384:216:-(in_w-out_w)*(t-(5))/5:0[pip:v];[0:v][pip:v]overlay=main_w-overlay_w-33.333332:main_h-overlay_h-33.333332:enable='between(t,0,0+5)'[outv]" -map [outv] -preset ultrafast -r 29.97 output.mp4

But the crop remains fixed. I think the crop timestamp doesn't work because it's an image. I can't find the solution, can you help me?

enter image description here

1 Answer

Instead of using the movie filter, you may add image.jpg as second input, and add -r for setting the framerate:

ffmpeg -y -i video.mp4 -r 29.97 -loop 1 -i image.jpg...

It defines the framerate (repeat rate) of image.jpg, and solves the timestamps issue.


Updated command line:

ffmpeg -y -i video.mp4 -r 29.97 -loop 1 -i image.jpg -filter_complex "[1:v]trim=start=0.0:duration=5,setpts=PTS-STARTPTS+0/TB[pip:v];[pip:v]scale='if(gte(ih,iw),384,-1):if(gte(ih,iw),-1,216)',crop=384:216:exact=1[pip:v];[pip:v]scale=iw*(1.3):ih*(1.3)[pip:v];[pip:v]crop=384:216:-(in_w-out_w)*(t-(5))/5:0[pip:v];[0:v][pip:v]overlay=main_w-overlay_w-33.333332:main_h-overlay_h-33.333332:enable='between(t,0,0+5)':format=yuv444[outv]" -map [outv] -preset ultrafast -r 29.97 output.mp4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy