webcam (816B)
1 #!/bin/sh 2 WEBCAM_DRIVER=v4l2 3 WEBCAM_DEVICE=$(find /dev -name "video*" | sort | sed -n '1p') 4 5 NOTIFY_NA=" Webcam 6 Install a webcam first!" 7 NOTIFY_OPEN_MSG=" Webcam 8 $WEBCAM_DEVICE is open now." 9 NOTIFY_CLOSE_MSG=" Webcm 10 $WEBCAM_DEVICE has been closed." 11 12 if [ ! -e "$WEBCAM_DEVICE" ]; then 13 notify "$NOTIFY_NA" 14 exit 2 15 fi 16 17 case "$1" in 18 shot) 19 ffmpeg -y -loglevel quiet -f "$WEBCAM_DRIVER" -i "$WEBCAM_DEVICE" \ 20 -frames:v 1 -f image2 -strftime 1 "$HOME/webcam-%Y-%m-%d-%H%M%S.jpg" 21 ;; 22 *) 23 ps ax | grep "mpv*av://$WEBCAM_DRIVER:$WEBCAM_DEVICE*" | \ 24 awk '{print $1}' | while read -r PID; do kill -9 "$PID"; wait; done 25 notify "$NOTIFY_OPEN_MSG" 26 mpv "av://$WEBCAM_DRIVER:$WEBCAM_DEVICE" --title=webcam \ 27 --profile=low-latency --untimed --load-scripts=no --no-osc 28 notify "$NOTIFY_CLOSE_MSG" 29 ;; 30 esac