Skip to content

Instantly share code, notes, and snippets.

@daktak
Last active December 22, 2023 20:34
Show Gist options
  • Save daktak/a3a1025cd9e4ce6e31b5209044877570 to your computer and use it in GitHub Desktop.
Save daktak/a3a1025cd9e4ce6e31b5209044877570 to your computer and use it in GitHub Desktop.
Ffmpeg record selected window. Written for Qubes-OS
#!/bin/bash
#pass in alsa or pulse to record from sound device
IFS=$
#omit the top pixels to hide tabs and address bar
FIREFOX_Y_BUFFER=94
FIREFOX_X_BUFFER=2
if [[ ${1} =~ alsa ]] ; then
sound="-f alsa -ac 2 -i hw:0"
fi
if [[ ${1} =~ pulse ]] ; then
sound="-f pulse -ac 2 -i default"
fi
output=`xwininfo`
width=`echo $output | grep Width: | awk '{print $2}'`
height=`echo $output | grep Height: | awk '{print $2}'`
topleftX=`echo $output | grep "Absolute upper-left X:" | awk '{print $4}'`
topleftY=`echo $output | grep "Absolute upper-left Y:" | awk '{print $4}'`
winid=`echo $output | grep "Window id:" | awk '{print $4}'`
window=`xprop -id $winid WM_CLASS`
window=${window##*WM_CLASS(STRING) = }
window=${window##*, }
window=${window//\"}
window=`echo $window | sed 's/:/_/g'`
if [[ ${window} =~ Firefox ]] || [[ ${window} =~ Icecat ]] ; then
topleftY=$(( ${topleftY} + ${FIREFOX_Y_BUFFER} ))
topleftX=$(( ${topleftX} + ${FIREFOX_X_BUFFER} ))
width=$(( ${width} - ${FIREFOX_X_BUFFER} ))
height=$(( ${height} - ${FIREFOX_Y_BUFFER} ))
fi
ffmpeg -video_size ${width}x${height} -framerate 25 -f x11grab -i :0.0+${topleftX},${topleftY} ${sound} ${window}.mp4
@daktak
Copy link
Author

daktak commented Oct 1, 2018

I installed most of the below rpms from https://download1.rpmfusion.org and https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/25/Everything/x86_64/os/Packages into Dom0 to get ffmpeg to work.

dirac-libs.rpm
dirac.rpm
ffmpeg-compat.rpm
ffmpeg-libs.rpm
ffmpeg.rpm
fribidi-devel.rpm
fribidi.rpm
jack-audio-connection-kit.rpm
lame-libs.rpm
lame.rpm
libass.rpm
libavc1394.rpm
libavdevice.rpm
libdc1394.rpm
libffado.rpm
libmfx.rpm
librtmp-devel.rpm
librtmp.rpm
libva-intel-driver.rpm
libva.rpm
libxml++.rpm
ocl-icd-devel.rpm
ocl-icd.rpm
openal-soft.rpm
opencl-filesystem.rpm
opencl-headers.rpm
opencl-utils-devel.rpm
opencl-utils.rpm
openjpg-libs.rpm
openjpg.rpm
rpmlist.txt
rtmpdump.rpm
schroedinger.rpm
x264-libs.rpm
x264.rpm
x265-libs.rpm
xvidcore.rpm

also added
exlude=ffmpeg* lame* ocl-icd* libmfx* libva*
to /etc/yum.conf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment