Updated capture card script to have very small delay

This commit is contained in:
Siina Mashek 2021-01-23 12:23:17 +02:00
parent ceb7b7c376
commit edef675cf9

View File

@ -5,42 +5,32 @@
# -- Siina, 2020.11.09
#
# Requirements:
# - alsa-utils
# - libv4l (brought in by USE=v4l)
# - mpv
#
# Tools I used to figure this shit out
# - arecord, aplay
# - ffmpeg
# - lspci
# - Lots of searching through ancient fragments of the 'net
#
# TODO:
# - Capture the exact PIDs of the launched mpv / alsaloop to prevent
# shutting down any other loops / mpv that happen to be open
## 0 - Find input and output sources with pactl
input="alsa_input.usb-AVerMedia_AVerMedia_USB_Device_52030300003520-02.iec958-stereo"
output="alsa_output.pci-0000_0b_00.4.analog-stereo"
## 1 - Configure video
# Set our device to 1080p otherwise it defaults to 480p
v4l2-ctl --set-fmt-video=width=1920,height=1080
## 2 - Launch viewer
# Connect to capture card and display captured images immediately
# Send to background so we can initiate the loop below
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
while :
do
alsaloop -C hw:2,0 -P hw:1,0 &
if [[ $(pgrep -f alsaloop) -gt 0 ]]; then
break
fi
done
## 3 - Connect audio, send to background for loop
pacat -r --latency-msec=1 -d $input | pacat -p --latency-msec=1 -d $output &
## 4 - Cleanup
# Watch for mpv to exit
while pgrep -f mpv >/dev/null; do
sleep 3
continue
done
# Kill the alsaloop when mpv exits, then terminate this script
kill -9 $(pgrep -f alsaloop)
# Kill pacat since it's not needed
kill -9 $(pgrep -f pacat)
exit