RTSP cam in octoprint workaround

Hi guys, I was struggling with rtsp cam in octoprint for some time and today I've found good solution. All is done one machine where octoprint is.

Build this https://github.com/horgh/videostreamer
Then run it

/path/to/Go/bin/videostreamer -input rtsp://camIP/stream_name -fcgi=false -format

in octoprint's settings set cam url to http://octopi_ip:8080/stream

Last step is to modify template at /home/pi/OctoPrint/venv/lib/python2.7/site-packages/octoprint/templates/tabs/control.jijnja2
at line 17 change this

<img id="webcam_image" data-bind="css: { flipH: settings.webcam_flipH(), flipV: settings.webcam_flipV() }, event: { load: onWebcamLoaded, error: onWebcamErrored }, visible: !webcamError()">

to this

<video style="width: 100%" autoplay id="webcam_image" data-bind="css: { flipH: settings.webcam_flipH(), flipV: settings.webcam_flipV() }, event: { load: onWebcamLoaded, error: onWebcamErrored }, visible: !webcamError()"></video>

If you use dashboard plugin you need to modify its template too.

2 Likes

Instead of modifying the code you could use this plugin I wrote that replaces the img tag with an iframe maybe.

1 Like

That is exactly what i was looking for.
Just got a cheap cam and found out it only supports rtsp and no http streams. Spend quite some time :smiley:
As soon as my print finishes i will try this out.
Really looking forward to this, thanks.

You may want to look over at this post. It is re-encoding rtsp stream into mjpg to work with OctoPrint by default.

1 Like

I'm really struggeling right now.
Installed everything and it should work.
Which ip should i use? I tried the loopback ip and the ip of my pi.
The rtsp link is correct, i tried it before several times.

I don't know where the problem ist.
The output is always the same:
"Waiting for clients..."
"Starting to serve requests on 0.0.0.0:8080 (Fast CGI)."

I hope you have some suggestions. Thanks!

Hi you have to run it with command i provided
/path/to/Go/bin/videostreamer -input rtsp://camIP/stream_name -fcgi=false -format

Just edit path to compiled videostreamer, camIP and stream name

Hi Van, the installation of the zip file gives me this result :
(octoprint 1.4.0)
"2020-04-20 13:16:44,731 /home/pi/oprint/bin/python2 -m pip --disable-pip-version-check install /tmp/tmpw1nvS8.zip --no-cache-dir
2020-04-20 13:16:46,216 > Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
2020-04-20 13:16:46,216 > Processing /tmp/tmpw1nvS8.zip
2020-04-20 13:16:46,734 ! ERROR: Command errored out with exit status 1:
2020-04-20 13:16:46,734 ! command: /home/pi/oprint/bin/python2 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-tR7ARu/setup.py'"'"'; file='"'"'/tmp/pip-req-build-tR7ARu/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-req-build-tR7ARu/pip-egg-info
2020-04-20 13:16:46,734 ! cwd: /tmp/pip-req-build-tR7ARu/
2020-04-20 13:16:46,735 ! Complete output (3 lines):
2020-04-20 13:16:46,735 ! Traceback (most recent call last):
2020-04-20 13:16:46,735 ! File "", line 1, in
2020-04-20 13:16:46,735 ! IOError: [Errno 2] No such file or directory: '/tmp/pip-req-build-tR7ARu/setup.py'
2020-04-20 13:16:46,735 ! ----------------------------------------
2020-04-20 13:16:46,735 ! ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output."
Thanks!

Where did you get that zip file?

Ok. It's not a octoprint plugin. As I wrote earlier you have to build it. Please read instructions in that git repo :slight_smile: If it's ok I could help you figure it out via teamviewer later today:)

ohh ok, sorry! I'll try! thanks a lot!

No problem

Hallo!!
ich haeb das problem das mein rstm stream ein password hat, bein zugriff hat diese form,
rtsp://userxx:pwxxxxxxx@192.168.1.148:554/stream1, wenn ich deine vorschlag benutze bekomme ich den fehler !Q@192.168.1.148: event not found, habe auch probiert den ganzen rstp string unter " " zu setzen aber hat uch nicht funktioniert.
Hat hier iemand eine vorschlag für mich wie ich das lösen kann ??
danke

Du wirst mit deiner Frage bestimmt mehr Erfolg haben, wenn du sie in Englisch verfasst :wink:

In english please:)

Soory !!! :slight_smile:

Hi!!
I have the problem that my rstm stream has a password, this access has this form,
rtsp: // userxx: pwxxxxxxx@192.168.1.148: 554 / stream1, if I use your suggestion I get the error !Q@192.168.1.148: event not found, I also tried to set the whole rstp string under "" but did uch not working.
Has anyone here a suggestion for me how I can solve this?
thank you

I was also able to use _ instead of & maybe this will help

rtsp://192.168.1.125/user=admin_password=_channel=1_stream=0.sdp?

rtsp://192.168.1.125/user=admin_password=_channel=1_stream=0.sdp?

after tryin to connect within octoprint i only get:

2020/05/03 19:43:41 Serving [GET] request from [127.0.0.1:36566] to path [/] (0 bytes)
2020/05/03 19:43:41 Unknown request.

@igor_quagliato Try it as @nuetim wrote

@nuetim As I can see you are requesting / it should be /stream

thanks for the hint. what ist the proper configuration for the Webcam Stream-URL?

( /webcam/?action=stream)?

also tried http://octopi_ip/stream with this i dont even get a request notice

Hi
I tried it so it seems what is happening
is the out put so rich ??

root @ octopi: ~ # $ GOPATH / bin / videostreamer -input rtsp: //192.168.1.125/user=igor72_igorigor=_channel=1_stream=0.sdp?
2020/05/03 20:38:43 encoder: Waiting for clients ...
2020/05/03 20:38:43 Starting to serve requests on 0.0.0.0:8080 (FastCGI)
Why did he have ip 0.0.0.0 ??