record-game: lossless recording (huge filesize) script - randomcrap - random crap programs of varying quality
HTML git clone git://git.codemadness.org/randomcrap
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit f786de2410fe176d27e6807002a06ad167149cd6
DIR parent 6e572f98014c00fda062585fc6eb97be0e654b95
HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sun, 31 May 2026 14:56:48 +0200
record-game: lossless recording (huge filesize) script
add audio flags (but not working yet on my system using Alsa)
Diffstat:
M record-desktop.sh | 4 ++++
A record-game.sh | 77 +++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+), 0 deletions(-)
---
DIR diff --git a/record-desktop.sh b/record-desktop.sh
@@ -6,6 +6,10 @@
# xrandr for desktop dimensions.
# xdotool for specific window.
# xwininfo for selecting a window and getting the $WINDOWID.
+#
+# Docs:
+# - https://trac.ffmpeg.org/wiki/Capture/Desktop
+# - https://ffmpeg.org/ffmpeg-devices.html#x11grab
spec="${DISPLAY:-:0.0}"
DIR diff --git a/record-game.sh b/record-game.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+# record X11 desktop to .webm file/stdout.
+# can record a specific window.
+#
+# Dependencies: ffmpeg for recording.
+# xrandr for desktop dimensions.
+# xdotool for specific window.
+# xwininfo for selecting a window and getting the $WINDOWID.
+#
+# Docs:
+# - https://trac.ffmpeg.org/wiki/Capture/Desktop
+# - https://ffmpeg.org/ffmpeg-devices.html#x11grab
+
+spec="${DISPLAY:-:0.0}"
+
+# argument 1 is the $WINDOWID.
+win=""
+if test -n "$1"; then
+ win="$1"
+fi
+
+# special parameter "sel": click on a window to get the window id and record it.
+if test x"$win" = x"sel"; then
+ win=$(xwininfo | sed -nE 's/.*Window id: (0x[0-9a-f]+).*/\1/p')
+ if test -z "$win"; then
+ echo "could not get window id" >&2
+ exit 1
+ fi
+fi
+
+# get window geometry information if window id specified.
+if test -n "$win"; then
+ # NOTE: a limitation is that the window should not be moved.
+ eval $(xdotool getwindowgeometry --shell "$win")
+ if test -z "$X" || test -z "$Y"; then
+ echo "unknown window size" >&2
+ exit 1
+ fi
+ BORDER="3" # workaround: don't record border: for me it's 3 pixels.
+ X=$((X + BORDER))
+ Y=$((Y + BORDER))
+# WIDTH=$((WIDTH - BORDER))
+# HEIGHT=$((HEIGHT - BORDER))
+
+ spec="${spec}+$X,$Y"
+ size="${WIDTH}x${HEIGHT}"
+else
+ # record whole screen.
+ size=$(xrandr --current | sed -nE 's/.*current ([0-9]+) x ([0-9]+).*/\1x\2/p')
+ if test -z "$size"; then
+ echo "unknown monitor/desktop size" >&2
+ exit 1
+ fi
+fi
+
+# with audio (alsa), stereo (2 channels):
+#withaudio=""
+
+
+# alsa, device: hw:CARD[,DEV[,SUBDEV]]
+# list: arecord -l, cat /proc/asound/cards, cat proc/asound/devices
+withaudio="-f alsa -ac 2 -i hw:1"
+
+#withaudio="-f pulse -ac 2 -i default"
+
+tm=$(date +'%Y%m%dT%H%M%S')
+
+filename="$HOME/tmp/recording_${tm}.mkv"
+
+# lossless recording, fast but huge filesize.
+ffmpeg $withaudio \
+ -video_size "$size" -framerate 60 -f x11grab -i :0.0 -c:v libx264rgb -crf 0 -preset ultrafast -color_range 2 "$filename"
+
+printf 'Recorded to file: %s\n' "$filename"
+
+# NOTE: to re-encode recording to smaller file:
+# ffmpeg -i output.mkv -c:v libx264rgb -crf 0 -preset veryslow output-smaller.mkv