-
-
Save hickscorp/dce5fa450b28be21fd1640c9f5615de2 to your computer and use it in GitHub Desktop.
ffmpeg screen casting
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 | |
if [[ $EUID -ne 0 ]]; then | |
exec sudo $0 $* | |
exit 0 | |
fi | |
function at_exit { | |
echo "Removing capture module..." | |
rmmod v4l2loopback 2> /dev/null | |
} | |
trap at_exit EXIT | |
SCREEN=${1:-0} | |
MONITOR=$(xrandr --listmonitors | awk -e '/^\s+'$SCREEN':/ { print $3 }') | |
VIDEO_NR=$(( $(find /dev -name 'video*' | sort -nr | head -n1 | sed -e 's#/dev/video##') + 1 )) | |
DEVICE="/dev/video$VIDEO_NR" | |
echo "Loading module v4l2loopback over video $DEVICE..." | |
modprobe v4l2loopback video_nr=$VIDEO_NR 'card_label=screenCap' exclusive_caps=1 | |
echo "Calculating capture geometry for monitor $MONITOR" | |
X=$(echo $MONITOR | awk -F+ '{ print $2 }') | |
Y=$(echo $MONITOR | awk -F+ '{ print $3 }') | |
WIDTH=$(echo $MONITOR | awk -Fx '{ print $1 }' | awk -F/ '{ print $1 }') | |
HEIGHT=$(echo $MONITOR | awk -Fx '{ print $2 }' | awk -F/ '{ print $1 }') | |
echo "Starting capture with geometry ${WIDTH}x${HEIGHT}@${X},${Y} to device $DEVICE..." | |
ffmpeg -loglevel error \ | |
-f x11grab \ | |
-r 30 \ | |
-s ${WIDTH}x${HEIGHT} \ | |
-i :0.0+${X},${Y} \ | |
-vcodec rawvideo \ | |
-pix_fmt yuv420p \ | |
-threads 0 \ | |
-f v4l2 $DEVICE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment