How can I record video on a Pinephone?
I'd like to be able to take a short maybe 10 second video using the Pinephone's camera. There seem to have been a few individuals who figured out how to do this, but they used very different methods and none of them seem to be currently functional:

Reddit post by UJC_theguy, who was able to use ffmpeg to record a video. Trying his method (with /dev/video2 since that's what my camera shows up as), I get the following:
[video4linux2,v4l2 @ 0xffff9790b670] ioctl(VIDIOC_STREAMON): Broken pipe
/dev/video2: Broken pipe

Reddit post by Atticus83, who used gstreamer instead of ffmpeg. Trying his method the _jprocess script fails with
WARNING: erroneous pipeline: no element "x264enc"

Python script from Martijn Braam, which uses ffmpeg to do the recording. Modified to use /dev/video2, it gives the following:
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
[video4linux2,v4l2 @ 0xffffae633670] The driver changed the time per frame from 1/20 to 1/15
[video4linux2,v4l2 @ 0xffffae633670] ioctl(VIDIOC_STREAMON): Broken pipe
/dev/video2: Broken pipe

So how can I record video if these don't work?

Edit: Atticus83's method actually does work, but the "ugly" gstreamer plugins are needed. When I wrote this post I thought I had already installed them, but upon trying to install all of the gst-plugins-* packages in pmOS, gst-plugins-ugly got installed and now it works. If anyone knows of a better method though, please post it here.
Hey KK22,

Did you manage to find a solution using ffmpeg? I'm stuck on the same issue when testing with Martijn Braam's python script. I also realized that I have to use /dev/video2, but always running into the broken pipe error.

Kang Sheng
Try my scripts maybe?

At least they worked last time I tried them, with the limitations documented in this thread on the Manjaro forum. And it might be that something needs tweaking, e.g., if the input were renamed yet again or something.
Thanks Kevin. I tweaked some of the numbers in your script and it worked perfectly! Thanks you for saving me so many potential hours of pulling at my hair.

Looking at what you have and my non-working script, what I can tell is different is the options used when calling media-ctl and ffmpeg. I'll have to study those options more carefully. First time using media-ctl and ffmpeg!

For anybody who wants a script that is working for the latest pinephone (at this time of writing), you can find it here:
Thanks for sharing your edited version! So I see you changed 3 to 4 in two (apparently unrelated) places: the IIO device for the accelerometer, and the camera devices. I will check whether I also need these changes on my PinePhone now and update the script in my SVN in that case.

As for the media-ctl and ffmpeg options, those are basically based on other scripts I found. I can explain what the commands do:
  • The first media-ctl command disables the selfie camera (gc2145) and enables the main/back camera (ov5640). There are two connections there, from "camera name":0 to 1:0, the latter is the multiplexed output. (Instead of the camera name with quotes, you can also use a number, but I have found that to change more often than the name does, so I changed it back to a name when I wrote the script. If it is in a script, I do not have to type it all the time anyway, so using the long form does not hurt.) The first is set to [0] = disabled, the second to [1] = enabled.
  • The second media-ctl command sets the output format (fmt:…) of the camera to something FFmpeg can process. The camera supports a few formats, there is a list somewhere. In any case, UYVY8_2X8 matches what FFmpeg's yuv420p can process, 1280x720 is the resolution, 1/30 means 30 fps.
  • The first FFmpeg command sets the video and audio "file formats" (to video4linux2 and pulse, respectively, which are not really file formats) and devices (to a kernel device file for video4linux2 and to a PulseAudio device name for pulse), the input format and resolution to match the above, the thread queue sizes to something that works well with the inputs (I do not remember exactly where those numbers came from), and the output codecs to lossless codecs that can be encoded at real time (which is the main trick in the script, because encoding directly to VP9 is too slow to work in real time).
  • The second FFmpeg command reencodes the above lossless file to VP9 video and Opus audio in a WebM container, also applying the video filters for rotation ($VF) autodetected by the first part of the script.
Interesting! Looks like it needs more tweaking to work on Mobian though.

I did find that device references needed to be changed to from "device4" to "device1". (The devices 0, 1, and 2 exist. Only #1 had the required entries.)

CUR_X=$(cat /sys/bus/iio/devices/iio\:device4/in_accel_x_raw)
CUR_Y=$(cat /sys/bus/iio/devices/iio\:device4/in_accel_y_raw)

...changed to...

CUR_X=$(cat /sys/bus/iio/devices/iio\:device1/in_accel_x_raw)
CUR_Y=$(cat /sys/bus/iio/devices/iio\:device1/in_accel_y_raw)

However, when running the script after making those changes, the first invocation of media-ctl barfs up on an invalid arg. I'm not familiar enough with that program to know what it's complaining about. Here's the output including an echo of the command line that fails (I believe I got the single and double quotes to echo correctly):

[mobian@mobian bin]$ ./ test

**** Executing the following command:
**** media-ctl -d1 -l'"gc2145 4-003c":0->1:0[0],"ov5640 4-004c":0->1:0[1]'

Unable to parse link: Invalid argument (22)
[mobian@mobian bin]$
(01-21-2023, 02:16 PM)Zebulon Walton Wrote: I did find that device references needed to be changed to from "device4" to "device1". (The devices 0, 1, and 2 exist. Only #1 had the required entries.)
Looks like the device number depends from phone to phone, depending possible on the distro, the kernel version, and/or the hardware revision. My PinePhone now has the accelerometer on device2. Used to be device3, which does not even exist now.

I guess we should just use a wildcard, as in:
CUR_X=$(cat /sys/bus/iio/devices/iio\:device*/in_accel_x_raw)
CUR_Y=$(cat /sys/bus/iio/devices/iio\:device*/in_accel_y_raw)
then the shell will pick the correct sensor.

[mobian@mobian bin]$ ./ test

**** Executing the following command:
**** media-ctl -d1 -l'"gc2145 4-003c":0->1:0[0],"ov5640 4-004c":0->1:0[1]'

Unable to parse link: Invalid argument (22)
[mobian@mobian bin]$
I guess the camera names are wrong. Try using 3-003c and 3-004c instead of 4-003c and 4-004c. For me, the ones with 3- are the correct ones, both back when I wrote the script and now. It looks like those names also depend on the hardware or distro, which is a problem, because the numeric IDs (5 and 7 in my case) are not stable either (e.g., I had them swapped at some point). Or print the topology with
media-ctl -d1 -p
and copy the names from there. That, or the hardcoded 1 for the sink is wrong, try the name "sun6i-csi" (including the quotes) instead.
Thanks, I'll play around with it a bit when I have time. Not that making videos is a partiularly high priority but it would be interesting to see it work.
Great to see this thread, I blogged about video recording on PinePhone a while ago, kept tinkering (I switched to VP8 encoding, as that's a lot faster), but then did not do any further experiments. Now (after upgrading to postmarketOS 22.12) my changes are no longer enough to get video recording working.
This may motivate me to play with video recording again Smile

One avenue worth exploring is tinkering with Millipixels, Purism's Megapixels fork for the Librem 5. They have video recording working in the latest builds from CI (meaning, it's not in a release yet, but the code is merged). As libcamera support is up-and-coming for the PinePhone camera (see Adam Piggs work on a camera app for Sailfish OS), this might be the fastest route to proper PinePhone video recording with a GUI app.

Also, I really look forward to this FOSDEM talk.

Possibly Related Threads…
Thread Author Replies Views Last Post
  eSIM on PinePhone just_a_q 2 1,207 03-14-2023, 10:14 AM
Last Post: EuvzO8
  Are you using the Pinephone as your daily driver? jro 150 69,612 03-13-2023, 09:06 AM
Last Post: dante404
  PinePhone Game Thread PixelPaintbrush 27 30,695 03-13-2023, 04:41 AM
Last Post: xavi92
Lightbulb Suggestion: NFC-F / FeliCa Support for next gen PinePhone or board add-on iamauser 0 185 03-11-2023, 10:21 AM
Last Post: iamauser
  UPDATED (June 2021): 17-distro multi-boot image for Pinephone (incl. 3GiB variant) megous 183 194,792 03-05-2023, 11:04 AM
Last Post: Eugo
  [Serious] Pinephone availability in volumes? oobdev 3 340 02-28-2023, 07:14 AM
Last Post: barray
  are you still using pinephone as a daily driver? zetabeta 29 2,340 02-09-2023, 11:48 AM
Last Post: silverwing
Sad New PinePhone won't boot 9/10 times - Screen is on but stays black :( dante404 8 3,086 02-03-2023, 01:27 AM
Last Post: dante404
  PureTalk work with Pinephone? car46999 6 1,063 01-30-2023, 12:05 AM
Last Post: car46999
  "PinenotePhone": Swap E-Ink Screen Onto Pinephone? britelite 0 286 01-03-2023, 06:17 PM
Last Post: britelite

Forum Jump:

Users browsing this thread: 1 Guest(s)