AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
4.14k stars 336 forks source link

select stream based on RTSP Extra parameter #1248

Open Dieghito72 opened 1 month ago

Dieghito72 commented 1 month ago

Hi, is possible to select the stream based on RTSP extra parameter like ?channel=X?

I have a Dahua indoor unit that automatically generate the URL based on IP/PORT/channel ID configuration, the idea is to referer different streams in go2rtc based on channel ID.

The URL used by the Dahua unit is in the form: rtsp://USER:PASSWORD@IP/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif

Actually I was able to show only one stream by configuring a stream called cam/realmonitor in go2rtc:

cam/realmonitor: ffmpeg:camera.giardino_sub#video=h264#width=1280#height=720#audio=copy#hardware

AlexxIT commented 1 month ago

I don't understand you. You probably refer to some Hass entity camera.giardino_sub. How does it set the URL?

Dieghito72 commented 1 month ago

Sorry for the confusion, let me try to explain better...

Here is part of my go2rtc configuration:

streams:
  camera.cancello_sub: rtsp://XXX:XXX@192.168.1.200:554/cam/realmonitor?channel=1\u0026subtype=1
  camera.garage_sub: rtsp://XXX:XXX@192.168.1.191:554/Preview_01_sub
  camera.giardino_sub: rtsp://XXX:XX@192.168.1.108:554/Preview_01_sub

  cam/realmonitor: ffmpeg:camera.giardino_sub#video=h264#width=1280#height=720#audio=copy#hardware/

Streams named camera.XX are provided by different cams. I would like to view these streams in a Dahua indoor unit (since this unit support camera visualization) but, unfortunately these streams are not in the correct format for the Dahua indoor unit, so I used ffmpeg to transcode video to correct resolution and here comes the stream cam/realmonitor.

In the Dahua indoor unit I configured a RTSP cam that points to the go2rtc server, since the URL used by the indoor unit is rtsp://USER:PASSWORD@go2rtc server IP/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif I obtained the transcoded stream cam/realmonitor provided by go2rtc (this is great 🥇 ).

I would like to visualize also the other cams, but unfortunately I cannot customize the URL provided by the Dahua indoor unit, I can only customize the channel that the unit provide as URL parameter ?channel=X to go2rtc.

So the idea was to obtain different stream in go2rtc based on ?channel=X parameter of the request... something like:

streams:
  camera.cancello_sub: rtsp://XXX:XXX@192.168.1.200:554/cam/realmonitor?channel=1\u0026subtype=1
  camera.garage_sub: rtsp://XXX:XXX@192.168.1.191:554/Preview_01_sub
  camera.giardino_sub: rtsp://XXX:XX@192.168.1.108:554/Preview_01_sub

  cam/realmonitor**?channel=1**: ffmpeg:camera.giardino_sub#video=h264#width=1280#height=720#audio=copy#hardware/
  cam/realmonitor**?channel=2**: ffmpeg:camera.garage_sub#video=h264#width=1280#height=720#audio=copy#hardware/
  cam/realmonitor**?channel=3**: ffmpeg:camera.cancello_sub#video=h264#width=1280#height=720#audio=copy#hardware/

I have already tried something as above without success...

Thank you for your attention and your hard work on this great project.

AlexxIT commented 1 month ago

It's not an easy task. I'll think about it