Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTSP Feed for printer cameras #1536

Open
greghesp opened this issue Mar 25, 2023 · 436 comments
Open

RTSP Feed for printer cameras #1536

greghesp opened this issue Mar 25, 2023 · 436 comments
Assignees
Labels
feature New feature or request Printer issues of Printer

Comments

@greghesp
Copy link

greghesp commented Mar 25, 2023

Is your feature request related to a problem? Please describe.
As a user, I cannot access the camera stream of my printer without using the Handy app or Bambu Studio

Describe the solution you'd like
As a user, I would like to be able to access my devices camera via a RTSP stream locally. This should be available whilst the device is in LAN or Cloud Mode, and should have the option to be secured using credentials, without the need for Bambu Studio camera tools to forward on the stream

Describe alternatives you've considered
There are no alternatives, due to the way this is currently implemented

Additional context
This was originally raised here
#1372, however the original poster decided to edit and close the issue for some reason. They then became toxic and it seems theirs GitHub account has been closed.

It had around 60 +1 comments and quite a lot of votes on the original post, so a much requested feature.

This feature is for the printer team, and is not a request for Bambu Studio.

As a developer of the Home Assistant integration, this is a much requested feature, but we are unable to implement this without a RTSP feed.

@greghesp greghesp added the feature New feature or request label Mar 25, 2023
@WolfwithSword
Copy link

+1 For an easily accessible RTSP camera stream feed, such that we can access it without needing bambu studio or the camera tools plugin running as a middleman. This way, I could open it in a browser or hook it up to several home automation platforms easily, or open it conveniently on my phone whether or not it is in LAN only mode.

@greghesp
Copy link
Author

Congrats. Know you copied the best and the feature's got my name on it.

I didn't copy the best, I took the drama out of it. End of. Stop being a child.

@AdrianGarside
Copy link

+1 for webcam style access direct from the printer.

@Ali229
Copy link

Ali229 commented Mar 25, 2023

+1 would love this feature as I now have multiple bambus connected to home assistant - being able to view the camera for each from one place and without internet would be useful

@KyleTeal
Copy link

+1 this would be a great feature

@jngmrks
Copy link

jngmrks commented Mar 25, 2023

+1 for a RTSP Stream direct from 3D-Printer

@RyanEwen
Copy link

+1 I think anyone coming from a printer using OctoPrint or Klipper expected RTSP out of the box

@trati629
Copy link

+1 for RTSP, would love to be able to see what my printer is doing from my TV and steam.

@Cobra-421
Copy link

+1 for RTSP direct from 3D-Printer

@andreifinski
Copy link

need it! hate to use wyze instead of existing camera

@FlyingHippo
Copy link

+1 for RTSP direct from 3D-Printer

@LayerCakeMakes
Copy link

+1 for a video stream locally from the 3d printer.

@uSyzex
Copy link

uSyzex commented Mar 26, 2023

+1 for LAN RTSP

@nejc-cc
Copy link

nejc-cc commented Mar 26, 2023

+1 for RTSP on LAN

@ice-brainvoid
Copy link

+1 for stream

@TriskelionTech
Copy link

+1 This would be awesome! would be great to have this linked to my home automation dashboard!

@davidt94
Copy link

+1 for this. Would be great

@sprior
Copy link

sprior commented Mar 26, 2023

Just a reminder that people who are interested in RTSP may also be interested in this one: #1504

@kazolar
Copy link

kazolar commented Mar 26, 2023

+1 would be awesome to add to BlueIris.

@Metallica22
Copy link

+1 for this.

@Turtletrumpet
Copy link

+1 for RTSP on LAN

@lorenzlars
Copy link

+1

2 similar comments
@dmcw999
Copy link

dmcw999 commented Mar 30, 2023

+1

@TheRealSimon42
Copy link

+1

@PatrickAmann
Copy link

+1 For an accessible RTSP camera stream on LAN.

@AdrianGarside
Copy link

@sodachen22 is there any update when the RTSP feed will be reliable? It works for short while after the printer is rebooted. But usually during the first print it stops working and then will remain broken until the printer is rebooted again.

@ondrovic
Copy link

