Skip to content

Instantly share code, notes, and snippets.

@bakman2
Last active July 14, 2024 12:21
Show Gist options
  • Save bakman2/521fd7333b4fad6602b9f9955c4fbc2c to your computer and use it in GitHub Desktop.
Save bakman2/521fd7333b4fad6602b9f9955c4fbc2c to your computer and use it in GitHub Desktop.
Octoprint IP Camera

How to use Octoprint with an IP camera that has an RTSP stream available

Optional: For Wyze cam only

Install Dafang Hacks on the Wyze Cam.

Once running and all is functional, continue. Set video bitrate to 1500, VBR, 30fps.

Installation

If OctoPrint is running on a Raspberry Pi (3B minimum):

ssh pi@<raspberry_ip>
sudo apt update
sudo apt install vlc

VLC will be used to transcode the rtsp stream to a http stream which OctoPrint can use as streaming URL

nano http_stream.sh

paste the following line:

cvlc -I dummy rtsp://ip_of_yourcam --sout "#transcode{vcodec=mjpg,quality=3,fps=5,acodec=none,width=1280,height=720}:standard{access=http{mime=multipart/x-mixed-replace; boundary=7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:8888/videostream.cgi}" 2>/dev/null

Change the ip_of_yourcam to match the full rtsp url from your camera

CTRL+x to save

chmod +x http_stream.sh
./http_stream.sh

Now you should be able to open your browser:

http://<raspberryip>:8888/videostream.cgi

If it works, you can use this url in OctoPrint for the Stream URL

For the snapshot URL use the stills url from your camera

Change your user/pass and ip to match your setup Click advanced options and uncheck Validate SSL on snapshot URL (if applicable)

As this process is cpu intensive you will need to play around with the quality=x,fps=x (fps = frames per second) options in the cvlc command. These settings work for me, but as I wanted better quality I have this process running on a more powerful device.

@emaklav
Copy link

emaklav commented Oct 6, 2023

Hi! I'm start rtsp-simple-server localy on ubuntu server that connected to printer, so I have access to HTPP stream from rtsp-simple-server in my browser, but Octo didnt saw this stream ...

@xam464
Copy link

xam464 commented Jul 14, 2024

For me I need to use the following stream URL:

/usr/bin/vlc -vvv --intf=dummy --no-audio rtsp://username:password@CAMERAIP:CAMERAPORT/STREAM --sout "#transcode{vcodec=mjpg,venc=ffmpeg{strict=-2,threads=1},scale=1.0,acodec=none}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:10001}" --network-caching=50 --sout-mux-caching=50 --file-caching=50 --live-caching=50

I put it in the following service code:

[Unit]
Description=rtsp2mjpeg
After=network.target

[Service]
User=pi
Type=simple
ExecStart=/usr/bin/vlc -vvv --intf=dummy --no-audio rtsp://username:password@CAMERAIP:CAMERAPORT/STREAM --sout "#transcode{vcodec=mjpg,venc=ffmpeg{strict=-2,threads=1},scale=1.0,acodec=none}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:10001}" --network-caching=50 --sout-mux-caching=50 --file-caching=50 --live-caching=50

[Install]
WantedBy=multi-user.target

After that, you put the url in OctoPrint:

NOTE: I installed the following. No Idea you will need to...

sudo apt-get install libavcodec-extra
sudo apt-get install ffmpeg
sudo apt-get install libavcodec-dev

Credits to:https://github.com/Tom-Hirschberger/vlc-rtsp2mjpeg-wrapper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment