Skip to content

Instantly share code, notes, and snippets.

@TayKangSheng
Created January 20, 2023 14:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TayKangSheng/a0f9a7edd2d298c3504392d7426f936a to your computer and use it in GitHub Desktop.
Save TayKangSheng/a0f9a7edd2d298c3504392d7426f936a to your computer and use it in GitHub Desktop.
PinePhone record video with rear camera
#!/bin/ash
# Credits to Kevin Kofler
# https://forum.pine64.org/showthread.php?tid=16539&pid=109333#pid109333
if [ -z "$1" ] ; then
echo "usage: ./record.sh videoname"
exit 1
fi
VF=""
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)
ABS_CUR_X=${CUR_X#-}
ABS_CUR_Y=${CUR_Y#-}
if [ $ABS_CUR_X -ge $ABS_CUR_Y ] ; then
if [ $CUR_X -ge 0 ] ; then
echo "portrait"
VF="-vf transpose,hflip"
else
echo "portrait inverted"
VF="-vf transpose,vflip"
fi
else
if [ $CUR_Y -lt 0 ] ; then
echo "landscape clockwise"
VF=""
else
echo "landscape counterclockwise"
VF="-vf hflip,vflip"
fi
fi
media-ctl -d1 -l'"gc2145 4-003c":0->1:0[0],"ov5640 4-004c":0->1:0[1]' || exit $?
media-ctl -d1 -V'"ov5640 4-004c":0[fmt:UYVY8_2X8/1280x720@1/30]' || exit $?
ffmpeg -input_format yuv420p -s 1280x720 -f video4linux2 -thread_queue_size 4096 -i /dev/video2 -f pulse -thread_queue_size 256 -i alsa_input.platform-sound.HiFi__hw_PinePhone_0__source -c:a flac -c:v ffvhuff "$1.mkv" || exit $?
ffmpeg -i "$1.mkv" $VF -c:v libvpx-vp9 -c:a libopus "$1.webm" || exit $?
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment