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

How to convert RTSP to MJPEG #1018

Open ldct-polemos opened 3 months ago

ldct-polemos commented 3 months ago

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!

Scrounger commented 2 months ago

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 -
AlexxIT commented 2 months ago

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.