0

I am generating video using ffmpeg by combining images, audio, logo and some text sliding from right to left. Currently I am using four different ffmpeg commands to complete my video generation process.

Command 1: Below command combines the images and output a video with desired animation

ffmpeg \
-t 5 -i 1.jpg \
-t 5 -i 2.jpg \
-t 5 -i 3.jpg \
-t 5 -i 4.jpg \
-filter_complex \
"[0:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=out:st=4:d=1[v0]; \
 [1:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1]; \
 [2:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2]; \
 [3:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v3]; \
 [v0][v1][v2][v3]concat=n=4:v=1:a=0,format=yuv420p[v]" -map "[v]" -s "800x450" ./out_fade.mp4

Command number 2: Then I use this 2nd command to add audio to my video.

ffmpeg -i 'input_video.mp4' -i 'audio.mp3' -codec copy -shortest video_out.mp4

Command number 3: This is used to add logo to my video on top left location.

ffmpeg -i 'input_video.mp4' -i 'logo.png' -filter_complex "[0:v][1:v] overlay=25:25" -pix_fmt yuv420p -c:a copy 'video_out.mp4'

Command number 4: This is used to add the sliding text in a red box at the bottom of the video screen.

ffmpeg -i video_input.mp4 -vf "drawbox=y=ih-80:color=#ef2626@0.8:width=iw:height=80:t=fill,drawtext=text='This is a testing text example.':expansion=normal:y=h-line_h-20:x='if(eq(t\,0)\,w\,if(lt(x\,(0-tw))\,w\,x-4))':fontfile='Lora/Lora-Regular.ttf':fontcolor=white: fontsize=40" video_final.mp4

This process is slow I think and I am thinking is it possible I can combine these 4 processes into one or at least reduce it to two commands?

0

Here's the combined command,

ffmpeg \
-i 1.jpg \
-i 2.jpg \
-i 3.jpg \
-i 4.jpg \
-i 'audio.mp3' \
-i 'logo.png' \
-filter_complex \
"[0:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=out:st=4:d=1[v0]; \
 [1:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1]; \
 [2:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2]; \
 [3:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v3]; \
 [v0][v1][v2][v3]concat=n=4:v=1:a=0,format=yuv420p,scale=800:450,setsar=1[v]; \
 [v][5]overlay=25:25,drawbox=y=ih-80:color=#ef2626@0.8:width=iw:height=80:t=fill,drawtext=text='This is a testing text example.':expansion=normal:y=h-line_h-20:x='if(eq(t\,0)\,w\,if(lt(x\,(0-tw))\,w\,x-4))':fontfile='Lora/Lora-Regular.ttf':fontcolor=white: fontsize=40" \
-c:a copy -shortest ./out_fade.mp4
  • Thanks this worked like a charm. – Imran Khan Oct 2 at 16:14

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.