How can I record video on a Pinephone?
#1
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:
Code:
[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
Code:
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:
Code:
  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.
  Reply
#2
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
  Reply
#3
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.
  Reply
#4
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: https://gist.github.com/TayKangSheng/a0f...d7426f936a
  Reply
#5
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.
  Reply
#6
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.)

Code:
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):

Code:
[mobian@mobian bin]$ ./record.sh test
portrait

**** 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]$
  Reply
#7
(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:
Code:
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.

Quote:
Code:
[mobian@mobian bin]$ ./record.sh test
portrait

**** 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
Code:
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.
  Reply
#8
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.
  Reply
#9
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.
  Reply
#10
Is there any video recording solution still working for you on the PinePhone (except using screen recording)?
I did not get any script working on an updated Mobian system with Phosh (Mobian edition convergence package):
https://gitlab.com/Alaraajavamma/fastvideo/-/issues/7
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  eSIM on PinePhone just_a_q 8 4,711 11-05-2024, 11:10 AM
Last Post: zetabeta
  Want to buy second hand PinePhone 3G version rudi.timmermans 0 182 11-01-2024, 09:58 AM
Last Post: rudi.timmermans
  Can use PlayStation on Pinephone? willharper 6 5,688 10-30-2024, 08:07 AM
Last Post: biketool
  Ordered PinePhone till today have no info or confirmation about order hennadiyt 1 372 10-05-2024, 02:20 PM
Last Post: KC9UDX
  US Mobile, via T-Mobile, won't support Pinephone Pro - SOLVED, SIMPLY jovval 11 5,805 07-28-2024, 03:42 PM
Last Post: dchang0
  Pinephone not booting, always vibrating alexander12 8 6,896 07-19-2024, 07:50 PM
Last Post: Blackheart
  PinePhone Pro P. Siera 2 834 07-17-2024, 12:41 AM
Last Post: P. Siera
  PinePhone Boots but only Shows Black Screen with Backlight danyeaw 1 696 06-30-2024, 10:18 AM
Last Post: danyeaw
  Pinephone won't boot. spha 13 5,910 05-15-2024, 10:31 PM
Last Post: Richy_T
  Pinephone boot. Richy_T 5 1,585 05-15-2024, 03:35 PM
Last Post: Richy_T

Forum Jump:


Users browsing this thread: 2 Guest(s)