local-bin/remedios/capturecard

37 lines
1.1 KiB
Text
Raw Normal View History

2020-11-10 01:04:20 +02:00
#!/bin/sh
# This took me far too long to figure out how to do but
# I think I've learned a lot from it. What a great exercise!
# These comments are for my future-self and whomever else.
# -- Siina, 2020.11.09
#
# Requirements:
# - libv4l (brought in by USE=v4l)
# - mpv
## 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
2020-11-10 01:04:20 +02:00
# Set our device to 1080p otherwise it defaults to 480p
v4l2-ctl --set-fmt-video=width=1920,height=1080
## 2 - Launch viewer
2020-11-10 01:04:20 +02:00
# 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 &
2020-11-10 01:04:20 +02:00
## 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
2020-11-10 01:04:20 +02:00
# Kill pacat since it's not needed
kill -9 $(pgrep -f pacat)
2020-11-10 01:04:20 +02:00
exit