5

I have to run from 8 to 17 commands on a video to add some overlay texts and overlay images.

My problem is that actually I'm using a complex solution: I take the original video, I add some text, I take the output, I add more text, I take the output, I add an image, ... and so on.

The process is really slow and it takes around 20 minutes to add everything to a 2 minutes video (1-2 minutes for each iteration).

Those are some examples of my commands. Is there a way to concatenate them all to a single one?

Add one row of text between two timestamps

-i "video.mp4" -filter_complex "[0]split[base][text];[text]drawtext=fontfile=Arial.ttf:text='Some text':fontcolor=white:fontsize=32:box=1: boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2 - 15,format=yuva444p,fade=t=in:st=6:d=2:alpha=1,fade=t=out:st=19:d=2:alpha=1[subtitles]; [base][subtitles]overlay" output_text1.mp4

Add another row of text between the same two timestamps

-i "output_text1.mp4" -filter_complex "[0]split[base][text];[text]drawtext=fontfile=Arial.ttf:text='some more text':fontcolor=white:fontsize=32:box=1: boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2 + 15,format=yuva444p,fade=t=in:st=6:d=2:alpha=1,fade=t=out:st=19:d=2:alpha=1[subtitles]; [base][subtitles]overlay" output_text2.mp4

Add the first image overlay after the text with some effects

-i "output_text2.mp4" -loop 1 -t 1 -i "1.png" -filter_complex "[1:v]format=yuva422p,scale=1115x1980,setsar=1/1,pad=1.5*iw:1.5*ih:(ow-iw)/2:(oh-ih)/2:color=black@0,zoompan=z='min(zoom+0.0005,1.5)':s=223x396:d=475:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)',fade=in:st=22:d=3.8:alpha=1,fade=out:st=37:d=3.8:alpha=1[im];[0][im]overlay=(main_w-overlay_w)/2:(main_h - overlay_h)/2:shortest=1" -pix_fmt yuv420p -c:a copy output_0.mp4

Add the second image overlay after the first with some effects

-i "output_0.mp4" -loop 1 -t 1 -i "2.jpg" -filter_complex "[1:v]format=yuva422p,scale=1490x1965,setsar=1/1,pad=1.5*iw:1.5*ih:(ow-iw)/2:(oh-ih)/2:color=black@0,zoompan=z='min(zoom+0.0005,1.5)':s=298x393:d=475:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)',fade=in:st=41:d=3.8:alpha=1,fade=out:st=56:d=3.8:alpha=1[im];[0][im]overlay=(main_w-overlay_w)/2:(main_h - overlay_h)/2:shortest=1" -pix_fmt yuv420p -c:a copy output_1.mp4

Is there a way to concat all those commands? Or is there a guideline to respect to concat various commands?

Thanks!

Pier Giorgio Misley
  • 4,977
  • 2
  • 20
  • 59
  • Possible duplicate of https://stackoverflow.com/questions/6195872/applying-multiple-filters-at-once-with-ffmpeg – tripleee Jun 08 '18 at 09:42
  • @tripleee thanks for the link! unfortunatly I already have multiple filters here, the problem is about applying the sam filter to multiple images or adding different overlay operations – Pier Giorgio Misley Jun 08 '18 at 09:53

1 Answers1

1

There are two possible cases

  1. You want a single output file (example 1).
  2. You want all intermediate files (example 2).

If you only need a single output file then you can specify a common output file name i.e. output_text.mp4 and separate the commands with ; this will execute all commands in same order taking last output as input.

Example 1:

-i "video.mp4" -filter_complex "[0]split[base][text];[text]drawtext=fontfile=Arial.ttf:text='Some text':fontcolor=white:fontsize=32:box=1: boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2 - 15,format=yuva444p,fade=t=in:st=6:d=2:alpha=1,fade=t=out:st=19:d=2:alpha=1[subtitles]; [base][subtitles]overlay" output_text.mp4; -i "output_text.mp4" -filter_complex "[0]split[base][text];[text]drawtext=fontfile=Arial.ttf:text='some more text':fontcolor=white:fontsize=32:box=1: boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2 + 15,format=yuva444p,fade=t=in:st=6:d=2:alpha=1,fade=t=out:st=19:d=2:alpha=1[subtitles]; [base][subtitles]overlay" output_text.mp4

If you need all intermediate files then write a shell script and declare the variable for all the output variable

Example 2:

1 = output_text1.mp4
2 = output_text2.mp4

-i "video.mp4" -filter_complex "[0]split[base][text];[text]drawtext=fontfile=Arial.ttf:text='Some text':fontcolor=white:fontsize=32:box=1: boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2 - 15,format=yuva444p,fade=t=in:st=6:d=2:alpha=1,fade=t=out:st=19:d=2:alpha=1[subtitles]; [base][subtitles]overlay" $1

-i $1 -filter_complex "[0]split[base][text];[text]drawtext=fontfile=Arial.ttf:text='some more text':fontcolor=white:fontsize=32:box=1: boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2 + 15,format=yuva444p,fade=t=in:st=6:d=2:alpha=1,fade=t=out:st=19:d=2:alpha=1[subtitles]; [base][subtitles]overlay" $2

and so on.

I think this will solve your problem.

LAV VISHWAKARMA
  • 1,097
  • 12
  • 22
  • Thanks for replying, I gave you the bounty but currently I have no time to test it. As soon as I can do it, I will mark you as answer, elseway I will write here! in the meanwhile, thanks for considering the question and helping! ^^ (ps: if possible, can you add a little explaination on how to mix multiple commands?) – Pier Giorgio Misley Jun 11 '18 at 21:53