Pinephone Camera on CLI with ffmpeg and media-ctl

Still on postmarketOS.

using bash, to call media-ctl and ffmpeg take pictures with the pinephone camera.

need to setup the camera for the resolution and format required :

media-ctl \
-d /dev/media1 \
--set-v4l2 '"ov5640 4-004c":0[fmt:SBGGR8_1X8/2592x1944@1/15]'

then call ffmpeg to record raw video to a file. Found the following settings work:

ffmpeg -hide_banner \
 -f rawvideo \
 -pix_fmt bayer_bggr8 \
 -s 2592x1944 \
 -f video4linux2 \
 -i /dev/video3 \
 -vsync 2 \
 -vframes 20 \
NAME_vid.yuv

this sets the encoder and resolution to match the settings above; the device /dev/video3 is my phone, not sure if this is standard for all.

why 20 frames? by experimentation, found that the first few frames were not good (~5 or so). To me it seems like the system is “warming up”. Initial black or green, then lighting/colours off. So for the “real” picture, need more than just one.

then, convert the above .yuv file to a set of jpeg files with another ffmpeg call:

ffmpeg \
 -ss 0.5 \
 -hide_banner \
 -f rawvideo \
 -pix_fmt bayer_bggr8 \
 -s 2592x1944 \
 -i NAME_vid.yuv \
 -vsync 2 \
 -vframes 2 \
 ~/Pictures/NAME_of_Pictures_%05d.jpg

can replace .jpg with .png or another picture format.
-ss 0.5 skips the bad frames

Note: latest ffmpeg gave an error (2021-04-11) when run:
Error relocating /usr/bin/ffmpeg: av_opt_child_class_iterate: symbol not found

but downloading the latest source for ffmpeg and compiling worked again.

Sample, a bit dark, took it in the evening.

todo:
more camera controls: exposure, and such…

This entry was posted in tech. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s