File gifrec added (mode: 100755) (index 0000000..b49e6b8) |
|
1 |
|
#!/bin/bash |
|
2 |
|
# Copyright 2020 xaizek <xaizek@posteo.net> |
|
3 |
|
# |
|
4 |
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
|
# you may not use this file except in compliance with the License. |
|
6 |
|
# You may obtain a copy of the License at |
|
7 |
|
# |
|
8 |
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
|
# |
|
10 |
|
# Unless required by applicable law or agreed to in writing, software |
|
11 |
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
|
# See the License for the specific language governing permissions and |
|
14 |
|
# limitations under the License. |
|
15 |
|
|
|
16 |
|
# Made after https://unix.stackexchange.com/a/113696/56269 |
|
17 |
|
# Uses (depends on): |
|
18 |
|
# - ffcast (https://github.com/lolilolicon/ffcast) |
|
19 |
|
# - convert from ImageMagick package (http://imagemagick.org/) |
|
20 |
|
# - ffmpeg |
|
21 |
|
# - tempfile |
|
22 |
|
|
|
23 |
|
# To use invoke as `gifrec recording` and use `recording.gif` created in current |
|
24 |
|
# directory afterwards. |
|
25 |
|
|
|
26 |
|
# TODO: enable optional use of https://github.com/lolilolicon/xrectsel to |
|
27 |
|
# select area with a mouse |
|
28 |
|
# TODO: maybe check whether ffcast is available before doing anything else |
|
29 |
|
# TODO: maybe get rid of convert: |
|
30 |
|
# https://www.linux.org.ru/forum/general/15373028?cid=15373044 |
|
31 |
|
|
|
32 |
|
if [ $# -ne 1 ]; then |
|
33 |
|
echo "Usage: $(basename "$0") name" |
|
34 |
|
exit 1 |
|
35 |
|
fi |
|
36 |
|
|
|
37 |
|
name="$1" |
|
38 |
|
|
|
39 |
|
frame_rate=20 |
|
40 |
|
delay=5 |
|
41 |
|
out_gif="$name.gif" |
|
42 |
|
|
|
43 |
|
tmp_avi="$(tempfile --prefix=gif- --suffix=.avi)" |
|
44 |
|
if [ $? -ne 0 ]; then |
|
45 |
|
echo "Failed to generate name for temporary file" |
|
46 |
|
exit 2 |
|
47 |
|
fi |
|
48 |
|
|
|
49 |
|
function remove_tmp_file() |
|
50 |
|
{ |
|
51 |
|
rm "$tmp_avi" |
|
52 |
|
} |
|
53 |
|
trap remove_tmp_file EXIT |
|
54 |
|
|
|
55 |
|
# TODO: looks like could use -w option of ffcast instead of this code, but |
|
56 |
|
# adding countdown might be harder |
|
57 |
|
echo 'Pick a window by clicking on it with a mouse...' |
|
58 |
|
window_id="$(xwininfo | sed -n '/Window id/s/.*\(0x[a-f0-9]\+\).*/\1/p')" |
|
59 |
|
|
|
60 |
|
for i in {3..1}; do |
|
61 |
|
echo "$i" |
|
62 |
|
sleep 1 |
|
63 |
|
done |
|
64 |
|
|
|
65 |
|
ffcast -# "$window_id" \ |
|
66 |
|
% ffmpeg \ |
|
67 |
|
-f x11grab \ |
|
68 |
|
-show_region 1 \ |
|
69 |
|
-framerate "$frame_rate" \ |
|
70 |
|
-video_size %s \ |
|
71 |
|
-i %D+%c \ |
|
72 |
|
-codec:v huffyuv \ |
|
73 |
|
-vf crop='iw-mod(iw\,2):ih-mod(ih\,2)' \ |
|
74 |
|
-f avi \ |
|
75 |
|
-y \ |
|
76 |
|
"$tmp_avi" \ |
|
77 |
|
&& convert -layers Optimize \ |
|
78 |
|
-set delay "$delay" \ |
|
79 |
|
"$tmp_avi" \ |
|
80 |
|
"$out_gif" |