<p>So here is what I came up with.</p>
<h1>A not <em>fully</em> one-liner solution</h1>
<h2>1) Generate black clips</h2>
<pre><code>ffmpeg -f lavfi -i &quot;color=black:s=1920x1080:r=30&quot; \
 -f lavfi -i &quot;anullsrc=r=48000:cl=stereo&quot; \
 -c:v libx264 -c:a aac -t 3 empty_3s.mp4
</code></pre>
<p>Use <strong>lavfi filters</strong> to generate your empty clip. Of course, change the parameters according to your videos and what you want to achieve. Especially:</p>
<ul>
<li>in first (video) source filter:
<ul>
<li><code>s</code> (size) should match that of the videos you want to concatenate.</li>
<li><code>r</code> (frame rate) should also match your videos (especially if your want a constant frame rate output)</li>
</ul>
</li>
<li>in second (audio) source filter:
<ul>
<li><code>r</code> (sample rate) should match that of the audio tracks from the videos you want to concatenate.</li>
<li><code>cl</code> (channel layout) should also match the audio from your videos</li>
</ul>
</li>
</ul>
<p>Output parameters (codecs for instance) should match those of your videos. Use <code>-t</code> to set the length (in seconds) of the empty clip.</p>
<h2>2) Concatenate and fade your videos using a <strong>complex filtergraph</strong></h2>
<pre><code>ffmpeg -i empty_1s.mp4 -i part_1.mp4 -i empty_3s.mp4 -i part_2.mp4 -i empty_1s.mp4 \
 -filter_complex \
  &quot;[1:v] fade=t=in:st=0:d=2, fade=t=out:st=58:d=2 [1v]; \
   [1:a] afade=t=in:st=0:d=2, afade=t=out:st=58:d=2 [1a]; \
   [3:v] fade=t=in:st=0:d=2, fade=t=out:st=118:d=2 [3v]; \
   [3:a] afade=t=in:st=0:d=1, afade=t=out:st=118:d=2 [3a]; \
   [0:v] [0:a] [1v] [1a] [2:v] [2:a] [3v] [3a] [4:v] [4:a] concat=n=5:v=1:a=1 [v] [a]&quot; \
 -map &quot;[v]&quot; -map &quot;[a]&quot; -c:v libx264 -c:a aac output.mp4
</code></pre>
<p><strong>Explanation:</strong></p>
<ul>
<li>we first specify the <strong>inputs</strong> (<code>-i</code>) that we will concatenate</li>
<li>we then set a <strong>complex filter</strong> (<code>-filter_complex</code>), that we use to:
<ul>
<li>first, <strong>fade in and out</strong> our videos. To that end we use the <strong><code>fade</code></strong> (for video) and <strong><code>afade</code></strong> (for audio) filters. We specify the start (<code>st</code>) and duration (<code>d</code>) for each fade. We output the results with outpad names (<code>[1v]</code>, <code>[1a]</code>...).</li>
<li>then, <strong>concatenate</strong> the black clips and the previously faded videos, using the <strong><code>concat</code></strong> filter. We specify the number of input segments <code>n</code> (i.e. the number of video+audio sets, in our case 5) we want to concat, and the number of video (<code>v=1</code>) and audio (<code>a=1</code>) streams for the output.</li>
</ul>
</li>
<li>we <code>map</code> the final output to the output streams from the concat filter</li>
<li>specify the encoding parameters to whatever you want :)</li>
</ul>
<p><strong>Important notes:</strong></p>
<ul>
<li>your videos (inputs) must have the <strong>same characteristics</strong> (pixel and sample format for video, sample rate and channel layout for audio). See <a href="https://ffmpeg.org/ffmpeg-filters.html#concat" rel="nofollow noreferrer" title="concat - FFmpeg Filters documentation">concat documentation</a> for more info.</li>
<li>in the fade filter, we specify start time and duration in seconds, but you can use frames or samples as well with <code>s</code> and <code>n</code> (video) or <code>ss</code> and <code>ns</code> (audio) options. See <a href="https://ffmpeg.org/ffmpeg-filters.html#afade" rel="nofollow noreferrer" title="afade - FFmpeg Filters documentation">afade</a> and <a href="https://ffmpeg.org/ffmpeg-filters.html#fade" rel="nofollow noreferrer" title="fade - FFmpeg Filters documentation">fade</a> filters documentation.</li>
<li>you must know the duration of your videos for the fade filter, especially for fade-outs. See <a href="https://video.stackexchange.com/questions/19867/how-to-fade-in-out-a-video-audio-clip-with-unknown-duration" title="How to fade in/out a video/audio clip with unknown duration?">this question</a> for hints on how two fade-out clips without having to manually specify start time.</li>
</ul>
<h1>True one-liner</h1>
<p>If you really want a one-liner (and not having to encode empty black clips), you can use:</p>
<pre><code>ffmpeg \
 -f lavfi -t 1 -i &quot;color=black:s=1920x1080:r=30&quot; -f lavfi -t 1 -i &quot;anullsrc=r=48000:cl=2&quot; \
 -i part_1.mp4 \
 -f lavfi -t 3 -i &quot;color=black:s=1920x1080:r=30&quot; -f lavfi -t 3 -i &quot;anullsrc=r=48000:cl=2&quot; \
 -i part_2.mp4 \
 -f lavfi -t 1 -i &quot;color=black:s=1920x1080:r=30&quot; -f lavfi -t 1 -i &quot;anullsrc=r=48000:cl=2&quot; \
 -filter_complex \
  &quot;[0:v] null [0v]; [1:a] anull [0a]; [3:v] null [2v]; [4:a] anull [2a]; \
   [6:v] null [4v]; [7:a] anull [4a]; \
   [2:v] fade=t=in:st=0:d=2, fade=t=out:st=58:d=2 [1v]; \
   [2:a] afade=t=in:st=0:d=2, afade=t=out:st=58:d=2 [1a]; \
   [5:v] fade=t=in:st=0:d=1, fade=t=out:st=118:d=2 [3v]; \
   [5:a] afade=t=in:st=0:d=1, afade=t=out:st=118:d=2 [3a]; \
   [0v] [0a] [1v] [1a] [2v] [2a] [3v] [3a] [4v] [4a] concat=n=5:v=1:a=1 [v] [a]&quot; \
 -map &quot;[v]&quot; -map &quot;[a]&quot; -c:v libx264 -c:a aac output.mp4
</code></pre>
<p>In that case we must <strong>beware of the input indices</strong>, as <em>black video clips and null audio clips are separated inputs</em> (I didn't figure out how to put them as two streams in a single input, if you have an idea feel free to share it).</p>
<p>Here I applied <code>null</code> and <code>anull</code> filters to those inputs to give them outpad tags, in order to use consistent identifiers in the <code>concat</code> filter. But this is purely optional.</p>
<p>Hope this helps, feel free to improve my solution with your insights :)</p>

CC BY-SA 3.0
2017-12-26T16:33:55.653Z
You don't need to generate distinct source filter inputs for the null video and audio segments. They can be used multiple times in the filter_complex.
Gyan
CC BY-SA 3.0
2017-12-11T16:33:19.920Z
2017-12-26T13:51:51.133Z
2020-06-17T09:53:03.607Z
TedGrassman
<p>I recently had the following problem:</p>

<p>I wanted, using ffmpeg, to <strong>concatenate several videos</strong> (with audio), <strong>adding black clips</strong> (with null audio) between them , and lastly <strong>fade</strong> the videos from those black clips (<strong>fade-in</strong>) and to those black clips (<strong>fade-out</strong>).</p>

<p>Schematically, with 2 videos for instance:</p>

<pre><code>black (1s) --&gt; part_1 (60s) --&gt; black (3s) --&gt; part_2 (120s) --&gt; black (1s)
            ^                ^              ^                 ^
       (2s-fade-in)     (2s-fade-out)  (2s-fade-in)      (2s-fade-out)
</code></pre>

<p>I was looking for a <strong>one-liner solution</strong> (to avoid re-encoding original videos more than once), but only found documentation or help for each part of the problem.</p>

<p>Having figured it out, I wanted to document my solution for those after me who will stumble on a similar problem :)</p>

<ffmpeg><filter>
How to concatenate multiple videos with fades (from- and to-black) in-between?
TedGrassman
# How to concatenate multiple videos with fades (from- and to-black) in-between?

(Asked by: username_0 on 2017-12-11)

I recently had the following problem:
I wanted, using ffmpeg, to concatenate several videos (with audio), adding black clips (with null audio) between them , and lastly fade the videos from those black clips (fade-in) and to those black clips (fade-out).
Schematically, with 2 videos for instance:
black (1s) --> part_1 (60s) --> black (3s) --> part_2 (120s) --> black (1s)
            ^                ^              ^                 ^
       (2s-fade-in)     (2s-fade-out)  (2s-fade-in)      (2s-fade-out)

I was looking for a one-liner solution (to avoid re-encoding original videos more than once), but only found documentation or help for each part of the problem.
Having figured it out, I wanted to document my solution for those after me who will stumble on a similar problem :)

**Tags:** ffmpeg, filter


---

## 1 answers

### Answer by username_0 on 2017-12-11. Score: 4 | Accepted answer

