Search code examples
ffmpegservervideo-streamingwebcamrtsp

Two USB cams to two rtsp-simple-servers simultaneously


Like in title, I have 2 USB cams and I need to create two RTSP streams. I'm using FFmpeg and rtsp-simple-server and it's working with one cam with this configuration (rtsp-simple-server.yml):

paths:
  cam:
    runOnInit: ffmpeg -f dshow -video_device_number 0 -i video="UVC Camera" -c:v libx264 -preset ultrafast -tune zerolatency -b:v 600k -f rtsp rtsp://192.168.5.203:8554/cam
    runOnInitRestart: yes

but I can't figure it out with second cam. I tried to make second instance of rtsp-simple-server in separete console and it doesn't work. I set it up like this (and few other ways with different port etc.):

paths:
  cam:
    runOnInit: ffmpeg -f dshow -video_device_number 1 -i video="UVC Camera" -c:v libx264 -preset ultrafast -tune zerolatency -b:v 600k -f rtsp rtsp://192.168.5.203:8555/cam2
    runOnInitRestart: yes

I get this error as result: Only one use of each socket address (protocol / network address / port) is allowed. and I still think there is better way to solve this with proper configuration.

I hoping for your help!


Solution

  • That was easy, it's working:

    paths:
      cam1:
        runOnInit: ffmpeg -f dshow -video_device_number 0 -i video="UVC Camera" -c:v libx264 -preset ultrafast -tune zerolatency -b:v 600k -f rtsp rtsp://192.168.5.203:8554/cam1
        runOnInitRestart: yes
      cam2:
        runOnInit: ffmpeg -f dshow -video_device_number 1 -i video="UVC Camera" -c:v libx264 -preset ultrafast -tune zerolatency -b:v 600k -f rtsp rtsp://192.168.5.203:8554/cam2
        runOnInitRestart: yes
    

    Now I wonder how to reduce latency with this setup, so if you have any suggestions feel free to reply here!