-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscreenshot
executable file
·71 lines (63 loc) · 1.91 KB
/
screenshot
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
#!/bin/sh -e
# shellcheck disable=SC2046
firstArg="$1"
shift
case "$firstArg" in
-g)
IFS=:+ read -r WIDTH HEIGHT X Y
;;
-a)
X=$1
Y=$2
WIDTH=$3
HEIGHT=$4
shift 4
;;
-e)
;;
-s)
exec $0 -a $(xrectsel "%x %y %w %h") "$@"
;;
-i)
exec env $(xdotool getwindowgeometry --shell "$(xdotool selectwindow)") "$0" -e "$@"
;;
-f)
exec env $(xdotool getwindowgeometry --shell "$(xdotool getwindowfocus)") "$0" -e "$@"
;;
-w)
window=$1
shift
exec env $(xdotool getwindowgeometry --shell "$window") "$0" -e "$@"
esac
if [ "$WIDTH" -eq 0 ] || [ "$HEIGHT" -eq 0 ] ; then
exit 1
fi
echo "$WIDTH:$HEIGHT:$X:$Y" >&2
defaultExt=png
take_video=0
if [ "$(basename "$0")" = screencast ] || [ "$2" = screencast ]; then
defaultExt=mp4
take_video=1
elif [ "$(basename "$0")" = screencastaudio ] || [ "$2" = screencastaudio ]; then
defaultExt=mp4
take_video=2
elif [ "$(basename "$0")" = screenrecord ] || [ "$2" = screenrecord ]; then
defaultExt=mp4
take_video=2
ALSA_INPUT_DEVICE=${ALSA_INPUT_DEVICE:-hw:Loopback,0,0}
fi
[ -n "$1" ] && fileName=$1 || fileName="$(date -u +%F_%H:%M:%S)_$$.$defaultExt"
if [ "$fileName" = "?" ]; then
cd "${PICTURES_DIR:-~}"
fileName=$(dmenu -p 'Enter file name' </dev/null)
fi
[ -d "$fileName" ] && fileName="$fileName/$(date -u +%s)_$$.$defaultExt"
if [ "$take_video" -eq 0 ]; then
ffmpeg -video_size "$WIDTH"x"$HEIGHT" -f x11grab -i ":0.0+$X,$Y" -vframes 1 "$fileName"
elif [ "$take_video" -eq 1 ]; then
ffmpeg -video_size "$WIDTH"x"$HEIGHT" -framerate 25 -f x11grab -i ":0.0+$X,$Y" "$fileName"
elif [ "$take_video" -eq 2 ]; then
echo "$ALSA_INPUT_DEVICE"
ffmpeg -video_size "$WIDTH"x"$HEIGHT" -framerate 25 -f x11grab -i ":0.0+$X,$Y" -f alsa -ac 2 -i "${ALSA_INPUT_DEVICE:-hw:0}" "$fileName"
fi
echo "$fileName"