Last active
May 13, 2020 06:29
-
-
Save nimatrueway/88d555d345141751d6fa45c55ef62ca7 to your computer and use it in GitHub Desktop.
Share a single screen (when having multi-screens) on slack through webcam (bad quality though)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export V4L2L_DIR=$(mktemp -d) | |
sudo apt-get install git v4l-utils dialog libelf-dev | |
echo ======================================================================== | |
echo == REMOVING ANY PREVIOUS INSTALLATION OF v4l2loopback ================== | |
echo ======================================================================== | |
sudo apt-get purge v4l2loopback-dkms v4l2loopback-utils | |
find "/lib/modules/$(uname -r)" | grep v4l2loopback | sudo xargs rm -f | |
echo ======================================================================== | |
echo == CLONING AND ISNTALLING v4l2loopback FROM GITHUB ===================== | |
echo ======================================================================== | |
git clone https://github.com/umlaeute/v4l2loopback.git $V4L2L_DIR | |
make "--directory=$V4L2L_DIR" | |
make "--directory=$V4L2L_DIR" install | |
echo ======================================================================== | |
echo == REBUILDING KERNEL MODULES DEPENDENCY TREE =========================== | |
echo ======================================================================== | |
sudo depmod -ae |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# global options | |
DO_FLIP_HORIZONTALLY=1 # slack shares webcam horizontally-fliped | |
echo ============================================================================= | |
echo == Loading V4L2-Loopback kernel module with 2 devices \(to simulate webcam\) == | |
echo ============================================================================= | |
sudo modprobe v4l2loopback devices=2 exclusive_caps=1,1 | |
echo ============================================================================= | |
echo == Fetching V4L2-Loopback device id ========================================= | |
echo ============================================================================= | |
FIRST_VIDEO_LOOPBACK=$(v4l2-ctl --list-devices | grep --after 1 v4l2loopback-000 | tail -n -1 | awk '{ print $1 }') | |
echo ============================================================================= | |
echo == Fetching screen region information ======================================= | |
echo ============================================================================= | |
ALL_SCREENS_DATA=/tmp/v4l2loopback-all-screens-names.log | |
xrandr | grep -w connected | sed -E 's|(\S+) connected (primary )?([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+).*|\1 \3x\4 \5,\6|' > "$ALL_SCREENS_DATA" | |
echo ============================================================================= | |
echo == Showing curses dialog to select which screen to share ==================== | |
echo ============================================================================= | |
HEIGHT=15 | |
WIDTH=40 | |
CHOICE_HEIGHT=4 | |
BACKTITLE="Select the screen that you would like to share" | |
TITLE="Display Select" | |
MENU="Choose one of the displays:" | |
CHOICE=$(dialog --clear \ | |
--backtitle "$BACKTITLE" \ | |
--title "$TITLE" \ | |
--menu "$MENU" \ | |
$HEIGHT $WIDTH $CHOICE_HEIGHT \ | |
`awk '{ print ++i " " $1 "_(" $3 ")" }' "$ALL_SCREENS_DATA"` \ | |
2>&1 >/dev/tty) | |
# clean screen | |
printf "\033c" | |
echo | |
tput reset | |
echo " " | |
echo " ===========================================================" | |
echo " " | |
echo " Casting screen.. you can watch it by running: " | |
echo " " | |
echo " vlc v4l2://$FIRST_VIDEO_LOOPBACK " | |
echo " " | |
echo " ===========================================================" | |
echo " " | |
ffmpeg \ | |
-loglevel error \ | |
-f x11grab \ | |
-r 15 \ | |
-s $(sed -n "${CHOICE}p" "$ALL_SCREENS_DATA" | awk '{print $2}') \ | |
-i :0+$(sed -n "${CHOICE}p" "$ALL_SCREENS_DATA" | awk '{print $3}') \ | |
-vcodec rawvideo -pix_fmt yuv420p \ | |
$([ "$DO_FLIP_HORIZONTALLY" == 1 ] && echo "-vf hflip -c:a copy" || echo "") \ | |
-threads 0 \ | |
-f v4l2 $FIRST_VIDEO_LOOPBACK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, everything works but I had to protect (escape) the parentheses : (to simulate webcam) => \ (to simulate webcam \ ).