So here is what I came up with.
A not fully one-liner solution
1) Generate black clips
ffmpeg -f lavfi -i "color=black:s=1920x1080:r=30" \
 -f lavfi -i "anullsrc=r=48000:cl=stereo" \
 -c:v libx264 -c:a aac -t 3 empty_3s.mp4

Use lavfi filters to generate your empty clip. Of course, change the parameters according to your videos and what you want to achieve. Especially:

in first (video) source filter:

s (size) should match that of the videos you want to concatenate.
r (frame rate) should also match your videos (especially if your want a constant frame rate output)


in second (audio) source filter:

r (sample rate) should match that of the audio tracks from the videos you want to concatenate.
cl (channel layout) should also match the audio from your videos



Output parameters (codecs for instance) should match those of your videos. Use -t to set the length (in seconds) of the empty clip.
2) Concatenate and fade your videos using a complex filtergraph
ffmpeg -i empty_1s.mp4 -i part_1.mp4 -i empty_3s.mp4 -i part_2.mp4 -i empty_1s.mp4 \
 -filter_complex \
  "[1:v] fade=t=in:st=0:d=2, fade=t=out:st=58:d=2 [1v]; \
   [1:a] afade=t=in:st=0:d=2, afade=t=out:st=58:d=2 [1a]; \
   [3:v] fade=t=in:st=0:d=2, fade=t=out:st=118:d=2 [3v]; \
   [3:a] afade=t=in:st=0:d=1, afade=t=out:st=118:d=2 [3a]; \
   [0:v] [0:a] [1v] [1a] [2:v] [2:a] [3v] [3a] [4:v] [4:a] concat=n=5:v=1:a=1 [v] [a]" \
 -map "[v]" -map "[a]" -c:v libx264 -c:a aac output.mp4

Explanation:

we first specify the inputs (-i) that we will concatenate
we then set a complex filter (-filter_complex), that we use to:

first, fade in and out our videos. To that end we use the fade (for video) and afade (for audio) filters. We specify the start (st) and duration (d) for each fade. We output the results with outpad names ([1v], [1a]...).
then, concatenate the black clips and the previously faded videos, using the concat filter. We specify the number of input segments n (i.e. the number of video+audio sets, in our case 5) we want to concat, and the number of video (v=1) and audio (a=1) streams for the output.


we map the final output to the output streams from the concat filter
specify the encoding parameters to whatever you want :)

Important notes:

your videos (inputs) must have the same characteristics (pixel and sample format for video, sample rate and channel layout for audio). See concat documentation for more info.
in the fade filter, we specify start time and duration in seconds, but you can use frames or samples as well with s and n (video) or ss and ns (audio) options. See afade and fade filters documentation.
you must know the duration of your videos for the fade filter, especially for fade-outs. See this question for hints on how two fade-out clips without having to manually specify start time.

True one-liner
If you really want a one-liner (and not having to encode empty black clips), you can use:
ffmpeg \
 -f lavfi -t 1 -i "color=black:s=1920x1080:r=30" -f lavfi -t 1 -i "anullsrc=r=48000:cl=2" \
 -i part_1.mp4 \
 -f lavfi -t 3 -i "color=black:s=1920x1080:r=30" -f lavfi -t 3 -i "anullsrc=r=48000:cl=2" \
 -i part_2.mp4 \
 -f lavfi -t 1 -i "color=black:s=1920x1080:r=30" -f lavfi -t 1 -i "anullsrc=r=48000:cl=2" \
 -filter_complex \
  "[0:v] null [0v]; [1:a] anull [0a]; [3:v] null [2v]; [4:a] anull [2a]; \
   [6:v] null [4v]; [7:a] anull [4a]; \
   [2:v] fade=t=in:st=0:d=2, fade=t=out:st=58:d=2 [1v]; \
   [2:a] afade=t=in:st=0:d=2, afade=t=out:st=58:d=2 [1a]; \
   [5:v] fade=t=in:st=0:d=1, fade=t=out:st=118:d=2 [3v]; \
   [5:a] afade=t=in:st=0:d=1, afade=t=out:st=118:d=2 [3a]; \
   [0v] [0a] [1v] [1a] [2v] [2a] [3v] [3a] [4v] [4a] concat=n=5:v=1:a=1 [v] [a]" \
 -map "[v]" -map "[a]" -c:v libx264 -c:a aac output.mp4

In that case we must beware of the input indices, as black video clips and null audio clips are separated inputs (I didn't figure out how to put them as two streams in a single input, if you have an idea feel free to share it).
Here I applied null and anull filters to those inputs to give them outpad tags, in order to use consistent identifiers in the concat filter. But this is purely optional.
Hope this helps, feel free to improve my solution with your insights :)

> **Comments:**
> **username_1**: You don't need to generate distinct source filter inputs for the null video and audio segments. They can be used multiple times in the filter_complex.  

---

