#!/bin/bash video_devices() { v4l2-ctl --list-devices | sed -ne 's/^\t//p' } AUDIO_DEVICE=pulse VIDEO_DEVICE=$(video_devices | head -n1) [ "$VIDEO_DEVICE" ] || exit 1 MAX_RECORDING_TIME=00:05:00 [ "$RECORD_FOREVER" ] && unset MAX_RECORDING_TIME NOW=$(date -Iseconds) OUTPUT=recording.${NOW//[:T]/.}.avi OUTPUT_LINK=recording.latest.avi XVID_QUALITY=10 info() { ffmpeg -hide_banner -f v4l2 -list_formats all -i "$VIDEO_DEVICE" v4l2-ctl --list-formats-ext # Such commands as these do nothing. ffmpeg overrides them. #v4l2-ctl --set-fmt-video=width=800,height=600,pixelformat=MJPG #v4l2-ctl --set-fmt-video=width=1600,height=1200,pixelformat=MJPG } # The higher resolution matches the display, and so fills the screen while # recording, but the field of view is larger in the 800x600 resolution, which # also supports a higher framerate. Thus 800x600 seems like the "natural" # resolution of the camera. Though, it is still quite low. :( V4L2_OPTIONS='-input_format mjpeg -framerate 30 -video_size 800x600' # V4L2_OPTIONS='-input_format mjpeg -framerate 15 -video_size 1280x800' # V4L2_OPTIONS='-input_format mjpeg -framerate 15 -video_size 1600x1200' drawtext='text=%{pts\\:hms}:x=5:y=h-lh-5:fontsize=18:fontcolor=white:box=1:boxcolor=0x00000099' record() { local timeout="${MAX_RECORDING_TIME+-t $MAX_RECORDING_TIME}" ffmpeg -hide_banner -loglevel error -stats \ $timeout -f video4linux2 ${V4L2_OPTIONS} -i "$VIDEO_DEVICE" \ $timeout -f "$AUDIO_DEVICE" -i default \ \ -c:v rawvideo \ -vf scale=iw/2:ih/2,drawtext="${drawtext}" \ -pix_fmt yuv420p \ -f xv selfie \ \ -c:v libxvid \ -c:a libmp3lame \ -q:v $XVID_QUALITY \ "$1" } silently() { "$@" >/dev/null 2>&1; } silently amixer-enable-mic banish record "$OUTPUT" [ -h "$OUTPUT_LINK" -o ! -e "$OUTPUT_LINK" ] && ln -sf "$OUTPUT" "$OUTPUT_LINK"