-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathshadowreplay
executable file
·83 lines (65 loc) · 1.82 KB
/
shadowreplay
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
#!/bin/sh
set -eu
RESOLUTION="$(xdpyinfo | grep dimensions | awk 'NR==1{print $2}')"
SOFTWARE_ENCODE=false
FPS="60"
ENCODER_STANDARD=h264
REPLAY_BUFFER="5"
if ls "$HOME"/Videos;then
VIDEO_FOLDER="$HOME"/Videos
elif ls /usr/bin/xdg-user-dir;then
VIDEO_FOLDER="$(xdg-user-dir VIDEOS)"
else
mkdir "$HOME"/Videos
VIDEO_FOLDER="$HOME"/Videos
fi
BUFFER_SEC=$((REPLAY_BUFFER * 60))
BUFFER_SEGMENT_LENGTH="30"
BUFFER_SEGMENTS=$((BUFFER_SEC / BUFFER_SEGMENT_LENGTH))
# Source user-specific config
. $HOME/.config/shadowreplay
if $NONFREE_AMD_ENCODER;then
ENCODER_API=amf
elif lspci | grep 'VGA.*ATI' >/dev/null;then
ENCODER_API=vaapi
elif lspci | grep 'VGA.*NVIDIA' >/dev/null;then
ENCODER_API=nvenc
elif lspci | grep 'VGA.*Intel' >/dev/null;then
ENCODER_API=qsv
fi
ENCODER="$ENCODER_STANDARD"_"$ENCODER_API"
if $SOFTWARE_ENCODE;then
ENCODER_API=
ENCODER=libx264
fi
BASEDIR=$(dirname "$0")
DATE=$(date +%Y-%d-%m-%H:%M:%S)
FILE="$VIDEO_FOLDER/replay-$DATE.mp4"
case $ENCODER_API in
"vaapi")
ENCODER_OPTS="-c:v $ENCODER -vf format='nv12|vaapi,hwupload' -vaapi_device /dev/dri/renderD128"
;;
"amf")
export VK_ICD_FILENAMES=/opt/amdgpu-pro/etc/vulkan/icd.d/amd_icd64.json:/opt/amdgpu-pro/etc/vulkan/icd.d/amd_icd32.json
ENCODER_OPTS="-c:v $ENCODER"
;;
"nvenc")
ENCODER_OPTS="-c:v $ENCODER -preset:v llhq -profile:v high -pix_fmt nv12 -b:v 15M -acodec aac"
;;
"qsv")
ENCODER_OPTS="-c:v $ENCODER"
;;
*)
ENCODER_OPTS="-c:v $ENCODER -preset medium"
;;
esac
ffmpeg_command ||
ffmpeg \
-i /tmp/ShadowRePlay.m3u8 \
-c copy "$FILE" -loglevel quiet &&
find /tmp -name 'ShadowRePlay*' -exec rm {} \; &&
notify-send -i video \
"ShadowRePlay" \
"Replay saved to $FILE"
cd "$BASEDIR" &&
./shadowreplay