aboutsummaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
Diffstat (limited to '.local')
-rwxr-xr-x.local/share/bin/ccpreview78
1 files changed, 43 insertions, 35 deletions
diff --git a/.local/share/bin/ccpreview b/.local/share/bin/ccpreview
index 98843a4..a835ab4 100755
--- a/.local/share/bin/ccpreview
+++ b/.local/share/bin/ccpreview
@@ -1,48 +1,56 @@
#!/bin/sh
-caffeine
-
-PCI_ADDRESS="0000:00:14.0"
-# USB_BUS_NUM="11"
-USB_BUS_NUM="12"
-VIDEO_DEVICE="/dev/v4l/by-path/pci-$PCI_ADDRESS-usb-0:$USB_BUS_NUM:1.0-video-index0"
-AUDIO_DEVICE="alsa:usbstream=CARD=MS2109"
+# capture card sysfs device path
+SYSFS_PATH="/devices/pci0000:00/0000:00:14.0/usb1/1-12"
+# script args
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)"
+# find audio device (pulseaudio)
+PULSE_DEVICE="$(pactl -f json list sources | jq \
+ --arg sysfs_path "$SYSFS_PATH" --raw-output \
+ '.[] | select(.properties["sysfs.path"] | . != null and startswith($sysfs_path)) | .name')"
+AUDIO_URL="av://pulse:$PULSE_DEVICE"
-# 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"
+# find video device (video4linux)
+V4L_PATH="$(find "/sys$SYSFS_PATH" -name 'video4linux' | head -n1)"
+V4L_PATH="$(find "$V4L_PATH" -name 'index' | xargs grep -l '^0$')"
+V4L_PATH="$(echo "$V4L_PATH" | sed 's#/index$#/uevent#')"
+VIDEO_DEVICE="$(. "$V4L_PATH" ; echo "/dev/$DEVNAME")"
+VIDEO_DEVICE="$(readlink -f "$VIDEO_DEVICE")"
+VIDEO_URL="av://v4l2:$VIDEO_DEVICE"
-# echo "link $CAPTURE_FR -> $OUTPUT_FR"
-# echo "link $CAPTURE_FL -> $OUTPUT_FL"
-
-# pw-link "$CAPTURE_FL" "$OUTPUT_FL"
-# pw-link "$CAPTURE_FR" "$OUTPUT_FR"
+RESOLUTION="${WIDTH}x${HEIGHT}"
-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"
+# set capture card v4l parameters
+v4l2-ctl --silent --device "$VIDEO_DEVICE" \
+ --set-parm "$FRAMERATE" \
+ --set-fmt-video "width=$WIDTH,height=$HEIGHT,pixelformat=MJPG" \
+ --set-ctrl "brightness=0,contrast=128,saturation=128,hue=0"
+# preview window
mpv \
- --no-config \
- --input-conf=/dev/null --profile=low-latency --untimed --no-correct-pts \
- --no-osc --no-input-default-bindings --cache=no --pause=no --force-seekable=no \
- --demuxer-lavf-format=video4linux2 \
- --demuxer-lavf-o-set=input_format=mjpeg,framerate="$FRAMERATE",resolution="$RESOLUTION",rw_timeout=30000000 \
- --demuxer-thread=yes \
- "av://v4l2:$DEVICE"
-# --audio-samplerate=48000 --audio-channels=stereo --audio-file="av://$AUDIO_DEVICE" \
-# --lavfi-complex="[aid1] amix [ao]; [v] [ao] concat=n=1:v=1:a=1 [vo] [ao]" \
-
-# pw-link -d "$CAPTURE_FL" "$OUTPUT_FL"
-# pw-link -d "$CAPTURE_FR" "$OUTPUT_FR"
+ --msg-level=input=no --no-config --input-conf=/dev/null \
+ --no-osc --no-input-default-bindings --pause=no --force-seekable=no \
+ \
+ --no-cache --untimed --no-correct-pts \
+ --no-demuxer-thread \
+ --video-sync=audio \
+ --audio-buffer=0 \
+ --vd-lavc-threads=1 \
+ --cache-pause=no \
+ --interpolation=no \
+ --video-latency-hacks=yes \
+ --stream-buffer-size=4k \
+ \
+ --demuxer-lavf-o-add=fflags=+nobuffer \
+ --demuxer-lavf-analyzeduration=0 \
+ --demuxer-lavf-o-add=input_format=mjpeg \
+ --demuxer-lavf-o-add=framerate="$FRAMERATE" \
+ --demuxer-lavf-o-add=resolution="$RESOLUTION" \
+ --demuxer-lavf-o-add=rw_timeout=30000000 \
+ \
+ "$VIDEO_URL" --audio-file="$AUDIO_URL"