Answers.Body: <p>Basic syntax is</p>
  
  <pre><code>ffmpeg -i video1 -i video2 -i video3 -i video4
         -filter_complex "[1]scale=0.40*iw:-1,setpts=PTS-STARTPTS+1/TB[v2];
                          [2]scale=0.40*iw:-1,setpts=PTS-STARTPTS+1/TB[v3];
                          [0][v2]overlay=x=W-w-20:y=H-h-20:eof_action=pass[m2];
                          [m2][v3]overlay=x=W-2*w-40:y=H-h-20:eof_action=pass[m3];
                          [m3][3]concat=n=2:v=1:a=0"   out.mp4
  </code></pre>
  
  <p>I assume all videos have same resolution and framerate. I've scaled videos 2 and 3 to 40% before overlay and offset their start time to 1 second.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-02T18:52:25.440Z
Answers.LastActivityDate: 2018-05-02T18:52:25.440Z
Answers.UserDisplayName: Gyan
Body: <h2>I have 4 files with same encoding to concatenate</h2>
  
  <blockquote>
    <ul>
    <li>"video1.mp4": duration 3 seconds. Show time from 00:00 to 00.03</li>
    <li>"video2.mp4": duration 1 second. Show time from 00:01 to 00.02</li>
    <li>"video3.mp4": duration 2 seconds. Show time from 00:01 to 00.03</li>
    <li>"video4.mp4": duration 2 seconds. Show time from 00:03 to 00.05</li>
    </ul>
  </blockquote>
  
  <h2>What commands to get the following output?</h2>
  
  <p>00:00</p>
  
  <p><a href="https://i.sstatic.net/SRRiL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/SRRiL.png" alt=""></a></p>
  
  <p>00:01 to 00:02</p>
  
  <p><a href="https://i.sstatic.net/nlMnd.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nlMnd.png" alt=""></a></p>
  
  <p>00:03</p>
  
  <p><a href="https://i.sstatic.net/2y4Wx.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2y4Wx.png" alt=""></a></p>
  
  <p>00:03 to 00:05</p>
  
  <p><a href="https://i.sstatic.net/bTzxG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bTzxG.png" alt=""></a></p>
  
Tags: <ffmpeg>
Title: FFmpeg concat plus video inside video with different times
UserDisplayName: Sauron
ThreadText: # FFmpeg concat plus video inside video with different times
  
  (Asked by: username_0 on 2018-05-02)
  
  ## I have 4 files with same encoding to concatenate
  
  > * "video1.mp4": duration 3 seconds. Show time from 00:00 to 00.03
  > * "video2.mp4": duration 1 second. Show time from 00:01 to 00.02
  > * "video3.mp4": duration 2 seconds. Show time from 00:01 to 00.03
  > * "video4.mp4": duration 2 seconds. Show time from 00:03 to 00.05
  
  ## What commands to get the following output?
  
  00:00
  
  [![](https://i.sstatic.net/SRRiL.png)](https://i.sstatic.net/SRRiL.png)
  
  00:01 to 00:02
  
  [![](https://i.sstatic.net/nlMnd.png)](https://i.sstatic.net/nlMnd.png)
  
  00:03
  
  [![](https://i.sstatic.net/2y4Wx.png)](https://i.sstatic.net/2y4Wx.png)
  
  00:03 to 00:05
  
  [![](https://i.sstatic.net/bTzxG.png)](https://i.sstatic.net/bTzxG.png)
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-02. Score: 2 | Accepted answer
  
  Basic syntax is
  
  ```
  ffmpeg -i video1 -i video2 -i video3 -i video4
         -filter_complex "[1]scale=0.40*iw:-1,setpts=PTS-STARTPTS+1/TB[v2];
                          [2]scale=0.40*iw:-1,setpts=PTS-STARTPTS+1/TB[v3];
                          [0][v2]overlay=x=W-w-20:y=H-h-20:eof_action=pass[m2];
                          [m2][v3]overlay=x=W-2*w-40:y=H-h-20:eof_action=pass[m3];
                          [m3][3]concat=n=2:v=1:a=0"   out.mp4
  
  ```
  
  I assume all videos have same resolution and framerate. I've scaled videos 2 and 3 to 40% before overlay and offset their start time to 1 second.
  
  
  ---
  
  