mpv record active

🧩 Syntax:
#!/bin/bash

# Set the hotkey to CTRL+r
hotkey="Control_L+r"

# Get the window ID of the active `mpv` window using `xwininfo`
wid=$(xwininfo -tree -root | grep -oP '(?<=\(has no name\):[ ]*).*mpv' | awk '{print $1}')

# Record the active `mpv` window using `ffmpeg`
ffmpeg -f x11grab -r 25 -s "$(xwininfo -id $wid | grep 'geometry' | awk '{print $2;}')" -i ":0.0+$(xwininfo -id $wid | grep 'Absolute upper-left X' | awk '{print $4}'),$(xwininfo -id $wid | grep 'Absolute upper-left Y' | awk '{print $4}')" -vcodec libx264 -preset ultrafast -qp 0 -threads 0 "$(date +%Y-%m-%d_%H-%M-%S).mp4"

# Send the hotkey to stop the recording
xdotool keyup $hotkey