+1 for this would be amazing to have it natively work in both handy / desktop apps without having to have home assistant running

@synman
Copy link

synman commented Jan 9, 2024

Very nice! Just tested here this method.

#!/usr/bin/python3

import struct
import sys
import os
import socket
import ssl

d = bytearray()

username = 'bblp'
access_code = 'xxx'
hostname = '192.xxx'
port = 6000

d += struct.pack("IIL", 0x40, 0x3000, 0x0)
for i in range(0, len(username)):
    d += struct.pack("<c", username[i].encode('ascii'))
for i in range(0, 32-len(username)):
    d += struct.pack("<x")
for i in range(0, len(access_code)):
    d += struct.pack("<c", access_code[i].encode('ascii'))
for i in range(0, 32-len(access_code)):
    d += struct.pack("<x")

ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

jpeg_start = "ff d8 ff e0"
jpeg_end = "ff d9"

read_chunk_size = 1024

with socket.create_connection((hostname, port)) as sock:
    with ctx.wrap_socket(sock, server_hostname=hostname) as ssock:
        ssock.write(d)
        buf = bytearray()
        start = False
        while 1:
            dr = ssock.recv(read_chunk_size);
            if not dr:
                break

            buf += dr

            if not start:
                i = buf.find(bytearray.fromhex(jpeg_start))
                if i >= 0:
                    start = True
                    buf = buf[i:]
                continue

            i = buf.find(bytearray.fromhex(jpeg_end))
            if i >= 0:
                img = buf[:i+len(jpeg_end)]
                buf = buf[i+len(jpeg_end):]
                start = False

                print(".", file=sys.stderr, end="", flush=True)

                os.write(1, b"--boundary\n")
                os.write(1, b"Content-Type: image/jpeg\n")
                os.write(1, b"Content-Length: %d\n\n" % len(img))
                os.write(1, img)
                os.write(1, b"\n");

and

% python3 p1p.py | mplayer -demuxer lavf -
MPlayer 1.5-15.0.0 (C) 2000-2022 MPlayer Team
Can't init Apple Remote.

Playing -.
Reading from stdin...
libavformat version 59.17.102 (internal)
.libavformat file format detected.
[lavf] stream 0: video (mjpeg), -vid 0
VIDEO:  [MJPG]  1280x720  0bpp  25.000 fps    0.0 kbps ( 0.0 kbyte/s)
[gl] using extended formats. Use -vo gl:nomanyfmts if playback fails.
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
libavcodec version 59.21.100 (internal)
[mjpeg @ 0x10a847a20]Requested frame threading with a custom get_buffer2() implementation which is not marked as thread safe. This is not supported anymore, make your callback thread-safe.
Selected video codec: [ffmjpeg] vfm: ffmpeg (FFmpeg MJPEG)
==========================================================================
Load subtitles in ./
Audio: no sound
Starting playback...
Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
VO: [gl_nosw] 1280x720 => 1280x720 Planar YV12
Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
VO: [gl_nosw] 1280x720 => 1280x720 Planar YV12
.V:   0.1   0/  0 ??% ??% ??,?% 0 0

it plays.

