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.77k stars 307 forks source link

Tuya HLS stream can be played on VLC but not on go2rtc #1152

Open felipecrs opened 1 month ago

felipecrs commented 1 month ago

I created this script:

https://github.com/felipecrs/get-tuya-webrtc-configs/blob/master/get_tuya_stream_url.sh

It can be used to get the Tuya stream URL without needing the Tuya integration in Home Assistant.

It works fine and has both RTSP and HLS mode.

However, my brother has 2 Tuya cameras for which the stream does not work in Home Assistant (apparently https://github.com/home-assistant/core/issues/68503). Then, making some tests with it, I noticed that camera's stream cannot be played through RTSP, but only HLS. This must be why it is not working in HA itself, because the HA integration always asks for a RTSP stream.

The HLS stream generated by such script for such camera looks like below:

streams
  tuya_1:
    - echo:/config/scripts/get_tuya_stream_url.sh hidden hidden hidden https://openapi.tuyaus.com HLS
https://aws-tractor2.tuyaus.com:8033/hls/03d62ef0e27f487ea335c06f48ece15e81acf8fb8aec1b1c.m3u8

It expires after some time.

image

The stream can be played just fine on VLC, no interruptions. With audio.

https://github.com/AlexxIT/go2rtc/assets/29582865/b525369d-d48f-4975-ad82-da257d7575a8

To be honest, sometimes it does not play and stays like this:

https://github.com/AlexxIT/go2rtc/assets/29582865/f675139d-c40f-4370-a834-4e765386c6a2

But on go2rtc no matter what the stream won't play. Through MSE or through WebRTC.

https://github.com/AlexxIT/go2rtc/assets/29582865/aeb13f82-5960-41ea-8171-15618c76a4e9

I only see this in the logs:

undefined error=EOF url=echo:/config/scripts/get_tuya_stream_url.sh hidden hidden hidden https://openapi.tuyaus.com HLS caller=github.com/AlexxIT/go2rtc/internal/streams/producer.go:171

If go2rtc could play this stream, my brother's camera could finally be useful for something. The camera is actually nice, it's very small and 5V. Good for internal use.

Please let me know if you have any idea, or in case you want to have access to such stream. I can provide you access.

AlexxIT commented 1 month ago

You should try echo ffmpeg source. Go2rtc has not best HLS client

felipecrs commented 1 month ago

Like this?

echo -n "ffmpeg:${url}#video=copy#audio=copy"

The following error shows up in the player:

image

image

Not sure if I am doing something wrong.

felipecrs commented 1 month ago

Oh, fixed that with:

echo -n "ffmpeg:${url}#video=copy#audio=opus"
felipecrs commented 1 month ago

Ok, now I tried with:

echo -n "ffmpeg:${url}#video=h264#hardware=vaapi#audio=aac#audio=opus"

But the stream is behaving exactly like before.

Looks like not even ffmpeg is able to play this stream correctly. Maybe it is a matter of tweaking some flags though.