summaryrefslogtreecommitdiff
path: root/dot/local/bin/selfie
diff options
context:
space:
mode:
Diffstat (limited to 'dot/local/bin/selfie')
-rwxr-xr-xdot/local/bin/selfie44
1 files changed, 40 insertions, 4 deletions
diff --git a/dot/local/bin/selfie b/dot/local/bin/selfie
index 9fa2a45..ef0adb2 100755
--- a/dot/local/bin/selfie
+++ b/dot/local/bin/selfie
@@ -1,24 +1,60 @@
1#!/bin/bash 1#!/bin/bash
2 2
3video_devices()
4{
5 v4l2-ctl --list-devices | sed -ne 's/^\t//p'
6}
7
3AUDIO_DEVICE=pulse 8AUDIO_DEVICE=pulse
4VIDEO_DEVICE=/dev/video0 9VIDEO_DEVICE=$(video_devices | head -n1)
10
11[ "$VIDEO_DEVICE" ] || exit 1
5 12
6MAX_RECORDING_TIME=00:05:00 13MAX_RECORDING_TIME=00:05:00
14[ "$RECORD_FOREVER" ] && unset MAX_RECORDING_TIME
7 15
8NOW=$(date -Iseconds) 16NOW=$(date -Iseconds)
9 17
10OUTPUT=recording.${NOW//[:T]/.}.avi 18OUTPUT=recording.${NOW//[:T]/.}.avi
11OUTPUT_LINK=recording.latest.avi 19OUTPUT_LINK=recording.latest.avi
12 20
21XVID_QUALITY=10
22
23info()
24{
25 ffmpeg -hide_banner -f v4l2 -list_formats all -i "$VIDEO_DEVICE"
26 v4l2-ctl --list-formats-ext
27
28 # Such commands as these do nothing. ffmpeg overrides them.
29 #v4l2-ctl --set-fmt-video=width=800,height=600,pixelformat=MJPG
30 #v4l2-ctl --set-fmt-video=width=1600,height=1200,pixelformat=MJPG
31}
32
33# The higher resolution matches the display, and so fills the screen while
34# recording, but the field of view is larger in the 800x600 resolution, which
35# also supports a higher framerate. Thus 800x600 seems like the "natural"
36# resolution of the camera. Though, it is still quite low. :(
37
38V4L2_OPTIONS='-input_format mjpeg -framerate 30 -video_size 800x600'
39# V4L2_OPTIONS='-input_format mjpeg -framerate 15 -video_size 1280x800'
40# V4L2_OPTIONS='-input_format mjpeg -framerate 15 -video_size 1600x1200'
41
42drawtext='text=%{pts\\:hms}:x=5:y=h-lh-5:fontsize=18:fontcolor=white:box=1:boxcolor=0x00000099'
13record() 43record()
14{ 44{
15 local timeout="${MAX_RECORDING_TIME+-t $MAX_RECORDING_TIME}" 45 local timeout="${MAX_RECORDING_TIME+-t $MAX_RECORDING_TIME}"
16 ffmpeg -hide_banner -loglevel error -stats \ 46 ffmpeg -hide_banner -loglevel error -stats \
17 $timeout -f video4linux2 -i "$VIDEO_DEVICE" \ 47 $timeout -f video4linux2 ${V4L2_OPTIONS} -i "$VIDEO_DEVICE" \
18 $timeout -f "$AUDIO_DEVICE" -i default \ 48 $timeout -f "$AUDIO_DEVICE" -i default \
19 -c:v rawvideo -pix_fmt yuv420p -f xv win \ 49 \
20 -c:a mp3 \ 50 -c:v rawvideo \
51 -vf scale=iw/2:ih/2,drawtext="${drawtext}" \
52 -pix_fmt yuv420p \
53 -f xv selfie \
54 \
21 -c:v libxvid \ 55 -c:v libxvid \
56 -c:a libmp3lame \
57 -q:v $XVID_QUALITY \
22 "$1" 58 "$1"
23} 59}
24 60