(not optimal because it searches whole buffer over and over for jpeg_end but that's just an example)

p1s-stream

wow, just wow... two days of banging my head and I finally stumbled upon this issue and y'all PoCs... 10 minutes later I've got my A1 camera exposed on my browser.

This python script is an awesome starter if you couple it with go2rtc.... remove the sysouts for the http mjpeg boundary headers (just dump the raw data) and configure go2rtc with:

streams:
     bambu_camera: "exec:/home/pi/bin/camera-stream.py"
Screenshot 2024-01-08 at 7 22 38 PM

@AdrianGarside
Copy link

AdrianGarside commented Jan 9, 2024

@synman see the ChamberImageThread() method here for more optimized processing which eliminates the search entirely:
https://github.com/greghesp/ha-bambulab/blob/develop/custom_components/bambu_lab/pybambu/bambu_client.py

It's on my list to see how I can convert the stream of jpegs into an mjpeg video stream so it can be exposed as a camera feed in home assistant. I hadn't got very far into investigating the plethora of tools that could be used but I'm pretty familiar with go2rtc as I'm using it to make the X1 stream reliable (by using it to proxy it so there's only a single connection to the printer that never disconnects).

@synman
Copy link

synman commented Jan 9, 2024

@AdrianGarside thanks for that link... ya know, I had looked at pybambu the other night and glossed over the webcam code. I'll see about adapting it for my specific use case.

@synman
Copy link

synman commented Jan 9, 2024

The pybambu snippet works wonderfully... Better than anything I've got out of handy and/or studio.

Thanks again!

@AdrianGarside
Copy link

Awesome. If you can expand on how you can convert the jpegs into an mjpeg with go2rtc that would be very helpful to me! :)

@synman
Copy link

synman commented Jan 9, 2024

@synman
Copy link

synman commented Jan 10, 2024

here's a pure python solution I pulled together today using a multi-threaded mjpeg web server I suped up a couple years ago and the protocol details provided in this thread.

https://github.com/synman/webcamd/tree/bambu

@0x5e
Copy link

0x5e commented Mar 4, 2024

golang version of @synman 's bambu-go2rtc if anyone need to run on device without python environment. https://gist.github.com/0x5e/dfb03f2ae7335bf03bb4b9cf59971597

does anyone know why a1 mini's camera stream is so slow, only 0.5~1 fps?

@THE-SIMPLE-MARK
Copy link
Contributor

golang version of @synman 's bambu-go2rtc if anyone need to run on device without python environment. https://gist.github.com/0x5e/dfb03f2ae7335bf03bb4b9cf59971597

does anyone know why a1 mini's camera stream is so slow, only 0.5~1 fps?

It's how it is sadly. A1 and the P1 series' cameras are intentionally frame rate limited due to the processor (an ESP32) not being able to handle a high framerate camera alongside managing the core functions of the printer.

@Schokobecher
Copy link

@sodachen22 is there any update when the RTSP feed will be reliable? It works for short while after the printer is rebooted. But usually during the first print it stops working and then will remain broken until the printer is rebooted again.

Sadly, 6 months later, this is still the case. Had to ditch the camera in HA Automations as it frequently caused them to fail (I/O Error, Timeouts)

@WolfwithSword
Copy link

WolfwithSword commented Apr 29, 2024

Sadly, 6 months later, this is still the case. Had to ditch the camera in HA Automations as it frequently caused them to fail (I/O Error, Timeouts)

I did hear recently that the 1.8 firmware supposedly is going to bring reliability improvements to camera streams via live-view and wifi. Only a rumour though but wouldn't be surprised.

@sodachen22
Copy link

@sodachen22 is there any update when the RTSP feed will be reliable? It works for short while after the printer is rebooted. But usually during the first print it stops working and then will remain broken until the printer is rebooted again.

Sadly, 6 months later, this is still the case. Had to ditch the camera in HA Automations as it frequently caused them to fail (I/O Error, Timeouts)

RTSP stability issue may be related to the client, network performance and the server on the printer. To narrow down if this issue is related to the client, would you please check if it is OK with BambuStudio? If there issue is still there, please share the LOG of Studio and Printer with us. Thanks!

@Schokobecher
Copy link

Handy and Bambu Studio keep the connection, but querying the printer directly (LAN Live View turned on) results in no image.
The issue only arises after a while, and is only fixed by a printer restart - after that the connections works immediatley.

Please also see:
greghesp/ha-bambulab#221

Most common error for me is:

Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtsps:https://:@192.168.1.45/streaming/live/1

@AlexxIT
Copy link

AlexxIT commented May 4, 2024

@synman Hi. Looks like you using python to convert data. I can add this code inside go2rtc. So it will be less CPU cost and more native.

Just needs to access to stream. For example via Ngrok
https://github.com/AlexxIT/go2rtc/wiki/Tunnel-RTSP-camera-to-Intenet

You or anyone else can PM me.

@bobobo1618
Copy link

For anyone with an X1 who comes across this, this seems to be a problem with the P1 series rather than the X1 series. When an X1 is in LAN mode, you can connect to it at rtsps:https://bblp:<access code>@<ip>:322/streaming/live/1. An example go2rtc config looks like this:

streams:
  bambu: rtsps:https://bblp:<access code>:<ip>:322/streaming/live/1

You can also connect directly with VLC, ffmpeg, mpv etc. but go2rtc makes it much more stable.

Maybe you might want to add it to the docs @AlexxIT?

@WolfwithSword
Copy link

For anyone with an X1 who comes across this, this seems to be a problem with the P1 series rather than the X1 series. When an X1 is in LAN mode, you can connect to it at rtsps:https://bblp:<access code>@<ip>:322/streaming/live/1.

Just FYI for X1 series, it does not require LAN mode, but does require LAN Liveview to be enabled, the name is slightly confusing but it is separate. As for P1/A1 series, they do not have the rtsps functionality at this time.

@ColColonCleaner
Copy link

ColColonCleaner commented Jun 30, 2024

Trying to access the camera feed this way rtsps:https://bblp:<access code>@<ip>:322/streaming/live/1 after including the correct IP and access code, but when using that URL with FFMPEG I get a 'Permission denied' error. The same access code here is used here as in bambu studio, and I can see the camera feed in bambu studio, so I'm not sure why it's failing via FFMPEG. Any clues?

@saileshkotha
Copy link

saileshkotha commented Jul 25, 2024

This works perfectly fine: https://github.com/slynn1324/BambuP1Streamer/blob/main/Dockerfile

Using scrypted, ffmpeg plugin. If anyone want detailed steps, please let me know. Will document this with all configuration details.

image image

@Crackeronkelz
Copy link

Iam trying that since 3 days…
Also want to do the same :-)
Can you please describe how to integrate that in scrypted ?

