nanosonde / sip2rtsp

A SIP client that provides two-way audio streams to gstreamer RTSP server with ONVIF backchannel support
MIT License
15 stars 4 forks source link

How can I use RTSP H265? #9

Closed whitetiger21022014 closed 1 year ago

whitetiger21022014 commented 1 year ago

Hello, Could you let me know how can I use rtsp H265 (I don't need to use ffmpeg tool to transcode from H265 to H264)? Thanks you

nanosonde commented 1 year ago

Hi @whitetiger21022014 ! So what you want is to do the same thing, but with H265 instead of H264? I assume that your camera already provides an H265 stream, right?

The launch_string config.yaml parameter for H264 looks like this ith re-encoding:

rtspsrc location=rtsp://10.10.10.10:8554/gartentor_h264_ext name=rtspsrc ! decodebin ! videoconvert ! videoscale ! videorate ! video/x-raw,format=I420,width=1280,height=720,framerate=15/1 ! x264enc bitrate=2000 speed-preset=superfast tune=zerolatency key-int-max=60 ! rtph264pay config-interval=1 name=pay0 pt=96 pulsesrc device="BaresipSpeakerInput" do-timestamp=true ! queue ! audioconvert ! audioresample ! audio/x-raw,format=S16LE,channels=1,rate=8000 ! opusenc ! rtpopuspay name=pay1

This launch_string will select only the video stream from the RTSP camera. The decodebin element would automatically select the required decoder. Later the stream is re-encoded to H264 using x264enc. Audio is selected from the SIP client's speaker and encoded to OPUS.

First I would suggest that you experiment with a gstreamer pipeline to get a working H265 video stream without audio from the gstreamer RTSP server. I presume that you do not want to re-encode (with x265enc) the H265 stream, right?

rtspsrc location=rtsp://<IP>:8554/h265_stream name=rtspsrc ! parsebin ! rtph265pay config-interval=1 name=pay0 pt=96

Later one could add audio again: rtspsrc location=rtsp://<IP>:8554/h265_stream name=rtspsrc ! parsebin ! rtph265pay config-interval=1 name=pay0 pt=96 pulsesrc device="BaresipSpeakerInput" do-timestamp=true ! queue ! audioconvert ! audioresample ! audio/x-raw,format=S16LE,channels=1,rate=8000 ! opusenc ! rtpopuspay name=pay1

nanosonde commented 1 year ago

Forgot one thing to add: the RTSP server is independent from the ONVIF server. The ONVIF server just describes what the RTSP server will deliver. The ONVIF server included in this repo just has some H264 stuff hard-coded. To really announce H265 support to an ONVIF client we would also have some small additions here: https://github.com/nanosonde/sip2rtsp/blob/main/pyonvifsrv/service_media.py (Search for H264 in this file and you will get an impression what to do)

nanosonde commented 1 year ago

Another launch_string that you could try for H265 without reencoding could be (untested):

rtspsrc location=rtsp://<IP>:8554/h265_stream name=rtspsrc ! transcodebin profile=video/x-h265 avoid-reencoding=true ! rtph265pay config-interval=1 name=pay0 pt=96

nanosonde commented 1 year ago

Just tried this on the command line:

gst-launch-1.0 rtspsrc protocols=tcp location=rtsp://<user>:<pwd>@10.10.10.41:554//h265Preview_01_main name=rtspsrc ! parsebin ! rtph265pay config-interval=1 name=pay0 pt=96 ! fakesink

This could work.

nanosonde commented 1 year ago

The corresponding launch_string looks like this:

launch_string: rtspsrc protocols=tcp location=rtsp://<user>:<pwd>@10.10.10.41:554//h265Preview_01_main name=rtspsrc ! parsebin ! rtph265pay config-interval=1 name=pay0 pt=96

Without audio so far.

nanosonde commented 1 year ago

With audio from SIP: Use this in config.yaml:

launch_string: rtspsrc protocols=tcp location=rtsp://<user>:<pwd>@10.10.10.41:554//h265Preview_01_main name=rtspsrc ! parsebin ! rtph265pay config-interval=1 name=pay0 pt=96 pulsesrc device="BaresipSpeakerInput" do-timestamp=true ! queue ! audioconvert ! audioresample ! audio/x-raw,format=S16LE,channels=1,rate=8000 ! opusenc ! rtpopuspay name=pay1