<p>Use</p>

<pre><code>ffmpeg -i shorter.mp4 -i longer.mp4 -filter_complex
 "[0]trim=0:3.5,drawbox=c=black[delay];[delay][0]concat[left];
  [left][1]hstack[v]"
 -map "[v]" -map 1:a -c:a copy out.mp4
</code></pre>

<p>where <code>3.5</code> should be replaced with the delayed start time (in seconds) of the shorter video.</p>

CC BY-SA 3.0
2018-01-04T09:04:49.897Z
Awesome! But there was one missing point. Sync was proper. But the right video didn't start until the delay (13s) elapsed. Then both videos started simultaneously. In essence, I lost the first 13s of the right video
Nagabhushan S N
CC BY-SA 3.0
2018-01-04T09:15:22.860Z
See edited cmd.
Gyan
CC BY-SA 3.0
2018-01-04T09:30:09.307Z
No. The update distorted. Both videos began simultaneously. After few seconds, left video paused for few seconds. Then it resumed in sync with the right video
Nagabhushan S N
CC BY-SA 3.0
2018-01-04T09:31:37.070Z
Show full log..
Gyan
CC BY-SA 3.0
2018-01-04T12:05:29.567Z
https://drive.google.com/open?id=1gaX3d2ccbUcNjS8TqIPBL1kRX-sB4z0y

I have put the logs here
Nagabhushan S N
CC BY-SA 3.0
2018-01-04T12:09:31.117Z
You're using an older version of ffmpeg which needs manual buffering. Change first line of filters to `[0]trim=0:3.5,drawbox=c=black,fifo[delay];[delay][0]concat,fifo[left]`
Gyan
CC BY-SA 3.0
2018-01-04T12:56:36.030Z
Got an Error
https://drive.google.com/open?id=1vgDD6T0HlR7BBaUHLdybBzlfBQnJNqyx

I installed ffmpeg today from here http://ffmpeg.org/releases/ffmpeg-3.4.1.tar.bz2. I'm running on macbook pro
Do, I need to install something else also?
Nagabhushan S N
CC BY-SA 3.0
2018-01-04T13:16:21.540Z
Get a binary from https://ffmpeg.zeranoe.com/builds/
Gyan
CC BY-SA 3.0
2018-01-04T13:42:35.960Z
Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/71182/discussion-between-nagabhushan-s-n-and-mulvya).
Nagabhushan S N
CC BY-SA 3.0
2018-01-04T16:21:26.063Z
Use `ffmpeg -i left.mp4 -i right.mp4 -i left.mp4 -filter_complex "[0]trim=0:13,drawbox=c=black:t=fill[delay];[delay][2]concat[left];[left][1]hstack[v]" -map "[v]" -map 1:a -c:a copy out.mp4` with the new binary. This is an outstanding buffer mgmt issue.
Gyan
CC BY-SA 3.0
2018-01-05T03:22:52.897Z
Error again! 
https://drive.google.com/open?id=1fRWw03VP-GlCtDJOgHcWgs5dXUnRlb4t
Nagabhushan S N
CC BY-SA 3.0
2018-01-05T06:08:53.160Z
What's the output of `ffmpeg -hide_banner -filters`
Gyan
CC BY-SA 3.0
2018-01-05T07:54:57.450Z
https://drive.google.com/open?id=13vBYu8M9wsiGXsJBTqgTB977sM7K2hlC
Nagabhushan S N
CC BY-SA 3.0
2018-01-05T09:45:59.157Z
It shows the concat filter. Rarely, there's a character coding issue when pasting to/from Stack Exchange. Retype the command at your end and run.
Gyan
CC BY-SA 3.0
2018-01-05T10:43:35.733Z
Yes. Its working perfectly fine now. Thanks a lot!
Also, I have one more request. A small extension. How to handle the below scenario. Left video should start after right video. But the length is such that left video extends after the right video ends. The current command handles this, but after right video ends, audio stops. Left video continues without audio. How to make such that after right video ends, audio should be taken from left video?
Should I ask a new question for this?
Nagabhushan S N
CC BY-SA 3.0
2018-01-05T17:26:42.903Z
Ask a new Q. It's more convoluted to switch audio like that.
Gyan
CC BY-SA 3.0
2018-01-06T08:03:47.883Z
I have asked here. https://video.stackexchange.com/q/23156/21062
Thanks!
Nagabhushan S N
CC BY-SA 3.0
2018-01-04T07:52:50.370Z
2018-01-04T09:15:14.190Z
2018-01-04T09:15:14.190Z
Gyan
<p>I have two videos of different length. I need to create a new video with one video at the left and other at the right. I tried using <a href="https://unix.stackexchange.com/a/233833/267627">this</a>. Problem is my videos are of different length. I want to start one video a few seconds after the other started. Also, I want to keep the audio of the longer video only.</p>

CC BY-SA 3.0
2018-01-04T06:21:09.163Z
Do you know which of the videos is longer?
Gyan
CC BY-SA 3.0
2018-01-04T07:36:02.790Z
Yes. I know. The right one.
Nagabhushan S N
<video><ffmpeg><video-editor>
Create splitscreen video using ffmpeg
Nagabhushan S N
# Create splitscreen video using ffmpeg

(Asked by: username_0 on 2018-01-04)

I have two videos of different length. I need to create a new video with one video at the left and other at the right. I tried using [this](https://unix.stackexchange.com/a/233833/267627). Problem is my videos are of different length. I want to start one video a few seconds after the other started. Also, I want to keep the audio of the longer video only.

**Tags:** video, ffmpeg, video-editor

> **Comments:**
> **username_1**: Do you know which of the videos is longer?  
> **username_0**: Yes. I know. The right one.  

---

## 1 answers

### Answer by username_1 on 2018-01-04. Score: 1 | Accepted answer

Use
ffmpeg -i shorter.mp4 -i longer.mp4 -filter_complex
 "[0]trim=0:3.5,drawbox=c=black[delay];[delay][0]concat[left];
  [left][1]hstack[v]"
 -map "[v]" -map 1:a -c:a copy out.mp4

where 3.5 should be replaced with the delayed start time (in seconds) of the shorter video.

> **Comments:**
> **username_0**: Awesome! But there was one missing point. Sync was proper. But the right video didn't start until the delay (13s) elapsed. Then both videos started simultaneously. In essence, I lost the first 13s of the right video  
> **username_1**: See edited cmd.  
> **username_0**: No. The update distorted. Both videos began simultaneously. After few seconds, left video paused for few seconds. Then it resumed in sync with the right video  
> **username_1**: Show full log..  
> **username_0**: https://drive.google.com/open?id=1gaX3d2ccbUcNjS8TqIPBL1kRX-sB4z0y  I have put the logs here  
> **username_1**: You're using an older version of ffmpeg which needs manual buffering. Change first line of filters to `[0]trim=0:3.5,drawbox=c=black,fifo[delay];[delay][0]concat,fifo[left]`  
> **username_0**: Got an Error https://drive.google.com/open?id=1vgDD6T0HlR7BBaUHLdybBzlfBQnJNqyx  I installed ffmpeg today from here http://ffmpeg.org/releases/ffmpeg-3.4.1.tar.bz2. I'm running on macbook pro Do, I need to install something else also?  
> **username_1**: Get a binary from https://ffmpeg.zeranoe.com/builds/  
> **username_0**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/71182/discussion-between-nagabhushan-s-n-and-mulvya).  
> **username_1**: Use `ffmpeg -i left.mp4 -i right.mp4 -i left.mp4 -filter_complex "[0]trim=0:13,drawbox=c=black:t=fill[delay];[delay][2]concat[left];[left][1]hstack[v]" -map "[v]" -map 1:a -c:a copy out.mp4` with the new binary. This is an outstanding buffer mgmt issue.  
> **username_0**: Error again!  https://drive.google.com/open?id=1fRWw03VP-GlCtDJOgHcWgs5dXUnRlb4t  
> **username_1**: What's the output of `ffmpeg -hide_banner -filters`  
> **username_0**: https://drive.google.com/open?id=13vBYu8M9wsiGXsJBTqgTB977sM7K2hlC  
> **username_1**: It shows the concat filter. Rarely, there's a character coding issue when pasting to/from Stack Exchange. Retype the command at your end and run.  
> **username_0**: Yes. Its working perfectly fine now. Thanks a lot! Also, I have one more request. A small extension. How to handle the below scenario. Left video should start after right video. But the length is such that left video extends after the right video ends. The current command handles this, but after right video ends, audio stops. Left video continues without audio. How to make such that after right video ends, audio should be taken from left video? Should I ask a new question for this?  
> **username_1**: Ask a new Q. It's more convoluted to switch audio like that.  
> **username_0**: I have asked here. https://video.stackexchange.com/q/23156/21062 Thanks!  

---

