go2rtc
go2rtc copied to clipboard
How to convert RTSP to MJPEG
Hi all,
I have a web application that for historical reasons can accept only MJPEG format, server-size pushed, with the famous "img" tag.
Basically the browser issues an HTTP request and then it pretends that the server responds with a multipart content type:
"Content-Type", "multipart/x-mixed-replace; boundary=--someboundary"
Such response ends only when browser closes connection. Early millennium stuff.
Now I would like to stream contents from a camera that produces RTSP (in the example below I'm simulating it locally with a gstreamer pipe). I'm able to visualize the stream via WebRTC module by using this config:
...
rtsp:
listen: ":8553" #just to avoid issue with gstreamer pipe listening on 8554
username: ""
password: ""
...
...
streams:
camerah264: rtsp://127.0.0.1:8554/test
This correctly works in Chrome. Then I tried to follow the transcoding guidelines for MJPEG and changed the config as follows:
streams:
- camerah264: rtsp://127.0.0.1:8554/test
- cameramjpegconverted: ffmpeg:camerah264#video=mjpeg]
But once I try to open
http://localhost:1984/stream.html?src=cameramjpegconverted&mode=mjpeg
I get the following error:
ERR github.com/AlexxIT/go2rtc/internal/mjpeg/init.go:166 > error="streams: EOF"
I also tried this:
streams:
camera1:
- rtsp://127.0.0.1:8554/test
- ffmpeg:camera1#video=mjpeg
And by opening
http://localhost:1984/stream.html?src=camera1&mode=mjpeg
I get:
ERR github.com/AlexxIT/go2rtc/internal/mjpeg/init.go:166 > error="streams: codecs not matched: H264 => JPEG"
What can be the problem?
Thanks and congrats for the great project!
This works for me. But this only an example, ffmepg parameter should be optimized
streams:
Test:
- exec:ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i "rtsp://XXXXXXX" -c:v mjpeg -q:v 1 -f mpjpeg -an -
In first config you have list inside streams section. This is wrong. Also you have bracket at the end - also wrong.
Second config right. Are you sure it's not working? You can increase log level to trace and check why ffmpeg can't start.
Sorry for the delay. I totally forget to mention that the source uses h264 codec over rtsp. Hence the error "not matched h264 mjpeg". So actually I have two questions:
- how to convert such h264 over rtsp to http(s) mjpeg?
- would it be possible for go2rtc to proxy the rtsp stream to webrtc? As far as I understood webrtc is the best option to have low latency streaming on a browser
- https://github.com/AlexxIT/go2rtc?tab=readme-ov-file#source-ffmpeg
- https://github.com/AlexxIT/go2rtc?tab=readme-ov-file