|
#!/bin/bash |
|
|
|
# Preliminary steps (void linux): |
|
# sudo xbps-install -Su v4l2loopback wf-recorder |
|
# (don't forget to reboot if new Kernel version was upgraded) |
|
# |
|
|
|
# Too lazy to autodetect active monitor resolution |
|
WIDTH=2560 |
|
HEIGHT=1440 |
|
|
|
|
|
# Detect and load kernel module if needed |
|
lsmod | grep v4l2loopback \ |
|
&& echo "Kernel module detected" \ |
|
|| ( \ |
|
echo "Need to modprobe v4l2loopback kernel module, please authorize:" \ |
|
&& sudo modprobe v4l2loopback \ |
|
) |
|
|
|
# List devices and exit when run without args |
|
if [ -z "$1" ]; then |
|
v4l2-ctl --list-devices |
|
echo "Please rerun sharescreen with the device device path of the Dummy listed above" |
|
echo "Ex: sharescreen /dev/video4" |
|
exit 1 |
|
fi |
|
|
|
device=$1 |
|
|
|
# Let device timout to prevent device-busy errors |
|
# v4l2-ctl -d $device -c timeout=3000 # unverified |
|
|
|
# Set capabilities for device, so chrom*/webrtcvideocapturer.cc |
|
# based software like discord is happy. |
|
# |
|
# https://gstreamer.freedesktop.org/documentation/video/video-format.html?gi-language=c#GstVideoFormat |
|
# GST_VIDEO_FORMAT_YUY2 (4) – packed 4:2:2 YUV (Y0-U0-Y1-V0 Y2-U2-Y3-V2 Y4 ...) |
|
# Suspicion that matching GST format is `YUY2` is further backed |
|
# by output of `gst-device-monitor-1.0` and finding section of webcam hardware |
|
# that's works in chosen software |
|
v4l2loopback-ctl set-caps \ |
|
"video/x-raw, format=YUY2, width=$WIDTH, height=$HEIGHT" \ |
|
$device || \ |
|
echo "WARN; Failed to set format, rmmmod / modprobe to free device?" |
|
|
|
## |
|
# In case your v4l2loopback utility is a different version, from what I can |
|
# dump, the significant commands my version executes is: |
|
# |
|
# v4l2-ctl -d /dev/video4 -c keep_format=1 |
|
# v4l2-ctl -d /dev/video4 -c sustain_framerate=1 |
|
# gst-launch-1.0 videotestsrc num-buffers=1 '!' video/x-raw,format=YUY2,width=2560,height=1440 '!' v4l2sink device=/dev/video4 |
|
# |
|
|
|
# Start screen-capture and dump the frames into chosen loopback-devices |
|
wf-recorder --muxer=v4l2 --file=$device \ |
|
-c rawvideo -x yuyv422 |
|
|
Thanks. It works.