I trying to create a video from a landscape image that moves from left to right of the image.

One form that I thought I can get this done is firstly generating N cropped images from the original one, each of them cropped more and more to the right and then apply some command like this one:

ffmpeg -framerate 1/X -i img%d.png -r 25 -pix_fmt yuv420p out.mp4

This for sure works but is not the quickest and cleaning form to do it. Are there a better method to accomplish this?

1 Answer 1


You can just use the crop filter.

ffmpeg -loop 1 -t 10 -i img.png
       -vf "crop=w=W:h=ih:x='(iw-W)*t/10':y=0"
       -r 25 -pix_fmt yuv420p out.mp4

The crop filter crops the image to Wxih pixels where ih is the original height. You should substitute W with your target width in pixels. The position of the top-left corner of the crop window is set by the x and y expressions.

Since you only want to move left-to-right, y is set to a fixed 0. For x, the expression (iw-W)*t/10 governs the horizontal position of the crop window. t is the processed frame's timestamp in fractional seconds. W is substituted with the target width. iw is the input width. The crop will start from the left edge and end at the right edge at t = 10 seconds.

For an image sequence of 10 seconds, use

ffmpeg -i img%d.png
       -vf "crop=w=W:h=ih:x='(iw-W)*t/10':y=0"
       -r 25 -pix_fmt yuv420p out.mp4
  • Looks good, the produced video thumbnail looks correct but the duration of the video is near 0. I tried to add :d=10 to the expresion and add -t to the general command and doesn't works. Current command ffmpeg -y -framerate 1/10 -i test.jpg -vf "crop=w=1080:h=ih:x='(iw-1080)*t/10' :y=0" -r 25 -pix_fmt yuv420p outpanoramic.mp4
    – Aracem
    May 10, 2018 at 13:33
  • 1
    The command in your Q implies an image sequence img%d.png but you're applying to a single image. I'll modify my command for this case.
    – Gyan
    May 10, 2018 at 13:39
  • Perfect! It works now. Thank you very much! I suggest you edit your answer to include both solutions, for one and for several images, perhaps someone find it useful
    – Aracem
    May 10, 2018 at 14:23
  • @Gyan what if I already made some changes to the video stream in filter_complex and named it [trimmed], how would I make a long input image to overlay from bottom to top and be able to set its speed? Jul 31, 2019 at 21:39
  • Post a new Q with your full command.
    – Gyan
    Aug 1, 2019 at 4:45

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.