VLC mosaic for multiple RSTP streams

Recently had a task to open streams from 4 cameras over RSTP in a single windows using VLC. There is a bunch of howtos on net with relevant info and examples, but after trying many options non of them worked out of the box. Tweaking things here and there for a while I managed to come up with the working configuration, so I post it here for future reference and hopefully it will be helpful to anyone else.

My cameras stream dimensions is 1280×720 and as I want to fit 4 cameras on one screen, I will scale them in half to have screen size 1280×720 and each stream size 64×360.

First thing to do is to create some background image with exact size of the desired screen (1280×720 in my case) and save somewhere near (bg.jpg in my case).

Then we need to create a VLM config file (let it be cam.vlm.conf) to tell VLC about my streams and how to deal with them:

new channel1 broadcast enabled                                                       
setup channel1 input "rtsp://x.x.x.x:554/?user=foo&password=bar&channel=1&stream=0.sdp"
setup channel1 output #mosaic-bridge{id=1,height=360,width=640}

new channel2 broadcast enabled                                                       
setup channel2 input "rtsp://x.x.x.y:554/?user=foo&password=bar&channel=1&stream=0.sdp"
setup channel2 output #mosaic-bridge{id=2,height=360,width=640}

new channel3 broadcast enabled                                                       
setup channel3 input "rtsp://x.x.x.z:554/?user=foo&password=bar&channel=1&stream=0.sdp"
setup channel3 output #mosaic-bridge{id=3,height=360,width=640}

new channel4 broadcast enabled                                                       
setup channel4 input "rtsp://x.x.x.w:554/?user=foo&password=bar&channel=1&stream=0.sdp"
setup channel4 output #mosaic-bridge{id=4,height=360,width=640}

new mosaic broadcast enabled
setup mosaic input file:///home/user/Pictures/bg.jpg
setup mosaic option image-duration=-1
setup mosaic option image-fps=0
setup mosaic option mosaic-rows=2
setup mosaic option mosaic-cols=2
setup mosaic option mosaic-position=1
setup mosaic output #transcode{sfilter=mosaic,vcodec=mp4v,vb=8500,acodec=none,fps=25,scale=1}:display

control channel1 play
control channel2 play
control channel3 play
control channel4 play
control mosaic play

The input path to the camera streams as well as full path to the background image should be adjusted accordingly.

Somehow VLC doesn’t want to recognize mosaic-(height|width|order) parameters in the VLM file, so need to supply them inline as arguments when calling VLC. Now as we have VLM file ready, we can start the stream with the following command:

cvlc --vlm-conf /home/user/Desktop/cam.vlm.conf --mosaic-width 1280 --mosaic-order "1,2,3,4" --mosaic-height 720

Adjust the path to the VLM file accordingly as well as mosaic order or whatever else you want. For me all of the above worked out perfectly well and I can see all my 4 cameras in single window.

6 thoughts on “VLC mosaic for multiple RSTP streams”

  1. Hello.
    Can you explain where to write the command “cvlc –vlm-conf /home/user/Desktop/cam.vlm.conf –mosaic-width 1280 –mosaic-order” 1,2,3,4 ” -mosaic-height 720 “?
    You say “when you call VLC”.
    Does this mean you have to add this command somewhere in the software shortcut?
    Thank you.
    – – – – –
    Bonjour.
    Pouvez-vous expliquer a quel endroit écrire la commande “cvlc –vlm-conf /home/user/Desktop/cam.vlm.conf –mosaic-width 1280 –mosaic-order “1,2,3,4” –mosaic-height 720″ ?
    Vous dite “quand on appel VLC”.
    Cela veux dire qu’il faut ajouter cette commande quelque part dans le raccourcis du logiciel?
    Merci.

  2. this is what I was looking for.

    I need to mosaic for 16 inputs all are udp:// streams. All are on my local network so that I do not want to transcode in different codec.

    Is that possible if I can see all of them in 16 windows without codec conversion. so video should not freeze

  3. If I had 1920×1080 cameras to work with, what would in the code provided above? Would the height and width of the streams need to be changed as well as the bg.png file?

  4. Все равно не понятно, делаю все, как вы пишете, но плеер просто открывается, как обычно… подскажите, что значит слово “cvlc”? и правильно ли я делаю : я запускаю командную строку, указываю путь программы, и далее ввожу все эти параметры?

    1. У меня всё это работало под линуксом, где была отдельная командна cvlc в добавок к обычной vlc.
      Сдается мне у вас винда и там видимо всё подругому.

      Быстро погуглив нашел вот эту статью https://superuser.com/questions/947116/how-do-i-use-vlc-command-line-in-windows-batch-line-without-showing-gui

      Там говорится что вместо cvlc под виндой надо запускать vlc -I dummy –dummy-quiet {path_to_file}

Leave a Reply to cedric malignon Cancel reply