blob: 45ef43822fda43c131e74fd289c788d1838477fe (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#!/bin/sh
set -e
[ -n "$DEBUG" ] && set -x
audio="$(pactl info | grep "Default Sink" | cut -d':' -f2 | xargs -L1).monitor"
output=$(swq current output)
showkeys=
ask=
crop=
hwacc=
output_file="${HOME}/Videos/wf_$(date +%FT%T).mkv"
optstring="a:o:kAcHnh"
while getopts "${optstring}" opt; do
case "${opt}" in
a) audio="${OPTARG}" ;;
o) output="${OPTARG}" ;;
k) showkeys=1 ;;
A) ask=1 ;;
c) crop=1 ;;
H) hwacc=1 ;;
h | ?)
printf 'usage: %s [-%s] [FILE]\n' "$(basename "$0")" "$(printf '%s' "${optstring}" | tr -d ':')"
printf '\n'
printf ' Launches wf-recorder(1) with optimized settings.\n'
printf ' When FILE is omitted, use %s.\n' "${output_file}"
printf '\n'
printf ' -a audio to record (default: %s)\n' "${audio}"
printf ' -o output to record (default: %s)\n' "${output}"
printf ' -k show keypresses; using wshowkeys(1)\n'
printf ' -A select audio/output interactively\n'
printf ' -c select an area of the screen to be recorded; using slurp(1)\n'
printf ' -H enable hardware-accelerated recording (usually reduces quality)\n'
printf '\n'
exit 2
;;
esac
done
shift $((OPTIND - 1))
[ -n "${1}" ] && output_file=$1
# select audio sink to record
if [ ! "${audio}" = "none" ] && [ -n "${ask}" ]; then
audio=$(MENU_PROMPT="wfez: choose audio:" soundswitch -j -O)
audio="${audio}.monitor"
fi
[ ! "${audio}" = "none" ] && audio_arg="-a ${audio}"
# select output to record
[ -n "${ask}" ] && output=$(slurp -o)
if [ -n "${showkeys}" ]; then
printf "Starting wshowkeys on %s\n" "${output}"
pritnf "WARNING: currently the -o flag to force display to a specific output is not implemented\n" >&2
# -o ${output}
sway exec "wshowkeys -a bottom -a left -F 'Iosevka Aile 25' -t 1" >/dev/null
trap '{ pkill wshowkeys; }' EXIT
fi
if [ -n "${crop}" ]; then
selection=
case $(printf "manual\nworkspace\ncontainer\n" | MENU_PROMPT="wfez: crop mode" menu -l5) in
manual)
geom=$(slurp -f "%o:%x,%y %wx%h")
;;
container)
selection=$(swq list con | jq -r '.[]|select(.name? and .visible?==true)|[.id, .name, (.type=="floating_con")]|join("\t")' | awk '{c="swq locate output-for-con "$1" | jq -r \"first | .name\""; c|getline o; close(c); printf "%3s\t%10s\t%8s\t%s\n", $1, $2, ($3 == "true" ? "floating" : "normal"), o}' | MENU_PROMPT="wfez: select container" menu -l5)
con_id=$(printf '%s' "$selection" | awk '{print $1}')
con_pos=$(swq has id "$con_id" | swq geometry)
con_out=$(swq | jq -r --argjson a "{\"id\":$con_id}" '..|select(.type?=="workspace" and (([.floating_nodes[], .nodes[]])|..|select(.id?==$a.id)))|.output')
geom="${con_out}:${con_pos}"
;;
*)
printf "not implemented\n" >&2
exit 1
;;
esac
output="$(printf '%s' "${geom}" | cut -d: -f1)"
geometry_arg="-g $(printf '%s' "${geom}" | cut -d: -f2-)"
fi
if [ -n "${hwacc}" ]; then
hwacc_arg='-c h264_vaapi -d /dev/dri/renderD128'
fi
makoctl set-mode off
set -x
wf-recorder -o "${output}" "${audio_arg}" "${geometry_arg}" "${hwacc_arg}" -f "${output_file}"
set +x
if [ ! "${audio}" = "none" ]; then
# correct mono audio in stereo channel
mv "${output_file}" /tmp/wfrec_tmp.mkv
trap '{ rm /tmp/wfrec_tmp.mkv; }' EXIT
ffmpeg -hide_banner -i /tmp/wfrec_tmp.mkv -vcodec copy -af "pan=mono|c0=c0" "${output_file}"
fi
makoctl set-mode ''
notify-send wfez "$output_file"
|