<p>The h/vstack filters are designed to pair frames so they will hold the first frame of an input if the other input isn't active. Use the tpad filter to add blank frames for the required duration.</p>

<p><code>ffmpeg -i left.mp4 -i right.mp4 -filter_complex [0:v]setpts=PTS-STARTPTS[l]; [1:v]setpts=PTS-STARTPTS,tpad=start_duration=14:start_mode=add:color=black[r]; [l][r]hstack=inputs=2[stacked]; [0:a][1:a]amix=inputs=2[a] -map [stacked] -map [a] -c:a aac -preset superfast result.mp4</code></p>

<p>If you don't have the tpad filter available, a slightly longer approach is to use the drawbox filter with ffmpeg 4.0+.</p>

<p><code>ffmpeg -i left.mp4 -i right.mp4 -filter_complex [0:v]setpts=PTS-STARTPTS[l]; [1:v]setpts=PTS-STARTPTS,split[rb][rv];[rb]trim=0:14,drawbox=t=fill:c=black[rb];[rb][rv]concat=n=2:v=1:a0[r]; [l][r]hstack=inputs=2[stacked]; [0:a][1:a]amix=inputs=2[a] -map [stacked] -map [a] -c:a aac -preset superfast result.mp4</code></p>

CC BY-SA 4.0
2019-08-26T15:27:25.023Z
I believe this should work. I am using this in android environment, but my ffmpeg build 3.3.4 is saying no such filter 'tpad'.
cocojal
CC BY-SA 4.0
2019-08-26T15:30:51.630Z
You'll need v4.2
Gyan
CC BY-SA 4.0
2019-08-26T15:38:32.790Z
I have another library with ffmpeg 4.0 compiled. Is there any other way, this can be achieved ?
cocojal
CC BY-SA 4.0
2019-08-26T15:44:18.503Z
added workaround
Gyan
CC BY-SA 4.0
2019-08-26T15:51:06.110Z
Thank you so much, it is time, I upgrade to 4.2, will build ffmpeg 4.2 and get back to you. Meanwhile I am accepting your answer.
cocojal
CC BY-SA 4.0
2019-08-26T15:11:49.297Z
2019-08-26T15:43:52.163Z
2019-08-26T15:43:52.163Z
Gyan
<p>I am merging two mp4 files using hstack. I am using amix to merge the audio. Everything works perfectly. </p>

<p>Now I want that the hstacked videos should play sequentially, that is one after the other. Here is what I have done </p>

<pre><code>ffmpeg -i left.mp4 -i right.mp4 -filter_complex [0:v]setpts=PTS-STARTPTS[l]; [1:v]setpts=PTS-STARTPTS+14/TB[r]; [l][r]hstack=inputs=2[stacked]; [0:a][1:a]amix=inputs=2[a] -map [stacked] -map [a] -c:a aac -preset superfast result.mp4
</code></pre>

<p>In the above example, I tried to delay the play back of the video on the right by 14 seconds (which happens to be the length of the left video). In essence I want the left video to play first and after it finishes the left video should play.</p>

<p>What I am getting instead from the command is, the left video remains still for 14 seconds with only displaying the first frame (the audio plays) and after 14 seconds the right video plays.</p>

<p>I am at my wits end trying to figure it out. What am I doing wrong ?</p>

<ffmpeg>
Merging two videos with hstack and play them back sequentially
cocojal
# Merging two videos with hstack and play them back sequentially

(Asked by: username_0 on 2019-08-26)

I am merging two mp4 files using hstack. I am using amix to merge the audio. Everything works perfectly. 
Now I want that the hstacked videos should play sequentially, that is one after the other. Here is what I have done 
ffmpeg -i left.mp4 -i right.mp4 -filter_complex [0:v]setpts=PTS-STARTPTS[l]; [1:v]setpts=PTS-STARTPTS+14/TB[r]; [l][r]hstack=inputs=2[stacked]; [0:a][1:a]amix=inputs=2[a] -map [stacked] -map [a] -c:a aac -preset superfast result.mp4

In the above example, I tried to delay the play back of the video on the right by 14 seconds (which happens to be the length of the left video). In essence I want the left video to play first and after it finishes the left video should play.
What I am getting instead from the command is, the left video remains still for 14 seconds with only displaying the first frame (the audio plays) and after 14 seconds the right video plays.
I am at my wits end trying to figure it out. What am I doing wrong ?

**Tags:** ffmpeg


---

## 1 answers

### Answer by username_1 on 2019-08-26. Score: 0 | Accepted answer

The h/vstack filters are designed to pair frames so they will hold the first frame of an input if the other input isn't active. Use the tpad filter to add blank frames for the required duration.

`ffmpeg -i left.mp4 -i right.mp4 -filter_complex [0:v]setpts=PTS-STARTPTS[l]; [1:v]setpts=PTS-STARTPTS,tpad=start_duration=14:start_mode=add:color=black[r]; [l][r]hstack=inputs=2[stacked]; [0:a][1:a]amix=inputs=2[a] -map [stacked] -map [a] -c:a aac -preset superfast result.mp4`

If you don't have the tpad filter available, a slightly longer approach is to use the drawbox filter with ffmpeg 4.0+.

`ffmpeg -i left.mp4 -i right.mp4 -filter_complex [0:v]setpts=PTS-STARTPTS[l]; [1:v]setpts=PTS-STARTPTS,split[rb][rv];[rb]trim=0:14,drawbox=t=fill:c=black[rb];[rb][rv]concat=n=2:v=1:a0[r]; [l][r]hstack=inputs=2[stacked]; [0:a][1:a]amix=inputs=2[a] -map [stacked] -map [a] -c:a aac -preset superfast result.mp4`

> **Comments:**
> **username_0**: I believe this should work. I am using this in android environment, but my ffmpeg build 3.3.4 is saying no such filter 'tpad'.  
> **username_1**: You'll need v4.2  
> **username_0**: I have another library with ffmpeg 4.0 compiled. Is there any other way, this can be achieved ?  
> **username_1**: added workaround  
> **username_0**: Thank you so much, it is time, I upgrade to 4.2, will build ffmpeg 4.2 and get back to you. Meanwhile I am accepting your answer.  

---

