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.85k stars 392 forks source link

Using go2rtc to play recordings [question] #1104

Open cuervodelviento opened 5 months ago

cuervodelviento commented 5 months ago

So I have been fiddling a bit with the go2rtc to support playing streams from NVR's that support it, so far I got it to work by adding:

Require: onvif-replay Range: clock=20240507T203746Z-20240507T203756Z

to the PLAY request

PLAY rtsp://192.168.1.205:565/PlaybackChannel/3/media.smp/ RTSP/1.0
Authorization: Digest username="admin", realm="iPolis", nonce="00000000000000000000000000093D36", uri="rtsp://192.168.1.205:565/PlaybackChannel/3/media.smp/", response="7b2dabc05c1613df4e09ef8a155c3a57"
Session: 32607
Require: onvif-replay
Range: clock=20240507T203746Z-20240507T203756Z
CSeq: 4

I was working on an old version of go2rtc, it was 1.5.0 but the playback was broken (using own go2rtc player). I updated to 1.9.1 ahd the playback now works on h264 but on h265 is not working, any place I should pay attention to?

(the livestream from the same source works in h265, but I'm assume that there may be any variants)

I also saw something about custom headers, is that for NVRs that supports them (i.e. the clock range is handled by the device and not in the PLAY request) or it can also add headers to the PLAY command?

I can provide Wireshark captures of a playback working with h264 and one stuck on h265 if you are interested on checking it out.

Thanks in advance for any guidance

AlexxIT commented 5 months ago

I haven't dealt with it. I don't know why it worked before and doesn't work now.

cuervodelviento commented 5 months ago

the h264 decoding(?) wasn't working on 1.5.0 (h265 wasn't working either) now in 1.9.1 h264 decoding is working, but h265 still doesn't work, I guess the h264 decoding working now is a byproduct on one enhancement that was done to it, thanks for your reply, this repo is amazing

AlexxIT commented 5 months ago

There have been a lot of changes between these versions. I don't plan to support non-standard headers like Range anytime soon. If you have issues with H265 in the regular version of go2rtc, I'm ready to examine the dumps.

cuervodelviento commented 5 months ago

Disclaimer: I'm aware that is not within the scope of the project and any reply I get is just you going out of your way and don't need to reply but I think that maybe having this discussion here may help others that are using your software to play recordings.

I'm querying an NVR, turns out that the issue is not encoding.

The NVR is replying with several tracks available, some of those tracks don't have any video, I'm trying to play the h265 track that is in fact empty, the h264 is the one that has data, but it wasn't setup, I tried setting it up along with the h265 track but got lost whens setting the trackID. Now how I'm testing it's from this link, so Chrome sends this-> image which is correct, basically there is no video on the h265 track so no data to be received. Edge will send this (h264 support) image and I get video. what I want is to have the play fallback to h264 (or well, to another one of the tracks) the main issue is that PLAY doesn't give any error, but instead doesn't return any data. (ideally, the NVR should reply with 702 when querying for a recording that doesn't exist, but this one does, but not in all tracks).

I was thinking on how should I proceed with this? should I set a certain timeout and then switch the track?

I'm doing my testing from the MSE stream link. image

AlexxIT commented 5 months ago

go2rtc has no mechanisms that will select a different track if there are problems with the first track.