#phonecamera #linuxphone #librem5

Librem 5 camera/kernel can do three possible resolutions, ~1024x768 @ ~24fps, ~2048x.. @ ~31 fps and ~4096x.. @ ~15fps. Debayering is actually easier and better quality if we downscale at the same time, and that allows best framerate, so we do that (2048x.. resolution).

ARM has problems with cache coherency w.r.t. DMA, and kernel solution is to simply disable cache on DMAbufs for userspace, which means accessing video data is 10x slower than it should be on the CPU. Which means debayering on GPU is attractive, and that's what we do. (gold.frag). GPU can do more image signal processing functions easily, too, so we do some of that.

Unfortunately, we hit the same uncached memory problem at the GPU output. So we use separate thread to copy. All this unfortunately does not fit on one core, so we need two threads, one controlling GPU debayer on frame n+1, while the other one copies video data from frame n. (heart.c). We save resulting RGBA data to ramdisk. This all costs maybe 80% of one core.

From there, Python scripts can pick them up: ucam.py displaying the viewfinder and mpegize.py handling the video encoding via gstreamer. There's basically 0% cpu left, but I can encode ~1024x.. video. Unfortunately that's without audio and with viewfinder at 1fps. Plus, combination of C + Python is great for prototyping, but may not be that great for performance.

Code is here: https://gitlab.com/tui/tui/-/tree/master/icam?ref_type=heads .

At this point I'd like viewfinder functionality merged into the rest of GPU processing. Ideally, I'd like to have a bitmap with GUI elements, combine it with scaled RGBA data, and rendering it to screen. I know SDL and Gtk, SDL looked like better match, but I could not get SDL and GPU debayering to work in single process (template SDL code is here https://gitlab.com/tui/debayer-gpu/-/blob/master/sdl/main.c?ref_type=heads ).

If you can integrate main.c and heart.c, that would be welcome. If you have example code that combines SDL with processing on GPU, that would be nice, too. If you know someone who can do GPU/SDL, boost would not be bad, I guess.

@datenwolf
@NekoCWD
@dcz
@martijnbraam

@pavel @datenwolf @dcz @martijnbraam @NekoCWD I played with it over the last days and I already have 526x390 30 FPS encoding with live viewfinder, perfectly synced audio, color correction, lens shading correction, tone mapping, AWB and AE - consuming about 40% CPU. Still needs chromatic shading correction and AF, and I started experimenting with enabling PDAF.

I can also make the sensor output 60 FPS and RAW10. Patches incoming ;) Still only 2 MIPI lanes though, so no 13MP 30FPS yet.

@dos @datenwolf @dcz @martijnbraam @NekoCWD I hope you played with it in your day job for about 8 hours a day, because otherwise I'll feel kind of bad :-). Thanks!

Do you also get constant clicking from the AF system? I thought it was gone on Mobian, but then it came back.

526x390 is easy, can you do 1052x..? Is it possible to peek at sources somewhere?

Thanks again.

@pavel @datenwolf @dcz @martijnbraam @NekoCWD It's 526x390, but properly binned (each channel's sample consists of 4 raw pixels averaged), which reduces noise. The shader got heavy though, does only ~35 FPS at this res - but there should be room for optimization. I've been more concerned with its correctness than performance so far.

Stats counting on the CPU with NEON is fast enough for full frame with some subsampling.

I'm giving it some finishing touches and will then publish it of course 😁

@dos @datenwolf @dcz @martijnbraam @NekoCWD So, this is what I was targetting with my "gstreamer will downscale UV components" comment: GPU is doing heavy computation to make sure you have great color values for each pixel, only for gstreamer to discard it in the next step.

Anyway, I'd love to see the code :-).
Follow

@pavel @datenwolf @dcz @martijnbraam @NekoCWD You could encode to YUV444 or even RGB, but lack of lens corrections is much more visible than chroma subsampling:)

@dos @datenwolf @dcz @martijnbraam @NekoCWD Lens corrections -- are we speaking lens shading or geometry corrections?

I am still eager to see your code. I'd like to try to tweak it for 1024x.. resolution, to get good quality videos.
Sign in to participate in the conversation
Librem Social

Librem Social is an opt-in public network. Messages are shared under Creative Commons BY-SA 4.0 license terms. Policy.

Stay safe. Please abide by our code of conduct.

(Source code)

image/svg+xml Librem Chat image/svg+xml