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
3.74k stars 304 forks source link

USB webcam gives "WRN [hls] can't get init id=XXXXXXX" with every start/refresh but still works #1166

Open puterboy opened 3 weeks ago

puterboy commented 3 weeks ago

I am using a IMC Networks XHC Camera 720p USB 3.9mm endoscope cam. My go2rtc.yaml looks like this:

  usbcam_h264:
   - ffmpeg:device?video=/dev/v4l/by-id/usb-9734-20210906_HD_Camera-video-index0&input_format=yuyv422&video_size=1280x720#video=h264#hardware

Everything works except that I get following warning messages on the console:

10:46:00.981 WRN [hls] can't get init id=aGjt0avg
10:46:05.048 WRN [hls] can't get init id=aGjt0avg
10:47:05.813 WRN [hls] can't get init id=QsBUycxh
10:53:28.707 WRN [hls] can't get init id=0iAXBdmO
10:53:32.731 WRN [hls] can't get init id=0iAXBdmO
10:53:35.476 WRN [hls] can't get init id=Ak3r3aRR
10:53:39.708 WRN [hls] can't get init id=Ak3r3aRR
10:53:45.994 WRN [hls] can't get init id=1XZ1e20Z
10:53:50.808 WRN [hls] can't get init id=1XZ1e20Z
10:53:57.935 WRN [hls] can't get init id=MavhdMun
10:54:00.431 WRN [hls] can't get init id=d1l4Qly5
10:55:00.207 WRN [hls] can't get init id=p2mdYoSQ

The messages seem to occur often (but not always) when the stream is started or refreshed. I also notice that this stream seems to take longer to start than my PiCamera v3 stream.

Any idea what is causing this warning and what to do about it?

AlexxIT commented 3 weeks ago

That means the stream from the camera didn't start in 3 seconds.

puterboy commented 3 weeks ago

Ahhh -- that is consistent with the delay behavior I am seeing, though might be helpful to make the WRN message more self-explanatory.

Also, any ideas why the USB webcam takes so long to start? Is there anything I can do to reduce the delay or is this a "camera" issue? (note my RPi5 is lightly loaded so it shouldn't be a CPU issue)

puterboy commented 3 weeks ago

I did some more investigating of the init id=XXXXXX warning.

It seems like the camera delay is causing Octoprint-Obico to fail to load the camera. Octoprint log shows the following error message generated by ffmpeg FFMPEG command (called from python)

ffmpeg -loglevel error -re -i http://192.168.1.048:1984/api/stream.m3u8?src=usbcam_h264&mp4 -filter:v fps=15 -b:v 944438 -pix_fmt yuv420p -s 640x360 -c:v libx264 -an -f rtp rtp://127.0.0.1:17735?pkt_size=1300

FFMPEG STDERR:

[hls @ 0xb0bea90] Error when loading first segment 'http://192.168.1.048:1984/api/hls/segment.m4s?id=z5TYEApf&n=0'
[in#0 @ 0xb0be830] Error opening input: Server returned 404 Not Found
Error opening input file http://192.168.1.048:1984/api/stream.m3u8?src=usbcam_h264&mp4.
Error opening input files: Server returned 404 Not Found

In turn, the ffmpeg process terminates with exit code 8.

If the issue is due to camera not starting in 3 seconds, is there a way to set a longer delay? Or is there an option to ffmpeg to tell it to be patient and not fail?

Note the elongated delay may be because it seems like this camera needs to launch a "helper" ffmpeg process spawned by go2rtc.

ffmpeg -hide_banner -v error -f v4l2 -input_format yuyv422 -video_size 1280x720 -i /dev/v4l/by-id/usb-9734-20210906_HD_Camera-video-index0 -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency -pix_fmt:v yuv420p -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/ceeeb28d257d2f320d221087a05b29c4

So, is there a way to tell ffmpeg to be patient and wait before terminating...

AlexxIT commented 3 weeks ago

I don't know any reason for using HLS as FFmpeg input. It's not real time format

puterboy commented 2 weeks ago

Unfortunately, my understanding is that the only h264 that Octoprint works well with is HLS. WebRTC doesn't work well yet and not aware of any other h264 streaming that does.

AlexxIT commented 2 weeks ago

Your tests wrong. HLS just can't be only working format.

puterboy commented 2 weeks ago

I WISH you were right! Webrtc is "experimental" in Octoprint and doesn't work with many streamers. I tried the link go2rtc offers and it fails to work. I tried all the following variations on the link url:

mypi:1984/stream.html?src=picam_h264&mode=webrtc
webrtc://mypi:1984/stream.html?src=picam_h264&mode=webrtc
http://mypi:1984/stream.html?src=picam_h264&mode=webrtc

None of them worked and I was told to try hls

I am happy to try anything...

AlexxIT commented 2 weeks ago

All this links wrong. I don't know where you get them.

puterboy commented 2 weeks ago

I got the links from the 'links' page on YOUR app: http://mypi:1984/links.html?src=picam_h264 The link it gives for webrtc is

[stream.html](http://mypi:1984/stream.html?src=picam_h264&mode=webrtc) WebRTC stream / browsers: all / codecs: H264, PCMU, PCMA, OPUS / +H265 in Safari

I tried it as above as well as without the http:// prefix and as well as with a webrtc: prefix. Nothing worked in Octoprint -- though it worked fine when typed into my browser so links themselves seem good.

Am I doing something stupid?

AlexxIT commented 2 weeks ago

.html links only for browser

puterboy commented 2 weeks ago

Ahhhh... Well, I now tried all the below but STILL doesn't work in Octoprint (though works in my browser as well as mplayer app)

http://mypi:1984/api/stream.mp4?src=picam_h264&mp4=flac
http://mypi:1984/api/stream.mp4?src=picam_h264&mp4
http://mypi:1984/api/stream.mp4?src=picam_h264

Also tried with 'http' replaced with 'webrtc' but didn't help.

Would really love to get go2rtc work with Octoprint with Webrtc but it just doesn't seem to work. I really think go2rtc should be the DEFAULT streamer for Octopi/Octoprint if it can work since it seems so otherwise clean...

AlexxIT commented 2 weeks ago

I have never seen Octoprint. And don't know how to help you.

puterboy commented 2 weeks ago

I understand. Thanks for your help. BTW, Octoprint is the goto interface app for 3D-printing and as such is very popular.

I wish I could encourage use of your AWESOME streamer with Octoprint but if I can't get it working, I will need to try another streamer.