Window recording with ffmpeg

Author Mitja Felicijan <mitja.felicijan@gmail.com> 2026-05-06 15:31:27 +0200
Committer Mitja Felicijan <mitja.felicijan@gmail.com> 2026-05-06 15:31:27 +0200
Commit de060174ef843829a9340a46e120508bf7c4cab1 (patch)
-rw-r--r-- .config/i3/config 6
-rwxr-xr-x .shenanigans.sh 28
2 files changed, 30 insertions, 4 deletions
diff --git a/.config/i3/config b/.config/i3/config
...
164
client.focused_inactive $dark         $dark         $light        $light
164
client.focused_inactive $dark         $dark         $light        $light
165
client.urgent           $secondary    $secondary    $light        $light
165
client.urgent           $secondary    $secondary    $light        $light
166
  
166
  
167
# Workspace 1 only has floating windows
167
# Workspaces with only floating windows
168
for_window [workspace="1"] floating enable
168
for_window [workspace="^(1|5)$"] floating enable
169
  
169
  
170
# Expections for opening in floating mode where XSetClassHint is set to floating
170
# Expections for opening in floating mode where XSetClassHint is set to floating
171
for_window [class="^(mpv|SimpleScreenRecorder|Thunar|transmission|Xmagnify)$"] floating enable
171
for_window [class="^(floating|mpv|SimpleScreenRecorder|Thunar|transmission|Xmagnify)$"] floating enable
172
for_window [title="^(Stalag|game)$"] floating enable
172
for_window [title="^(Stalag|game)$"] floating enable
diff --git a/.shenanigans.sh b/.shenanigans.sh
1
# Software list:
1
# Software list:
2
#   xss-lock xkbset xclip xsel cifs-utils picom
2
#   xss-lock xkbset xclip xsel xwininfo cifs-utils picom ffmpeg
3
#   vim git tmux maim mc htop entr rsync jq rofi stow newsboat 
3
#   vim git tmux maim mc htop entr rsync jq rofi stow newsboat 
4
#   st rsync curl hstr tree make gdb nvtop ctags mpv lazygit fd
4
#   st rsync curl hstr tree make gdb nvtop ctags mpv lazygit fd
5
  
5
  
...
83
	printf "%-18s %s\n" "San Francisco:" "$(TZ='America/Los_Angeles' date +'%a %H:%M')"
83
	printf "%-18s %s\n" "San Francisco:" "$(TZ='America/Los_Angeles' date +'%a %H:%M')"
84
	printf "%-18s %s\n" "New York:" "$(TZ='America/New_York' date +'%a %H:%M')"
84
	printf "%-18s %s\n" "New York:" "$(TZ='America/New_York' date +'%a %H:%M')"
85
}
85
}
  
86
  
  
87
record() {
  
88
	mkdir -p "$HOME/Videos"
  
89
	win=$(xwininfo -int | awk '/Window id:/{print $4; exit}')
  
90
	[ -z "$win" ] && { echo "no window picked"; exit 1; }
  
91
  
  
92
	eval $(
  
93
		xwininfo -id "$win" | awk '
  
94
			/Absolute upper-left X:/{x=$4}
  
95
			/Absolute upper-left Y:/{y=$4}
  
96
			/Width:/{w=$2}
  
97
			/Height:/{h=$2}
  
98
		END{printf("X=%s;Y=%s;W=%s;H=%s\n", x, y, w, h)}
  
99
		'
  
100
	)
  
101
  
  
102
	if [ -z "$W" ] || [ -z "$H" ]; then
  
103
		echo "failed to get geometry"; exit 1
  
104
	fi
  
105
  
  
106
	ts=$(date '+%F-%H-%M-%S')
  
107
	out="$HOME/Videos/record-${ts}.mp4"
  
108
	echo "Recording ${W}x${H}+${X},${Y} -> ${out}"
  
109
  
  
110
	ffmpeg -y -f x11grab -video_size "${W}x${H}" -framerate 60 -i "${DISPLAY:-:0.0}+${X},${Y}" -c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p "$out"
  
111
}