aboutsummaryrefslogtreecommitdiff
path: root/.local/share/bin/ccpreview
blob: d0f8525d7c6f61a0fe24fadf2d301eb4fa2300d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh

caffeine

PCI_ADDRESS="0000:00:14.0"
USB_BUS_NUM="2"
VIDEO_DEVICE="/dev/v4l/by-path/pci-$PCI_ADDRESS-usb-0:$USB_BUS_NUM:1.0-video-index0"

WIDTH="$1"
HEIGHT="$2"
FRAMERATE="$3"
RESOLUTION="${WIDTH}x${HEIGHT}"
DEVICE="$(readlink -f "$VIDEO_DEVICE")"
DEVICE_INDEX="$(grep "usb-$PCI_ADDRESS-$USB_BUS_NUM" /proc/asound/card*/usbmixer | cut -d: -f1 | tr -cd '[:digit:]')"
DEFAULT_SINK_ALIAS="$(pw-metadata 0 default.audio.sink | grep -Po "value:'(.*?)'" | head -c-2 | cut -c8- | jq --raw-output .name)"

CAPTURE_FL="alsa:pcm:$DEVICE_INDEX:front:$DEVICE_INDEX:capture:capture_0"
CAPTURE_FR="alsa:pcm:$DEVICE_INDEX:front:$DEVICE_INDEX:capture:capture_1"
OUTPUT_FL="$DEFAULT_SINK_ALIAS:playback_0"
OUTPUT_FR="$DEFAULT_SINK_ALIAS:playback_1"

echo "link $CAPTURE_FR -> $OUTPUT_FR"
echo "link $CAPTURE_FL -> $OUTPUT_FL"

pw-link "$CAPTURE_FL" "$OUTPUT_FL"
pw-link "$CAPTURE_FR" "$OUTPUT_FR"

v4l2-ctl -d "$DEVICE" --set-parm "$FRAMERATE"
v4l2-ctl -d "$DEVICE" --set-fmt-video "width=$WIDTH,height=$HEIGHT,pixelformat=MJPG"
v4l2-ctl -d "$DEVICE" --set-ctrl "brightness=0,contrast=128,saturation=128,hue=0"

mpv --demuxer-lavf-format=video4linux2 \
	--demuxer-lavf-o-set=input_format=mjpeg,framerate="$FRAMERATE",resolution="$RESOLUTION" \
	--cache=no \
	--pause=no \
	--force-seekable=no \
	--no-osc \
	--no-input-default-bindings \
	"av://v4l2:$DEVICE"

pw-link -d "$CAPTURE_FL" "$OUTPUT_FL"
pw-link -d "$CAPTURE_FR" "$OUTPUT_FR"