0

I want to animate with ffmpeg as in the picture. The animation must be 3 seconds long. Zoom in for 0.5 seconds at the beginning of the video Swipe left for 1 second Swipe right for 1 second Zoom out for 0.5 seconds. I have a 3 images. Is this possible?

i'am tryging ffmpeg (python or php or msdos)

example image

1
  • Xfade "...create transitions between two inputs with various wipes, slides, crossfades, and other effects."
    – JayCravens
    Commented May 13 at 13:44

1 Answer 1

2

math

ffmpeg -loop 1 -t 3 -r 60 -i 1.jpg -lavfi "
format=yuv444p,
scale=1080:1920,
pad=1920:1920:-1:-1,
zoompan=z='
if(lt(in,30), trunc(iw*10*(1+0.005*in)/2)*2/(iw*10),
if(lt(in,150),trunc(iw*10*(1+0.005*30)/2)*2/(iw*10),
              trunc(iw*10*(1+0.005*(180-in))/2)*2/(iw*10)))'
:d=1
:x='
if(lt(in,30), iw/2-iw/zoom/2,
if(lt(in,90), iw/2-iw/zoom/2+30-in,
if(lt(in,150),iw/2-iw/zoom/2+30-90+in-90,
              iw/2-iw/zoom/2)))'
:y='ih/2-ih/zoom/2'
:s=1920x1920
:fps=60,
crop=1080
" -c:v ffv1 out.mkv

fps 60, pad to square pic 1920x1920, it gives smooth zoom, maybe :)

python script, not optimized:

#!/usr/bin/python3
import os
path="/mnt/public/upload/vert_jpg/"
WID=1080
HEI=1920
INP=""
FCT=0
SCA=""
FIL=""
ZOM="""format=yuv444p,
scale=1080:1920,
pad=1920:1920:-1:-1,
setsar=1,
zoompan=z='
if(lt(in,30), trunc(iw*10*(1+0.005*in)/2)*2/(iw*10),
if(lt(in,150),trunc(iw*10*(1+0.005*30)/2)*2/(iw*10),
              trunc(iw*10*(1+0.005*(180-in))/2)*2/(iw*10)))'
:d=1
:x='
if(lt(in,30), iw/2-iw/zoom/2,
if(lt(in,90), iw/2-iw/zoom/2+30-in,
if(lt(in,150),iw/2-iw/zoom/2+30-90+in-90,
              iw/2-iw/zoom/2)))'
:y='ih/2-ih/zoom/2'
:s=1920x1920
:fps=60,
crop=1080
"""

for filename in sorted(os.listdir(path)):
  if (filename.endswith(".jpg")):
    INP+=f' -loop 1 -t 3 -r 60 -i "{path}{filename}"'
    PAD=f"[{FCT}v]"
    SCA+=f"[{FCT}:v]{ZOM},drawtext=text='{filename}':fontcolor=yellow:fontsize=50{PAD};"
    FIL+=f"{PAD}"
    FCT+=1

os.system(f'ffmpeg {INP} -filter_complex "{SCA}{FIL}concat={FCT}:1:0" -c:v h264_nvenc -cq 20 /tmp/output.mkv -y -hide_banner')
os.system(f'mpv /tmp/output.mkv')
3
  • You are a great man. Your code worked perfectly. but I only see 1.jpg. Can I add 1-2-3-4 images?
    – zetrabit
    Commented May 13 at 17:20
  • Thank you code is working perfect.Isn't it possible to do this with a single ffmpeg code?
    – zetrabit
    Commented May 15 at 12:52
  • try to replace os.system(f'ffmpeg ... with print(f'ffmpeg ... to get generated command line Commented May 16 at 0:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .