4

I am investigating a possibility to store video streams which are coming from few sources already coded in h264 without video transcoding as the device I would like to use for this project won't be capable of transcoding combined video on the fly.

What I am looking for is two or more pictures side to side (not video concatenation) packed into mp4/avi/mkv.

I believe mkv container supports such kind of packaging but I've not been able to find appropriate options for ffmpeg or other tool to store it this way. What it does is very slow video transcoding into one big h264 stream.

Scath
  • 3,777
  • 10
  • 29
  • 40
Serg Fillipenko
  • 141
  • 1
  • 2
  • 2
    The MPEG container also supports more than one TS (transport stream) in one file with different properties. But congrats on your choice of MKV, it's better and easier to parse. – zx485 May 23 '18 at 17:08

2 Answers2

7

If your player can handle it just make it perform the side-by-side view. No encoding or muxing required.

mpv video player

enter image description here

Example using mpv:

mpv --lavfi-complex="[vid1][vid2]hstack[vo];[aid1][aid2]amix[ao]" input1.mp4 --external-file=input2.mp4

The above example assumes each input has the same height. Otherwise you will have to add the scale, scale2ref, pad, and/or crop filters. Simple example using the crop filter to remove 20 pixels from the height:

mpv --lavfi-complex="[vid1]crop=iw:ih-20[c];[c][vid2]hstack[vo];[aid1][aid2]amix[ao]" input1.mp4 --external-file=input2.mp4

See the mpv documentation and FFmpeg Filters for more info.

llogan
  • 121,796
  • 28
  • 232
  • 243
4

Just specify multiple inputs.

ffmpeg -i [input 1] -i [input 2] ... -map 0 -map 1 ... -codec copy -f matroska [output]

As for the "side-to-side" part, it's up to the player to determine the presentation. If you don't control the player and you need a specific layout or presentation, then you must "burn" all these video streams into a new one and encode it as a new single stream.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • 1
    In this case you will need to include the `-map` option to manually select the desired streams, such as `-map 0 -map 1`, because the [default stream selection behavior](https://ffmpeg.org/ffmpeg.html#Stream-selection) will only select one stream per stream type. Also, `-f` is not required (but if it were needed the proper value is `matroska`, not `mkv`). – llogan May 23 '18 at 17:59
  • @LordNeckbeard Valid points, thanks. Also, I specify `-f` because I'm usually outputting to STDOUT as a stream. – Brad May 23 '18 at 18:17
  • -codec copy appends second stream to the end instead of forcing VLC to play it in parallel. -map doesn't change the behaviour. – Serg Fillipenko May 24 '18 at 12:49
  • @SergFillipenko Setting the codec doesn't change anything like this. All this does is put two streams in the same output. And, they should be interleaved. – Brad May 24 '18 at 15:20