remove: uninstall unused ffmpeg screen-replay feature

Deleted screen_replay.sh (x11grab ring-buffer) and kill_stale_recorders.sh
(stale-ffmpeg killer). Removed autostart exec and Mod+Shift+F12 binding from
i3/config; removed replay startup from dwm-session. Both scripts archived in
testsAndMisc-archive.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-06-06 10:44:36 +02:00
parent 10f3a6649b
commit 8fdbfd8411
5 changed files with 62 additions and 284 deletions

View File

@ -0,0 +1,27 @@
{
"intent": "Remove unused ffmpeg instant-replay feature and move scripts to testsAndMisc-archive.",
"scope": [
"linux_configuration/scripts/single_use/utils/screen_replay.sh",
"linux_configuration/scripts/periodic_background/system-maintenance/bin/kill_stale_recorders.sh",
"linux_configuration/scripts/periodic_background/i3-configuration/i3/config",
"linux_configuration/dwm/bin/dwm-session"
],
"changes": [
"Deleted screen_replay.sh (ffmpeg x11grab ring-buffer daemon + save/stop/status commands)",
"Deleted kill_stale_recorders.sh (written to clean up stray ffmpeg x11grab processes from the replay daemon)",
"Removed 'Screen replay buffer' exec and keybinding lines from i3/config",
"Removed replay= variable and startup call from dwm-session"
],
"verification": [
{
"command": "grep -r screen_replay testsAndMisc/linux_configuration",
"result": "pass",
"evidence": "No remaining references to screen_replay in linux_configuration after edits"
}
],
"risks": ["None — feature was unused; no running daemon to kill"],
"rollback": [
"Restore scripts from testsAndMisc-archive/linux_configuration/scripts/",
"Re-add exec and bindsym lines to i3/config and replay lines to dwm-session"
]
}

View File

@ -0,0 +1,30 @@
#!/bin/sh
# dwm session launcher — invoked by lightdm via /usr/share/xsessions/dwm.desktop
# Mirrors the i3 config's autostart. Deliberately NOT `set -e` (see installer).
set -u
# XDG autostart .desktop files (nm-applet tray etc.)
command -v dex >/dev/null 2>&1 && dex --autostart --environment dwm &
# lock the screen on suspend (i3 used xss-lock + i3lock)
if command -v xss-lock >/dev/null 2>&1 && command -v i3lock >/dev/null 2>&1; then
xss-lock --transfer-sleep-lock -- i3lock --nofork &
fi
# network applet, compositor, notes app — all installed; harmless if duplicated
command -v nm-applet >/dev/null 2>&1 && nm-applet &
command -v picom >/dev/null 2>&1 && picom &
command -v simplenote >/dev/null 2>&1 && simplenote &
# restore wallpaper if feh saved one
[ -x "$HOME/.fehbg" ] && "$HOME/.fehbg" &
# repo helpers (real current paths under single_use/utils); guarded in case moved
idle="$HOME/testsAndMisc/linux_configuration/scripts/single_use/utils/turn_off_auto_idle_screen_shutdown.sh"
[ -x "$idle" ] && bash "$idle" --watch-controller &
# lightweight status bar (root window name)
command -v dwmstatus >/dev/null 2>&1 && dwmstatus &
# the window manager — must be last; replaces this shell
exec dwm

View File

@ -57,6 +57,11 @@ tiling_drag modifier titlebar
# start a terminal
bindsym $mod+Return exec terminator
# scratchpad calculator: floating popup running the live-calc widget (type
# math, results appear as you type; Ctrl-D to close)
bindsym $mod+c exec --no-startup-id /home/kuhy/testsAndMisc/linux_configuration/zsh/calc-popup.sh
for_window [window_role="calc"] floating enable, border pixel 3, resize set 820 px 220 px, move position center
# kill focused window
bindsym $mod+Shift+q kill
@ -213,7 +218,3 @@ bar {
}
bindsym $mod+d exec "dmenu_run -nf '#F8F8F2' -nb '#282A36' -sb '#6272A4' -sf '#F8F8F2' -fn 'monospace-10' -p 'dmenu%'"
# Screen replay buffer
exec --no-startup-id /home/kuchy/linux-configuration/scripts/utils/screen_replay.sh start
bindsym $mod+Shift+F12 exec --no-startup-id /home/kuchy/linux-configuration/scripts/utils/screen_replay.sh save

View File

