xaizek / xscripts (License: Apache-2.0) (since 2020-06-28)
Small collection of some scripts I find useful.
<root> / gifrec (b49e6b810b7ffc8f08933414acdad8da087b7362) (2,254B) (mode 100755) [raw]
#!/bin/bash
# Copyright 2020 xaizek <xaizek@posteo.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Made after https://unix.stackexchange.com/a/113696/56269
# Uses (depends on):
# - ffcast (https://github.com/lolilolicon/ffcast)
# - convert from ImageMagick package (http://imagemagick.org/)
# - ffmpeg
# - tempfile

# To use invoke as `gifrec recording` and use `recording.gif` created in current
# directory afterwards.

# TODO: enable optional use of https://github.com/lolilolicon/xrectsel to
#       select area with a mouse
# TODO: maybe check whether ffcast is available before doing anything else
# TODO: maybe get rid of convert:
#       https://www.linux.org.ru/forum/general/15373028?cid=15373044

if [ $# -ne 1 ]; then
    echo "Usage: $(basename "$0") name"
    exit 1
fi

name="$1"

frame_rate=20
delay=5
out_gif="$name.gif"

tmp_avi="$(tempfile --prefix=gif- --suffix=.avi)"
if [ $? -ne 0 ]; then
    echo "Failed to generate name for temporary file"
    exit 2
fi

function remove_tmp_file()
{
    rm "$tmp_avi"
}
trap remove_tmp_file EXIT

# TODO: looks like could use -w option of ffcast instead of this code, but
#       adding countdown might be harder
echo 'Pick a window by clicking on it with a mouse...'
window_id="$(xwininfo | sed -n '/Window id/s/.*\(0x[a-f0-9]\+\).*/\1/p')"

for i in {3..1}; do
    echo "$i"
    sleep 1
done

ffcast -# "$window_id" \
       % ffmpeg \
       -f x11grab \
       -show_region 1 \
       -framerate "$frame_rate" \
       -video_size %s \
       -i %D+%c \
       -codec:v huffyuv \
       -vf crop='iw-mod(iw\,2):ih-mod(ih\,2)' \
       -f avi \
       -y \
       "$tmp_avi" \
&& convert -layers Optimize \
           -set delay "$delay" \
           "$tmp_avi" \
           "$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