0

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

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 '18 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 '18 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 '18 at 14:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.