From 34bcc9c5c194ada8b2a17a31d2b72e16cdb7c719 Mon Sep 17 00:00:00 2001 From: Siina Mashek Date: Wed, 2 Dec 2020 05:19:20 +0200 Subject: [PATCH] Implemented naive tracking of PIDs to close mpv+alsaloop --- bin/capturecard | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/bin/capturecard b/bin/capturecard index 878b09d..08e03a5 100755 --- a/bin/capturecard +++ b/bin/capturecard @@ -16,21 +16,24 @@ # - Lots of searching through ancient fragments of the 'net # # TODO: -# - Capture and retry to connect audio +# - Capture the exact PIDs of the launched mpv / alsaloop to prevent +# shutting down any other loops / mpv that happen to be open # Set our device to 1080p otherwise it defaults to 480p v4l2-ctl --set-fmt-video=width=1920,height=1080 # Connect to capture card and display captured images immediately # Send to background so we can initiate the loop below -mpv av://v4l2:/dev/video0 --profile=low-latency --untimed & - -# audio can't connect until video is established due to a constant -# powercycle when inactive, likely due to lack of proper driver -sleep 3 +mpv --title="Capture Card" av://v4l2:/dev/video0 --profile=low-latency --untimed & # Run a loop for the capture card digital audio to be sent to my desktop audio -alsaloop -C hw:2,0 -P hw:1,0 +alsaloop -C hw:2,0 -P hw:1,0 & -# Let's exit this shit when done +# Watch for mpv to exit +while pgrep -f mpv >/dev/null; do + continue +done + +# Kill the alsaloop when mpv exits, then terminate this script +kill -9 $(pgrep -f alsaloop) exit