<p>'map' selects input sources, files in this case. Your command combines all the tracks into a single stream, not separate ones as desired.</p>

CC BY-SA 4.0
2020-03-20T04:51:55.423Z
The command in @SaaruLindestakke answer keeps them as separate streams. `map` does not combine streams; it can only select input **streams** (not files).
Gyan
CC BY-SA 4.0
2020-03-19T18:59:18.970Z
2020-03-19T18:59:18.970Z
Hewey Dewey
<p>Yes, this is possible using ffmpeg and the <code>mkv</code> container.</p>

<p>An example command sequence would be:</p>

<pre><code>ffmpeg -i input1 -i input2 -c copy -map 0 -map 1 output.mkv
</code></pre>

<p><sub><a href="http://ffmpeg.gusari.org/viewtopic.php?f=12&amp;t=828">source</a></sub></p>

<p>Breaking down the command:</p>

<ul>
<li><code>-i input1</code> This selects the first input file. Could be something like my <code>video_track1.mov</code>.</li>
<li><code>-i input2</code> Here you can specify the second input file. You can add another entry <code>-i input3</code> if you have more input videos. I don't know what the maximum amount of videos is you can place in one <code>mkv</code> container.</li>
<li><code>-c copy</code> This copies all the streams (audio and video) in their original encoding.</li>
<li><code>-map 0</code> This maps all the streams (audio and video) of the first input file to the first track of the output file.</li>
<li><code>-map 1</code> This maps all the streams (audio and video) of the second input file to the second track of the output file.</li>
</ul>

<p>More information on the <code>-map</code> option can be found <a href="http://ffmpeg.org/ffmpeg.html#Advanced-options">in the documentation of ffmpeg</a>.</p>

CC BY-SA 3.0
2014-10-21T07:22:10.070Z
Thank you Bart. Just a quick follow-up question if I may. Suppose the 2nd video is a bit shorter than the 1st video I want to combine, is there any way I can offset at which point the second stream should be available (eg. 1 second later), to keep the two streams in sync?
Zuiq Pazu
CC BY-SA 3.0
2014-10-21T07:56:04.397Z
Not sure, I'm not an expert, just a happy Googler, but you could experiment with the [`-ss` option](https://trac.ffmpeg.org/wiki/Seeking%20with%20FFmpeg#Cuttingsmallsections). Please edit your question with the addition and add an answer yourself including the ffmpeg code if you find that it works. This will help future visitors.
Saaru Lindestøkke
CC BY-SA 4.0
2022-08-16T13:43:19.057Z
This almost worked, but my input video didnt have timestamps. I created them with `ffmpeg -fflags +genpts -i input1_no_ts.avi -c copy input1.mp4` and `ffmpeg -fflags +genpts -i input2_no_ts.avi -c copy input2.mp4`
user27221
CC BY-SA 3.0
2014-10-20T15:43:56.437Z
2014-10-20T15:53:10.687Z
2014-10-20T15:53:10.687Z
Saaru Lindestøkke
<p>So I have multiple videos of the same scenery from different angles. These are stored as separate files. Can I combine these as multiple video streams within one file? </p>

<p>For example I know this is possible with MKV, I just don't know how to "join" them.</p>

<p>Is this possible using <em>ffmpeg</em>? If so, which command sequence do I use?
If not, what other application would be able to do this?</p>

<video><editing><ffmpeg>
Combine multiple videos as separate streams in one mkv file
Zuiq Pazu
# Combine multiple videos as separate streams in one mkv file

(Asked by: username_0 on 2014-10-20)

So I have multiple videos of the same scenery from different angles. These are stored as separate files. Can I combine these as multiple video streams within one file?

For example I know this is possible with MKV, I just don't know how to "join" them.

Is this possible using *ffmpeg*? If so, which command sequence do I use?
If not, what other application would be able to do this?

**Tags:** video, editing, ffmpeg


---

## 2 answers

### Answer by username_3 on 2014-10-20. Score: 16 | Accepted answer

Yes, this is possible using ffmpeg and the mkv container.
An example command sequence would be:
ffmpeg -i input1 -i input2 -c copy -map 0 -map 1 output.mkv

source
Breaking down the command:

-i input1 This selects the first input file. Could be something like my video_track1.mov.
-i input2 Here you can specify the second input file. You can add another entry -i input3 if you have more input videos. I don't know what the maximum amount of videos is you can place in one mkv container.
-c copy This copies all the streams (audio and video) in their original encoding.
-map 0 This maps all the streams (audio and video) of the first input file to the first track of the output file.
-map 1 This maps all the streams (audio and video) of the second input file to the second track of the output file.

More information on the -map option can be found in the documentation of ffmpeg.

> **Comments:**
> **username_0**: Thank you Bart. Just a quick follow-up question if I may. Suppose the 2nd video is a bit shorter than the 1st video I want to combine, is there any way I can offset at which point the second stream should be available (eg. 1 second later), to keep the two streams in sync?  
> **username_3**: Not sure, I'm not an expert, just a happy Googler, but you could experiment with the [`-ss` option](https://trac.ffmpeg.org/wiki/Seeking%20with%20FFmpeg#Cuttingsmallsections). Please edit your question with the addition and add an answer yourself including the ffmpeg code if you find that it works. This will help future visitors.  
> **username_4**: This almost worked, but my input video didnt have timestamps. I created them with `ffmpeg -fflags +genpts -i input1_no_ts.avi -c copy input1.mp4` and `ffmpeg -fflags +genpts -i input2_no_ts.avi -c copy input2.mp4`  

---

### Answer by username_1 on 2020-03-19. Score: -1

'map' selects input sources, files in this case. Your command combines all the tracks into a single stream, not separate ones as desired.

> **Comments:**
> **username_2**: The command in @SaaruLindestakke answer keeps them as separate streams. `map` does not combine streams; it can only select input **streams** (not files).  

---

