ffmpeg: zoom a horizontal photo in a vertical video, fill the empty space at the top and bottom with a blurry photo

The script image_to_video_zoom_vertical.sh to zoom a horizontal photo in a vertical video and fill the empty space at the top and bottom with a blurry photo using ffmpeg:

INPUT="$1"
OUTPUT="${INPUT%%.*}_zoom.MP4"
MAX_ZOOM="${2:-1.2}"

DURATION_SECONDS="${3:-5}"
FPS="30"
DURATION=$(bc <<< "${DURATION_SECONDS}*${FPS}")
ZOOM_SPEED=$(bc <<< "scale=4;(${MAX_ZOOM}-1)/${DURATION}")

W=1080
H=1920

ffmpeg -i "$INPUT" \
       -filter_complex "[0]scale=w=-1:h=${H},boxblur=50[bg];[0]format=rgba,pad=w=iw:h=iw*${H}/${W}:x=(ow-iw)/2:y=(oh-ih)/2:color=#00000000,zoompan=z='zoom+${ZOOM_SPEED}':x='iw/2-iw/zoom/2':y='ih/2-ih/zoom/2':d=${DURATION}:fps=${FPS}:s=${W}x${H}[fg];[bg][fg]overlay=(W-w)/2:(H-h)/2,crop=${W}:${H}" \
       -pix_fmt yuv420p -c:v libx264 "$OUTPUT" -y

vertical video with zoomming image

Read more here: Source link