Last active
May 14, 2021 21:07
-
-
Save kkavod/3cd3145e9547e6f18852 to your computer and use it in GitHub Desktop.
Captures a window and creates a virtual camera from it, uses GStreamer 1.0 on Linux
This file contains 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 | |
# This pipeline is based on https://gist.github.com/lifning/1857803 | |
# but is updated for GStreamer 1.0 and also crops the window | |
# Tested on Chrome with https://github.com/bluetiger9/v4l2loopback | |
# with exclusive_caps enabled: | |
# $ sudo modprobe v4l2loopback devices=8 exclusive_caps=1 | |
DEV=$(zenity --file-selection \ | |
--filename=/dev/video0 \ | |
--file-filter='V4L2 loopback devices | video*') | |
echo "Select a window to capture..." | |
# Could be refactored to use one xwininfo call instead of 3 | |
XID=$(xwininfo -int | grep 'Window id' | awk '{print $4}') | |
WW=$(xwininfo -id $XID | grep 'Width' | awk '{print $2}') | |
WH=$(xwininfo -id $XID | grep 'Height' | awk '{print $2}') | |
# camera width/height | |
CW=640 | |
CH=360 | |
# start x/y padding | |
SX=20 | |
SY=40 | |
# end x/y padding | |
EX=20 | |
EY=55 | |
echo endx=$[$CW-$EX] endy=$[$CH-$EY] | |
gst-launch-1.0 --eos-on-shutdown \ | |
\ | |
ximagesrc use-damage=false show-pointer=false xid=$XID startx=$SX starty=$SY endx=$[$WW-$EX] endy=$[$WH-$EY] \ | |
! videoconvert \ | |
! videoscale method=1 add-borders=true \ | |
! video/x-raw,width=$CW,height=$CH \ | |
! videorate \ | |
! tee name=displaypipe \ | |
! tee name=recordpipe \ | |
! queue \ | |
! v4l2sink device=$DEV \ | |
\ | |
displaypipe. \ | |
! queue \ | |
! autovideosink \ | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screenshot:
![screencamera](https://cloud.githubusercontent.com/assets/10680473/13896618/a4e6335c-ed92-11e5-8349-532ebc98b853.png)