Search code examples
iosffmpeg

Large Panorama to Panning Video


What would be the most efficient way to create a video from a panoramic image that would for example have the size: 5000 width x 600 height px?

I created this GIF image that would explain things a bit better. Imagine that the video would be inside the red border. So the video would potentially be panning from left to right.

GIF explanation


Solution

  • A moving crop is the most convenient way to achieve this in ffmpeg.

    ffmpeg -loop 1 -i in.jpg -vf "crop=500:ih:'min((iw/10)*t,9*iw/10)':0" -t 10 pan.mp4
    

    The crop filter crops to a size of 500 x ih i.e. 500x600. The top-left co-ordinate of the cropping window is fixed to Y=0. For X, the expression is min((iw/10)*t,9*iw/10) i.e. in each second, the cropping window will slide across 10% of the image width. So, at t=9, the cropping window covers (4500,0) to (5000,600) for the example image. From that time, the min function returns the other value 9*iw/10 = 4500 and the sliding stops.