Myzel394 / Alibi

Use your phone as a dashcam and save the last 30 minutes when you need them.
GNU General Public License v3.0
219 stars 10 forks source link

Add camera preview #81

Closed materoy closed 3 months ago

materoy commented 4 months ago

This pr adds camera preview for the selected facing camera. Landscape ui for it needs some improvement, but this feature is good to go.

materoy commented 4 months ago

The controls could be drawn on top of the camera preview to improve uix

Myzel394 commented 4 months ago

Looks good on first sight! Originally, I wanted to add both a preview plus a dark blurred background that would cover the whole background of the app. Do you know if this is possible, or would you even be down to implementing this? :D

Myzel394 commented 4 months ago

oh and btw

Landscape ui for it needs some improvement

No worries, I'll take over the landscape part :)

materoy commented 4 months ago

Looks good on first sight! Originally, I wanted to add both a preview plus a dark blurred background that would cover the whole background of the app. Do you know if this is possible, or would you even be down to implementing this? :D

It is easily possible, although I was thinking of moving the preview entirely to the background, and just darken the areas which the controls and info cover, for contrast. Like OSD in video cameras. I'll draw a figma sketch and link it here to showcase.

Myzel394 commented 4 months ago

It is easily possible

Is it? I'd love to see this implemented. :D When I tried working on this, I almost went crazy because I couldn't find out a proper way to do this. :C So if you know how to do this, I'd be very happy to include this in Alibi!

I was thinking about creating such a design:

image

Myzel394 commented 4 months ago

Just tested it out, looks good! Can't believe I forgot to add the binding camera instance, otherwise this feature could have been available so much earlier! ^^ If we could blur the image, that would be the cherry on the top! Do you know how to do that?

materoy commented 4 months ago

I actually tried the compose way, but it doesn't work on the preview, the other way is to manipulate the video preview itself. But that comes with a performance cost.

Myzel394 commented 4 months ago

I actually tried the compose way, but it doesn't work on the preview, the other way is to manipulate the video preview itself. But that comes with a performance cost.

That's also what I faced when I tried to implement this. Performance shouldn't be a big problem if we quickly blur it and even if, it's a blurred preview, so the most up-to-date image isn't that important :D

What I've found out about manually changing the preview is that this doesn't seem to be easily doable. Although I could be mistaken of course. If you know a relatively easy way to do so, please tell me so! :D If there's none / you don't know one, we'll fallback to a plain preview then

materoy commented 4 months ago

I was wrong, it's not that easy to blur the preview, there's 2 options to use off-the-shelf blurring library or to implement a fragment shader in opengl which having to go down to that level it's a good learning experience but it might take a while

Myzel394 commented 3 months ago

Okay so for now let's just add a fully visible preview. You can toggle between this preview and the current look. If you figure out how to blur the preview, feel free to open a PR. I'll also take a look again - though it really seems to be quite difficult :/

I'll take care of implementing the rest, thanks for your contribution! :)

Myzel394 commented 3 months ago

Hey I got bad news: It looks like the video batches itself are completely empty (0 bytes) when using the camera preview :/ I have no idea why this is the case, I think CameraX is not really mature yet. Anyways, I'll remove the CameraPreview feature for now. I won't remove your code, I'll just remove the component out of the rendering. If you know how to fix that or why this is happening, I'd be happy to know :D