greghesp / ha-bambulab

A Home Assistant Integration for Bambu Lab Printers
695 stars 58 forks source link

P1P Chamber Camera Image Type #365

Open lunDreame opened 6 months ago

lunDreame commented 6 months ago

Describe the feature

Is it possible to change the user setup so that the P1P camera sensor type can be selected as an image or camera? I want to bring the P1P chamber camera to Homekit, but it's impossible with image dishing.

What device is this for?

P1P

Other Information

No response

AdrianGarside commented 6 months ago

In principle it ought to be possible to have it present as a camera in MJPEG format since that format is just a stream of individual jpeg images. I'm not sure I'm up to the task of doing that entirely inside the integration but doing it with other tools like ffmpeg looks to get complicated and messy pretty quickly. I'll do some digging.

lunDreame commented 6 months ago

In principle it ought to be possible to have it present as a camera in MJPEG format since that format is just a stream of individual jpeg images. I'm not sure I'm up to the task of doing that entirely inside the integration but doing it with other tools like ffmpeg looks to get complicated and messy pretty quickly. I'll do some digging.

I would recommend forcing the P1P camera frame rate to 30 fps or 15 fps to resolve 0.5 fps. Originally, it looks like this. I think I can combine 30 or 60 photos of 0.5 frame to make it virtual 30 or 60 fps. Photo Sync might be different, but you get to combine photos to increase the frame.


import cv2

def merge_frames(frames):
    merged_frames = []
    for i in range(0, len(frames), 2):
        frame1 = frames[i]
        frame2 = frames[i + 1] if i + 1 < len(frames) else frames[i]
        merged_frame = cv2.addWeighted(frame1, 0.5, frame2, 0.5, 0)
        merged_frames.append(merged_frame)
    return merged_frames

merged_frames = merge_frames(frames)
AdrianGarside commented 6 months ago

Home assistant doesn't appear to support a camera with a purely in-memory stream source. It only supports web based streams. So the only way to convert the images into a video would be to do it externally to home asssistant using tooling like ffmpeg.

chansearrington commented 6 months ago

What about a tool like scrypted?

qwasy commented 6 months ago

I'm using this addon https://github.com/kurim/p1stream-ha which provides a webrtc and other streams. But, I can't get it working as a generic camera, that's why I'm using it with https://github.com/AlexxIT/WebRTC as a videocard. Worked fine, till the last update broke the card somehow :/ But the network parts still works fine. I also use wget for picture notifications etc.

Maybe that's an okay workaround...

AdrianGarside commented 6 months ago

I'm using WebRTC as well for my X1 - I'll be sure not to update it! WebRTC gives a vastly better and vastly lower latency playback than the generic camera. And it allows multiple connections to share the go2rtc proxy stream instead of each connecting directly to the printer. And setting it to keep the connection alive in the background means that the X1 video feed will keep running for longer despite its reliability issues since active feeds tend to keep working even when the printer fails new feed attempts.

Looks like that addon is using go2rtc under the hoods as well given the listed URL to connect to.

qwasy commented 6 months ago

Oh, no I meant the addon from kurim. The latest update broke something with my WebRTC videocard. WebRTC itself works fine. Maybe the WebRTC infos could be put into the faq?

lunDreame commented 6 months ago

Oh, no I meant the addon from kurim. The latest update broke something with my WebRTC videocard. WebRTC itself works fine.

Maybe the WebRTC infos could be put into the faq?

https://github.com/kurim/p1stream-ha

How did you add a camera to HA using this add-on? Please tell me how

kurim commented 6 months ago

@iluna8 you can follow his description and my solution for his issue. https://github.com/kurim/p1stream-ha/issues/4

github-actions[bot] commented 4 months ago

Stale issue message