xaizek / xscripts (License: Apache-2.0) (since 2020-06-28)
Small collection of some scripts I find useful.
Commit 6f9c8afe64b914d9d9de72fda65740cda2ceb860

Add gifrec script
Author: xaizek
Author date (UTC): 2020-06-28 20:52
Committer name: xaizek
Committer date (UTC): 2020-06-28 21:03
Parent(s): 9768a7ba98c43fc97746a181eea76915ca6ef395
Signing key: 99DC5E4DB05F6BE2
Tree: 4029261469aaee6bfbfc937844b83f4178d527c3
File Lines added Lines deleted
README.md 1 0
gifrec 80 0
File README.md changed (mode: 100644) (index 8265b6e..f266be6)
... ... Look at the top comments inside scripts.
19 19
20 20 | Script | Description | Script | Description
21 21 | ------------------------ | ----------- | ------------------------ | -----------
22 | gifrec | Handy script to record interaction as a GIF
22 23 | gt-clean-merged-branches | Interactive deletion of old branches in a Git repo | gt-clean-merged-branches | Interactive deletion of old branches in a Git repo
23 24
24 25 ### License ### License
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"
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/xscripts

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/xscripts

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master