Skip to content

Instantly share code, notes, and snippets.

@ericfont
Last active May 6, 2018 07:01
Show Gist options
  • Select an option

  • Save ericfont/0358a209f7aafda25feef357db03f79b to your computer and use it in GitHub Desktop.

Select an option

Save ericfont/0358a209f7aafda25feef357db03f79b to your computer and use it in GitHub Desktop.
records from webcam when midi play button pressed and stops when stop button pressed
#!/bin/bash
device="/dev/v4l/by-id/usb-046d_HD_Pro_Webcam_C920_0AE6127F-video-index0"
takenum=1
aseqdump -p "MPKmini2" | \
while IFS=" ," read src ev1 ev2 ch label1 data1 label2 data2 rest; do
case "$ev1 $ev2 $data1" in
"Note on 45" )
killall ffmpeg
if fuser -v $device > /dev/null 2>&1; then
printf '%s\n' "device in use"
else
printf '%s\n' "device available"
fi
timestamp=`date +%Y%m%d-%H%M%S`;
until pids=$(pidof ffmpeg)
do
ffmpeg -f v4l2 -s 1920x1080 -r 30 -input_format h264 -i $device -an -c:v copy -f avi - | tee "wc-$1 take-$takenum $timestamp.avi" | mpv - &
sleep 0.2
done
((takenum++));
;;
"Note on 46" )
killall ffmpeg;
killall mpv;
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment