I never worked with ffmpeg before and I'm wondering which optimization I can take for my situation.

In a loop I have multiple input.mp4 files which I first convert one by one to have a common scale and audio rate with this command:

ffmpeg -i input_01.mp4 -vf 'scale=1280:720,setdar=16/9' -ar 44100 -ac 1 input_01_tmp.mp4

Later I add images to each input.mp4 files again one by one:

ffmpeg -i input_01_tmp.mp4 -i input_01_logo.png -filter_complex "[0:v][1:v]overlay=10:10:enable='between(t,2,11)',fade=t=in:start_time=1.5:d=0.5:alpha=1,fade=t=out:start_time=10.5:d=0.5:alpha=1[fg];[0][fg]overlay=format=auto,format=yuv420p" -c:a copy input_01_unified.mp4

Finally after the loop I combine them with mkvmerge:

mkvmerge -o output.mkv \+ input_01_unified.mp4 +\ input_02_unified.mp4 ...

I'm sure this is not the optimal solution and wondering how I should change it.

Is it possible to do all of this in one command? Either for each file or for the whole process.

  • Can be done in one command. Share entire command for 1st and 2nd step – Gyan Oct 5 '18 at 17:12
  • @Gyan thanks! added the missing parts to the commands in the question – cquests Oct 5 '18 at 17:29

The single command will be long, but here's an example for 3 inputs.

ffmpeg -i input_01.mp4 -loop 1 -t 11 -i input_01_logo.png
       -i input_02.mp4 -loop 1 -t 11 -i input_02_logo.png
       -i input_03.mp4 -loop 1 -t 11 -i input_03_logo.png
        -map "[v]" -map "[a]" -pix_fmt yuv420p output.mkv

You may need single quotes in the map depending on your shell.

Use a recent version of ffmpeg, at least 4.0

  • Thank you! I'll try this out today and accept the answer. Besides time saving, has this any effects on better quality in comparison to what I did? – cquests Oct 6 '18 at 11:34
  • Thanks @Gyan I didn't forget and accept the answer. Much appreciate your help <3 – cquests Oct 12 '18 at 19:52
  • For clarification, is it beneficial to combine filters like this? Does it ensure that everything will be done in one encode, or will it still encode multiple times just like running each operation separately? – Hashim Aziz Mar 2 at 23:53
  • 1
    Yes, this is the standard method and only carries out single encoding operation after all filtering. – Gyan Mar 3 at 11:12

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.