diff options
Diffstat (limited to 'dot/local/bin/selfie')
-rwxr-xr-x | dot/local/bin/selfie | 44 |
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 | ||
3 | video_devices() | ||
4 | { | ||
5 | v4l2-ctl --list-devices | sed -ne 's/^\t//p' | ||
6 | } | ||
7 | |||
3 | AUDIO_DEVICE=pulse | 8 | AUDIO_DEVICE=pulse |
4 | VIDEO_DEVICE=/dev/video0 | 9 | VIDEO_DEVICE=$(video_devices | head -n1) |
10 | |||
11 | [ "$VIDEO_DEVICE" ] || exit 1 | ||
5 | 12 | ||
6 | MAX_RECORDING_TIME=00:05:00 | 13 | MAX_RECORDING_TIME=00:05:00 |
14 | [ "$RECORD_FOREVER" ] && unset MAX_RECORDING_TIME | ||
7 | 15 | ||
8 | NOW=$(date -Iseconds) | 16 | NOW=$(date -Iseconds) |
9 | 17 | ||
10 | OUTPUT=recording.${NOW//[:T]/.}.avi | 18 | OUTPUT=recording.${NOW//[:T]/.}.avi |
11 | OUTPUT_LINK=recording.latest.avi | 19 | OUTPUT_LINK=recording.latest.avi |
12 | 20 | ||
21 | XVID_QUALITY=10 | ||
22 | |||
23 | info() | ||
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 | |||
38 | V4L2_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 | |||
42 | drawtext='text=%{pts\\:hms}:x=5:y=h-lh-5:fontsize=18:fontcolor=white:box=1:boxcolor=0x00000099' | ||
13 | record() | 43 | record() |
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 | ||