This works perfectly fine: https://github.com/slynn1324/BambuP1Streamer/blob/main/Dockerfile

Using scrypted, ffmpeg plugin. If anyone want detailed steps, please let me know. Will document this with all configuration details.

image image

@posita
Copy link

posita commented Sep 4, 2024

Trying to access the camera feed this way rtsps:https://bblp:<access code>@<ip>:322/streaming/live/1 after including the correct IP and access code, but when using that URL with FFMPEG I get a 'Permission denied' error. The same access code here is used here as in bambu studio, and I can see the camera feed in bambu studio, so I'm not sure why it's failing via FFMPEG. Any clues?

Try ffplay instead of ffmpeg? For me, neither VLC nor ffmpeg worked. ffplay did, however.

@AdrianGarside
Copy link

AdrianGarside commented Sep 4, 2024

Trying to access the camera feed this way rtsps:https://bblp:<access code>@<ip>:322/streaming/live/1 after including the correct IP and access code, but when using that URL with FFMPEG I get a 'Permission denied' error. The same access code here is used here as in bambu studio, and I can see the camera feed in bambu studio, so I'm not sure why it's failing via FFMPEG. Any clues?

Bambu studio doesn’t use the RTSP connection. Support for that was added solely for external access to the video feed locally on the network. It often stops working and rebooting the printer is the only way to start it working again.

@SebastianOsinski
Copy link

This works perfectly fine: https://github.com/slynn1324/BambuP1Streamer/blob/main/Dockerfile

Using scrypted, ffmpeg plugin. If anyone want detailed steps, please let me know. Will document this with all configuration details.

image image

@saileshkotha Does this Docker app still work for you on newest printer firmware? I get errors when trying to stream with it on newest P1S FW.

@shamanskyh
Copy link

Using Scrypted here which works okay, though I'm disappointed in the reliability of the RTSPS stream. It frequently becomes inoperable after a short time and only resumes working after a full restart of the printer.

I'd really appreciate a more reliable local RTSPS stream.

@posita
Copy link

posita commented Oct 13, 2024

You can also connect directly with VLC, ffmpeg, mpv etc. but go2rtc makes it much more stable.

@bobobo1618, how were you able to get VLC to work? VLC doesn't seem to recognize the rtsps scheme, but it won't work for me with rtsp:https://bblp:<access-code>@<ip-addr>:322/streaming/live/1 either. It just endlessly tries to connect. ffplay and mpv work fine for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request Printer issues of Printer
Projects
None yet
Development

No branches or pull requests