@ -1,67 +0,0 @@
#!/bin/bash
# Kill stray recorders and .NET profilers that were left running unintentionally.
#
# Targets based on the resource-usage report: ffmpeg x11grab and dotnet
# trace/monitor/ust processes can easily burn GiB of RAM and many CPU-hours
# after whatever session started them has ended.
#
# Usage:
# kill_stale_recorders.sh # interactive: lists matches, prompts
# kill_stale_recorders.sh --force # non-interactive: kill all matches
# kill_stale_recorders.sh --dry-run # only list, don't kill
set -euo pipefail
PATTERNS=(
'ffmpeg.*x11grab'
'ffmpeg.*-f[[:space:]]+x11grab'
'dotnet-trace'
'dotnet-monitor'
'dotnet-ust'
)
mode='prompt'
case ${1:-} in
--force) mode='force' ;;
--dry-run) mode='dry' ;;
-h | --help)
sed -n '2,12p' "$0"
exit 0
;;
esac
mapfile -t matches < <(
for pat in "${PATTERNS[@]}"; do
pgrep -af "$pat" 2> /dev/null || true
done | sort -u
)
if ((${#matches[@]} == 0)); then
echo 'No stale recorder/profiler processes found.'
exit 0
fi
echo 'Stale processes:'
printf ' %s\n' "${matches[@]}"
if [[ $mode == dry ]]; then
exit 0
fi
if [[ $mode == prompt ]]; then
read -r -p 'Kill these? [y/N] ' answer
[[ $answer == [yY] ]] || {
echo 'Aborted.'
exit 0
}
fi
killed=0
for line in "${matches[@]}"; do
pid=${line%% *}
[[ -n $pid ]] || continue
if kill "$pid" 2> /dev/null; then
killed=$((killed + 1))
fi
done
echo "Sent SIGTERM to $killed process(es)."

View File

@ -1,213 +0,0 @@
#!/usr/bin/env bash
# screen_replay.sh - Instant replay buffer for Linux (X11)
# Continuously records screen in segments; on hotkey, saves last 90 seconds
# and immediately plays it in mpv.
set -euo pipefail
REPLAY_DIR="${REPLAY_DIR:-/tmp/screen_replay}"
SAVE_DIR="${SAVE_DIR:-$HOME/Videos/replays}"
PID_FILE="$REPLAY_DIR/daemon.pid"
LOCK_FILE="$REPLAY_DIR/save.lock"
BUFFER_SECS="${BUFFER_SECS:-90}"
SEG_SECS=15
# segments needed: ceil(buffer/seg) + 1 for the one being written + 1 margin
SEG_WRAP=$(( (BUFFER_SECS / SEG_SECS) + 2 ))
FRAMERATE="${FRAMERATE:-30}"
die() { printf 'Error: %s\n' "$*" >&2; exit 1; }
FFMPEG="/usr/bin/ffmpeg"
FFPROBE="/usr/bin/ffprobe"
check_deps() {
local missing=()
[[ -x "$FFMPEG" ]] || missing+=("ffmpeg")
[[ -x "$FFPROBE" ]] || missing+=("ffprobe")
for cmd in mpv xrandr; do
command -v "$cmd" &>/dev/null || missing+=("$cmd")
done
if (( ${#missing[@]} )); then
die "Missing dependencies: ${missing[*]}"
fi
}
is_running() {
[[ -f "$PID_FILE" ]] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null
}
cmd_start() {
check_deps
mkdir -p "$REPLAY_DIR" "$SAVE_DIR"
if is_running; then
echo "Already running (PID: $(cat "$PID_FILE"))"
return 0
fi
local display="${DISPLAY:-:0}"
# Detect primary monitor geometry via xrandr
local xrandr_line
xrandr_line=$(xrandr | grep ' connected primary ' | head -1)
[[ -n "$xrandr_line" ]] || die "Could not detect primary monitor (no 'primary' flag in xrandr)"
local geometry
geometry=$(printf '%s' "$xrandr_line" | grep -oP '\d+x\d+\+\d+\+\d+')
[[ -n "$geometry" ]] || die "Could not parse primary monitor geometry"
local resolution offset_x offset_y
resolution=$(printf '%s' "$geometry" | grep -oP '^\d+x\d+')
offset_x=$(printf '%s' "$geometry" | grep -oP '(?<=\+)\d+' | sed -n '1p')
offset_y=$(printf '%s' "$geometry" | grep -oP '(?<=\+)\d+' | sed -n '2p')
# Clean stale segments
rm -f "$REPLAY_DIR"/seg*.mkv
"$FFMPEG" -f x11grab -video_size "$resolution" -framerate "$FRAMERATE" \
-i "${display}+${offset_x},${offset_y}" \
-c:v libx264 -preset ultrafast -crf 23 \
-g "$FRAMERATE" \
-f segment -segment_time "$SEG_SECS" \
-segment_wrap "$SEG_WRAP" \
-reset_timestamps 1 \
"$REPLAY_DIR/seg%02d.mkv" \
</dev/null >"$REPLAY_DIR/ffmpeg.log" 2>&1 &
local pid=$!
echo "$pid" > "$PID_FILE"
disown "$pid"
# Give ffmpeg a moment to start (or fail)
sleep 1
if ! kill -0 "$pid" 2>/dev/null; then
rm -f "$PID_FILE"
echo "ffmpeg failed to start. Log:" >&2
cat "$REPLAY_DIR/ffmpeg.log" >&2
return 1
fi
echo "Replay daemon started (PID: $pid, buffer: ${BUFFER_SECS}s, segments: ${SEG_WRAP}x${SEG_SECS}s)"
}
cmd_save() {
is_running || die "Daemon not running. Start with: $0 start"
# Prevent concurrent saves
exec 9>"$LOCK_FILE"
flock -n 9 || die "Another save is already in progress"
local timestamp output concat_file
timestamp=$(date +%Y%m%d_%H%M%S)
output="$SAVE_DIR/replay_${timestamp}.mp4"
concat_file=$(mktemp /tmp/replay_concat.XXXXXX)
# Collect segments sorted by modification time (oldest first)
local -a segments=()
while IFS=$'\t' read -r _ path; do
segments+=("$path")
done < <(find "$REPLAY_DIR" -maxdepth 1 -name 'seg*.mkv' -printf '%T@\t%p\n' 2>/dev/null | sort -n)
(( ${#segments[@]} >= 1 )) || die "No recorded data yet"
# The last segment is being actively written by ffmpeg.
# Snapshot it so we capture everything up to this moment.
local active_seg="${segments[-1]}"
local snapshot="$REPLAY_DIR/_snapshot.mkv"
cp -- "$active_seg" "$snapshot"
# Use completed segments + snapshot of the active one
local -a use_segments=()
for seg in "${segments[@]:0:${#segments[@]}-1}"; do
use_segments+=("$seg")
done
use_segments+=("$snapshot")
# Build ffmpeg concat list
for seg in "${use_segments[@]}"; do
printf "file '%s'\n" "$seg"
done > "$concat_file"
# Concatenate with stream copy (near-instant)
"$FFMPEG" -f concat -safe 0 -i "$concat_file" \
-c copy -y "$output" 2>/dev/null
# Trim to last BUFFER_SECS if the recording is longer
local duration start
duration=$("$FFPROBE" -v error -show_entries format=duration -of csv=p=0 "$output")
start=$(awk "BEGIN {v = $duration - $BUFFER_SECS; print (v > 0 ? v : 0)}")
if awk "BEGIN {exit !($start > 1)}"; then
local trimmed="${output%.mp4}_tmp.mp4"
"$FFMPEG" -ss "$start" -i "$output" \
-c copy -avoid_negative_ts make_zero \
-y "$trimmed" 2>/dev/null
mv -- "$trimmed" "$output"
fi
trap - EXIT
rm -f "$concat_file" "$REPLAY_DIR/_snapshot.mkv"
echo "Saved: $output"
mpv --force-window=immediate "$output" &>/dev/null &
disown
}
cmd_stop() {
if is_running; then
local pid
pid=$(cat "$PID_FILE")
kill -INT "$pid" 2>/dev/null || true
for _ in {1..20}; do
kill -0 "$pid" 2>/dev/null || break
sleep 0.1
done
kill -9 "$pid" 2>/dev/null || true
rm -f "$PID_FILE" "$REPLAY_DIR"/seg*.mkv "$LOCK_FILE"
echo "Daemon stopped"
else
echo "Not running"
rm -f "$PID_FILE"
fi
}
cmd_status() {
if is_running; then
echo "Running (PID: $(cat "$PID_FILE"))"
local count size
count=$(find "$REPLAY_DIR" -name 'seg*.mkv' 2>/dev/null | wc -l)
size=$(du -sh "$REPLAY_DIR" 2>/dev/null | cut -f1)
echo "Segments: $count/${SEG_WRAP}, Disk: $size"
else
echo "Not running"
fi
}
usage() {
cat <<EOF
Usage: $(basename "$0") {start|save|stop|status}
Instant screen replay buffer — records the last ${BUFFER_SECS}s of your screen.
Press your configured hotkey to save the buffer and play it back immediately.
Commands:
start Start the background recording daemon
save Save the last ${BUFFER_SECS}s and open in mpv
stop Stop the daemon and clean up temp files
status Show whether the daemon is running
Environment variables (override defaults):
BUFFER_SECS Replay buffer length in seconds (default: 90)
FRAMERATE Recording frame rate (default: 30)
SAVE_DIR Directory for saved replays (default: ~/Videos/replays)
DISPLAY X11 display to capture (default: :0)
EOF
}
case "${1:-help}" in
start) cmd_start ;;
save) cmd_save ;;
stop) cmd_stop ;;
status) cmd_status ;;
*) usage ;;
esac