Answers.Body: <p>The single command will be long, but here's an example for 3 inputs.</p>
  
  <pre><code>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
         -filter_complex
          "[0]scale=1280:720,setsar=1[0v];
           [1]fade=t=in:st=1.5:d=0.5:alpha=1,fade=t=out:st=10.5:d=0.5:alpha=1[0l];
           [2]scale=1280:720,setsar=1[1v];
           [3]fade=t=in:st=1.5:d=0.5:alpha=1,fade=t=out:st=10.5:d=0.5:alpha=1[1l];
           [4]scale=1280:720,setsar=1[2v];
           [5]fade=t=in:st=1.5:d=0.5:alpha=1,fade=t=out:st=10.5:d=0.5:alpha=1[2l];
           [0v][0l]overlay=10:10:format=auto:enable='between(t,2,11)'[0vl];
           [1v][1l]overlay=10:10:format=auto:enable='between(t,2,11)'[1vl];
           [2v][2l]overlay=10:10:format=auto:enable='between(t,2,11)'[2vl];
           [0]pan=1c,aresample=r=44100[0a];
           [2]pan=1c,aresample=r=44100[1a];
           [4]pan=1c,aresample=r=44100[2a];
           [0vl][0a][1vl][1a][2vl][2a]concat=n=2:v=1:a=1[v][a]"
          -map "[v]" -map "[a]" -pix_fmt yuv420p output.mkv
  </code></pre>
  
  <p>You may need single quotes in the <code>map</code> depending on your shell.</p>
  
  <p>Use a recent version of ffmpeg, at least 4.0</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-06T11:34:56.700Z
Answers.Text: 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?
Answers.UserDisplayName: cquests
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-12T19:52:27.247Z
Answers.Text: Thanks @Gyan I didn't forget and accept the answer. Much appreciate your help <3
Answers.UserDisplayName: cquests
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-02T23:53:10.953Z
Answers.Text: 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?
Answers.UserDisplayName: Hashim Aziz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-03T11:12:49.637Z
Answers.Text: Yes, this is the standard method and only carries out single encoding operation after all filtering.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-14T15:32:46.453Z
Answers.Text: What if we have some hundreds of input files and overcome the command line characters limits (for example, in Windows it is 8192 chars). The "filter_complex" could be written into a file and use "-filter_complex_script" instead. But what about the "-loop" commands? Is there a way to "shrink" the loops in some way? Or another way to have the same result with a shorter command line? I ask because I have this specific problem right now...
Answers.UserDisplayName: radiolondra
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-06T05:01:25.843Z
Answers.LastActivityDate: 2018-10-06T05:01:25.843Z
Answers.UserDisplayName: Gyan
Body: <p>I never worked with ffmpeg before and I'm wondering which optimization I can take for my situation.</p>
  
  <p>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: </p>
  
  <p><code>ffmpeg -i input_01.mp4 -vf 'scale=1280:720,setdar=16/9' -ar 44100 -ac 1 input_01_tmp.mp4</code></p>
  
  <p>Later I add images to each input.mp4 files again one by one:</p>
  
  <p><code>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</code></p>
  
  <p>Finally after the loop I combine them with mkvmerge:</p>
  
  <p><code>mkvmerge -o output.mkv \+ input_01_unified.mp4 +\ input_02_unified.mp4 ...</code></p>
  
  <p>I'm sure this is not the optimal solution and wondering how I should change it. </p>
  
  <p>Is it possible to do all of this in one command? Either for each file or for the whole process.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-05T17:12:38.813Z
Comments.Text: Can be done in one command. Share entire command for 1st and 2nd step
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-05T17:29:39.963Z
Comments.Text: @Gyan thanks! added the missing parts to the commands in the question
Comments.UserDisplayName: cquests
Tags: <ffmpeg><encoding><video-quality><scale>
Title: How to combine and optimize ffmpeg filters to avoid encoding multiple times?
UserDisplayName: cquests
ThreadText: # How to combine and optimize ffmpeg filters to avoid encoding multiple times?
  
  (Asked by: username_0 on 2018-10-05)
  
  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.
  
  **Tags:** ffmpeg, encoding, video-quality, scale
  
  > **Comments:**
  > **username_1**: Can be done in one command. Share entire command for 1st and 2nd step  
  > **username_0**: @username_1 thanks! added the missing parts to the commands in the question  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-10-06. Score: 3 | Accepted answer
  
  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
         -filter_complex
          "[0]scale=1280:720,setsar=1[0v];
           [1]fade=t=in:st=1.5:d=0.5:alpha=1,fade=t=out:st=10.5:d=0.5:alpha=1[0l];
           [2]scale=1280:720,setsar=1[1v];
           [3]fade=t=in:st=1.5:d=0.5:alpha=1,fade=t=out:st=10.5:d=0.5:alpha=1[1l];
           [4]scale=1280:720,setsar=1[2v];
           [5]fade=t=in:st=1.5:d=0.5:alpha=1,fade=t=out:st=10.5:d=0.5:alpha=1[2l];
           [0v][0l]overlay=10:10:format=auto:enable='between(t,2,11)'[0vl];
           [1v][1l]overlay=10:10:format=auto:enable='between(t,2,11)'[1vl];
           [2v][2l]overlay=10:10:format=auto:enable='between(t,2,11)'[2vl];
           [0]pan=1c,aresample=r=44100[0a];
           [2]pan=1c,aresample=r=44100[1a];
           [4]pan=1c,aresample=r=44100[2a];
           [0vl][0a][1vl][1a][2vl][2a]concat=n=2:v=1:a=1[v][a]"
          -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
  
  > **Comments:**
  > **username_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?  
  > **username_0**: Thanks @username_1 I didn't forget and accept the answer. Much appreciate your help <3  
  > **username_2**: 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?  
  > **username_1**: Yes, this is the standard method and only carries out single encoding operation after all filtering.  
  > **username_3**: What if we have some hundreds of input files and overcome the command line characters limits (for example, in Windows it is 8192 chars). The "filter_complex" could be written into a file and use "-filter_complex_script" instead. But what about the "-loop" commands? Is there a way to "shrink" the loops in some way? Or another way to have the same result with a shorter command line? I ask because I have this specific problem right now...  
  
  ---
  
  