Skip to content

Commit 33fdeb5

Browse files
committed
Update screen-capture
Update screen-capture Signed-off-by: Bensuperpc <bensuperpc@gmail.com>
1 parent 31afaec commit 33fdeb5

File tree

2 files changed

+90
-43
lines changed

2 files changed

+90
-43
lines changed

video/screen-capture-h265.sh

Lines changed: 0 additions & 34 deletions
This file was deleted.

video/screen-capture.sh

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,96 @@ set -euo pipefail
2020
#// //
2121
#//////////////////////////////////////////////////////////////
2222

23+
readonly VERSION="1.0.0"
2324

24-
type ffmpeg >/dev/null 2>&1 || { echo "ffmpeg could not be found" >&2; exit 1; }
25+
DS_version() {
26+
echo "screen-capture $VERSION"
27+
}
2528

26-
if (( $# == 1 )); then
27-
ffmpeg -f x11grab -video_size 1920x1080 -framerate 60 -i :0 \
28-
-vcodec libx264 -preset ultrafast -qp 0 -pix_fmt yuv444p \
29-
"$1"
30-
else
31-
echo "Usage: ${0##*/} <output file>"
32-
exit 1
33-
fi
29+
# Values can by override
30+
ENCODING_LIB=${ENCODING_LIB:-libx264}
31+
RESOLUTION=${RESOLUTION:-1920x1080}
32+
FRAMERATE=${FRAMERATE:-60}
33+
SCREEN=${SCREEN:-:0}
34+
QUALITY=${QUALITY:-0}
35+
PRESET=${PRESET:-ultrafast}
36+
OUTPUT=${OUTPUT:-screen_capture.mkv}
37+
PIXEL=${PIXEL:-yuv444p}
38+
39+
TESTS=${TESTS:-none}
40+
COPY=${COPY:-true}
41+
42+
DS_check() {
43+
type ffmpeg >/dev/null 2>&1 || { echo "ffmpeg could not be found" >&2; exit 1; }
44+
}
45+
46+
DS_help() {
47+
echo "Usage: ${0##*/} --output <output file>"
48+
echo "Others option:
49+
--lib libx264 or libx265
50+
--resolution 1920x1080
51+
--framerate 60
52+
--quality 0
53+
--screen :0
54+
--preset ultrafast, fast, slow...
55+
--pixel yuv444p
56+
-h or --help
57+
-v or --version"
58+
exit 0
59+
}
3460

61+
62+
DS_main() {
63+
if [[ -z $* ]]; then
64+
DS_version
65+
DS_help
66+
exit 0
67+
fi
68+
69+
while [[ $# -gt 0 ]] && ([[ "$1" == "--"* ]] || [[ "$1" == "-"* ]]) ;
70+
do
71+
opt="$1";
72+
echo "opt: $opt"
73+
shift;
74+
case "$opt" in
75+
"--lib" )
76+
ENCODING_LIB="$1"; shift;;
77+
"--test="* ) # alternate format: --first=date
78+
TESTS="${opt#*=}";;
79+
"--screen" )
80+
SCREEN="$1"; shift;;
81+
"--framerate" )
82+
FRAMERATE="$1"; shift;;
83+
"--quality" )
84+
QUALITY="$1"; shift;;
85+
"--preset" )
86+
PRESET="$1"; shift;;
87+
"--pixel" )
88+
PIXEL="$1"; shift;;
89+
"--resolution" )
90+
RESOLUTION="$1"; shift;;
91+
"--output" )
92+
OUTPUT="$1"; shift;;
93+
"--help" | "-h" )
94+
DS_help;;
95+
"--version" | "-v" )
96+
DS_version;;
97+
"--copy" )
98+
COPY=true;;
99+
*) echo >&2 "Invalid option: $*"; exit 1;;
100+
esac
101+
done
102+
DS_check
103+
DS_exec
104+
}
105+
106+
DS_exec() {
107+
ffmpeg -f x11grab -video_size "$RESOLUTION" -framerate "$FRAMERATE" -i "$SCREEN" \
108+
-vcodec "$ENCODING_LIB" -preset "$PRESET" -qp "$QUALITY" -pix_fmt "$PIXEL" \
109+
"$OUTPUT"
110+
111+
}
112+
113+
if [[ "$0" == "${BASH_SOURCE[0]}" ]]; then
114+
DS_main "$@"
115+
fi

0 commit comments

Comments
 (0)