Search code examples
ffmpeg

How to slide mutiple images left continuously?


I use ffmpeg to slide images from left to center as below:

#slide 1st image from right to center
#countdown 10 seconds
#slide 1st image from center to left and in the same time
#slide 2nd image from right to center
#countdown 10 seconds
#...

ffmpeg -loglevel quiet -loop 1 -i input.png -filter_complex "split=2[bg][slider];[bg]drawbox=c=black:t=fill[bg];[bg][slider]overlay=x='max(W-w*t,0)':y=0" -t 10 -y output.mp4

There is black background between two images, I want to the preious page keep slide from center to left and next page slide fron right to center, what can I do? enter image description here


Solution

  • some python script, partly adapted:

    #!/usr/bin/python3
    import os
    
    LST=[]
    DIR="/mnt/public/upload/jpgs+audio/"
    LSD=os.listdir(DIR)
    LSD.sort()
    for f in LSD:
      if (f.endswith(".jpg")):
        print(f)
        LST.append(f)
    
    FLV=''
    OFS=0        #start
    XFO=10       #countdown in seconds
    OFE=OFS+XFO  #end
    CNT=0        #counter
    
    INP=[]
    f=DIR+LST[0]
    INP.append(f' -loop 1 -i "{f}"')
    PDV='[v0]'
    FLT=f"""
    [0]split=2[bg][v];
    [bg]drawbox=c=black:t=fill[bg];
    [bg][v]overlay=x='if(lt(t,{OFE}),max(W-w*t,0),max(0-w*(t-{OFE}),0-W))'{PDV};
    """
    OFS+=XFO
    OFE=OFS+XFO
    
    for CNT in range(1, len(LST)):
      FLV+=f'{PDV}'
      PDV=f'[v{CNT}]'
      FLV+=f"""[{CNT}]overlay=x='if(between(t,{OFS},{OFE}),max(W-w*(t-{OFS}),0),max(0-w*(t-{OFE}),0-W))'{PDV};
    """
      f=DIR+LST[CNT]
      INP.append(f' -loop 1 -i "{f}"')
      OFS+=XFO
      OFE=OFS+XFO
    
    OFS+=2
    s='ffmpeg'
    for t in INP:
      s=s+t
    s=s+f' -filter_complex "{FLT}{FLV}" -map {PDV} -t {OFS} output.mp4 -y'
    print(s)
    os.system(s)
    os.system(f'mpv output.mp4')