<p>Sure. Command is</p>

<pre><code>ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -i bg.mp3
-filter_complex
"[0]trim=0:20,scale=1920:-1,crop=1920:1080:0:0[a];
 [1]trim=0:20,scale=1920:-1,crop=1920:1080:0:0[b];
 [2]trim=0:20,scale=1920:-1,crop=1920:1080:0:0[c];
 [a][b][c]concat=3[v]"
-map "[v]" -map 3:a
-shortest out.mp4
</code></pre>

<p>Skip the <code>-shortest</code> if the audio is slightly longer than 1 minute. Alternatively, adjust one of the trim endpoints to make up for the shortfall.</p>

<p><em>to play in the background of the final video</em> -> I assume final here means the output and not the 3rd video.</p>

CC BY-SA 4.0
2019-07-29T21:44:11.010Z
Is there a benefit of using `-i 1.mp4 ... [0]trim=0:20...` over `-ss 0 -t 20 -i 1.mp4 ...`? I would think that trimming within a filter takes more resources than seeking to the video locations on the input level. Code wise, this definitely seems more readable.
user3643
CC BY-SA 4.0
2019-07-30T04:54:11.867Z
You will save decoding time if your -ss is inside the file, yes. But ffmpeg can only seek to keyframes so the portion between the returned keyframe and actual ss point as well as the limiting of duration via input -t is carried out by auto-inserting a trim filter at the front.
Gyan
CC BY-SA 4.0
2019-07-30T05:16:00.900Z
So basically the same, unless your ss point is quite far into the file? Thanks.
user3643
CC BY-SA 3.0
2017-01-17T13:04:37.660Z
2017-01-17T13:04:37.660Z
Gyan
<p>Need to:</p>

<p>concatenate 3 mpg4 video clips (each around 1 minute long, and 800x500 size) + background mp3 -> into a 1-minute long (1920x1080) video composed of the first 20 seconds from each of the 4 videos.</p>

<p>So each clip would need to be enlarged (from 800x500 to 1920x1200 to keep aspect ration), and then the height (cropped down to 1920x1080 from the bottom of the video).</p>

<p>Then each video cut down to the first 20 seconds.</p>

<p>Then the 3 videos are concatenated (along with a 1 minute long mp3 file to play in the background of the final video).</p>

<p>Questions:</p>

<ol>
<li>Is ffmpeg capable of doing this correctly and how?</li>
</ol>

<ffmpeg>
How to concatenate multiple videos with ffmpeg?
NickNo
# How to concatenate multiple videos with ffmpeg?

(Asked by: username_0 on 2017-01-17)

Need to:

concatenate 3 mpg4 video clips (each around 1 minute long, and 800x500 size) + background mp3 -> into a 1-minute long (1920x1080) video composed of the first 20 seconds from each of the 4 videos.

So each clip would need to be enlarged (from 800x500 to 1920x1200 to keep aspect ration), and then the height (cropped down to 1920x1080 from the bottom of the video).

Then each video cut down to the first 20 seconds.

Then the 3 videos are concatenated (along with a 1 minute long mp3 file to play in the background of the final video).

Questions:

1. Is ffmpeg capable of doing this correctly and how?

**Tags:** ffmpeg


---

## 1 answers

### Answer by username_1 on 2017-01-17. Score: 3 | Accepted answer

Sure. Command is
ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -i bg.mp3
-filter_complex
"[0]trim=0:20,scale=1920:-1,crop=1920:1080:0:0[a];
 [1]trim=0:20,scale=1920:-1,crop=1920:1080:0:0[b];
 [2]trim=0:20,scale=1920:-1,crop=1920:1080:0:0[c];
 [a][b][c]concat=3[v]"
-map "[v]" -map 3:a
-shortest out.mp4

Skip the -shortest if the audio is slightly longer than 1 minute. Alternatively, adjust one of the trim endpoints to make up for the shortfall.
to play in the background of the final video -> I assume final here means the output and not the 3rd video.

> **Comments:**
> **username_2**: Is there a benefit of using `-i 1.mp4 ... [0]trim=0:20...` over `-ss 0 -t 20 -i 1.mp4 ...`? I would think that trimming within a filter takes more resources than seeking to the video locations on the input level. Code wise, this definitely seems more readable.  
> **username_1**: You will save decoding time if your -ss is inside the file, yes. But ffmpeg can only seek to keyframes so the portion between the returned keyframe and actual ss point as well as the limiting of duration via input -t is carried out by auto-inserting a trim filter at the front.  
> **username_2**: So basically the same, unless your ss point is quite far into the file? Thanks.  

---

