Created
January 31, 2018 00:53
-
-
Save z/5ca5dd5583f58c77ccf9f6f6d32fc7ce to your computer and use it in GitHub Desktop.
a gource wrapper for Xonotic's repository structure written in bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# name: gource.sh | |
# version: 0.2.0 | |
# A convenience wrapper for visualizing Xonotic's git commits via gource. | |
# Copyright 2018 Tyler "-z-" Mulligan ([email protected]), MIT License | |
# Requires gource: https://github.com/acaudwell/Gource and GNU's sed | |
# [!] This script expects to live in xonotic's misc/tools directory | |
set -e | |
# Internal Constants | |
SCRIPT_NAME=$(basename $0) | |
VERSION=$(awk 'NR == 3 {print $3; exit}' $0) | |
REPOS="data/xonotic-data.pk3dir data/xonotic-music.pk3dir data/xonotic-nexcompat.pk3dir netradiant d0_blind_id data/xonotic-maps.pk3dir gmqcc" | |
TMP="/tmp/xon" | |
ALL_LOG="${TMP}/gource.log" | |
KEEP_LOGS=0 | |
# Commands | |
gource_generate_log() { | |
mkdir -p "${TMP}" | |
local all_commits="" | |
for repo in ${REPOS}; do | |
local log_file=$(echo "log-${repo}.log" |sed "s#/#-#g") | |
all_commits="${all_commits} ${TMP}/${log_file}" | |
echo "generating log for: ${repo}" | |
gource --output-custom-log ${TMP}/${log_file} "$@" ${XONOTIC_DIR}/${repo} | |
sed -i -r "s#(.+)\|#\1|/"${repo}"#" ${TMP}/${log_file} | |
done | |
cat ${all_commits} | sort -n > ${ALL_LOG} | |
} | |
gource_run() { | |
gource_generate_log "$@" | |
gource "$@" | |
} | |
gource_runonly() { | |
gource "$@" | |
} | |
gource_record() { | |
local input="${1:--}" | |
local output="${2:-out.webm}" | |
local format="${3:-webm}" | |
local framerate="${4:-60}" | |
case ${format} in | |
'x264') | |
# x264 | |
ffmpeg -y -r ${framerate} -f image2pipe -vcodec ppm -i ${input} -vcodec libx264 -preset ultrafast -pix_fmt yuv420p -crf 1 -threads 0 -bf 0 ${output} | |
;; | |
'webm') | |
# webm | |
ffmpeg -y -r ${framerate} -f image2pipe -vcodec ppm -i ${input} -vcodec libvpx-vp9 -lossless 1 -cpu-used 5 -threads 8 ${output} | |
;; | |
*) | |
echo "format not supported, try 'x264' or 'webm'." | |
exit 1 | |
;; | |
esac | |
} | |
# Helpers | |
_check_xonotic_dir() { | |
local xon_dir=$1 | |
if [[ ! -d ${xon_dir} ]]; then | |
echo "[ ERROR ] Unable to locate Xonotic"; exit 1 | |
fi | |
} | |
_get_xonotic_dir() { | |
relative_dir=$(dirname $0)/../.. | |
_check_xonotic_dir ${relative_dir} | |
export XONOTIC_DIR="$(cd ${relative_dir}; pwd)" | |
} | |
_cleanup() { | |
if [[ ${KEEP_LOGS} == 0 ]]; then | |
rm -r ${TMP}/log-* 2> /dev/null | |
fi | |
} | |
# Meta | |
_version() { | |
echo ${VERSION} | |
} | |
_help_short() { | |
echo "./${SCRIPT_NAME} | |
log [name] wraps gource to generate a '/tmp/xon/gource.log' log | |
for Xonotic's git structure | |
record <input> <output> [format] [framerate] convenince command that wraps ffmpeg | |
run <gource OPTIONS> implies log generation, and passes-through gource exec options | |
runonly <gource OPTIONS> explicit run, passes-through gource exec options | |
--version prints the version string | |
--help prints additional help | |
" | |
} | |
_help_long() { | |
echo "./${SCRIPT_NAME} | |
A convenience wrapper for visualizing Xonotic's git commits via gource. | |
Requires gource (https://github.com/acaudwell/Gource), ffmpeg optional. | |
Read the EXAMPLES to better understand the usage of this script. | |
FLAGS | |
--version prints the version string | |
--help prints additional help | |
COMMANDS | |
log [name] wraps gource to generate a '/tmp/xon/gource.log' log | |
for Xonotic's git structure | |
record <input> <output> [format] [framerate] convenince command that wraps ffmpeg | |
run <gource OPTIONS> implies log generation, and passes-through gource exec options | |
runonly <gource OPTIONS> explicit run, passes-through gource exec options | |
EXAMPLES | |
Log, generating a '/tmp/xon/gource.log' for Xonotic's repo structure: | |
./${SCRIPT_NAME} log | |
Run, implies generating a '/tmp/xon/gource.log': | |
./${SCRIPT_NAME} run /tmp/xon/gource.log | |
Run, again without generating a new log, but using the onld on '/tmp/xon/gource.log': | |
./${SCRIPT_NAME} runonly /tmp/xon/gource.log | |
Run, use a different camera method in gource: | |
./${SCRIPT_NAME} run --camera-mode track /tmp/xon/gource.log | |
Record a video by piping output from the run command to the record command: | |
./${SCRIPT_NAME} run -1280x720 /tmp/xon/gource.log -o - | ./${SCRIPT_NAME} record - out.webm | |
Record a video in the alternative format: | |
./${SCRIPT_NAME} run -1280x720 /tmp/xon/gource.log -o - | ./${SCRIPT_NAME} record - out.mp4 x264 | |
Record a video in two separate steps (warning: this creates a large RAW ppm file): | |
./${SCRIPT_NAME} run --seconds-per-day 5 --start-date \"2015-01-01\" -1280x720 /tmp/xon/gource.log -o /tmp/xon/out.ppm | |
./${SCRIPT_NAME} record /tmp/xon/out.ppm out.webm | |
Use a logo overlay: | |
# convert the xonotic SVG logo to a png with inkscape first | |
inkscape -z -e mediasource/gfx/logo/xonotic_icon.png -w 128 -h 128 ../../../mediasource/gfx/logo/xonotic_icon.svg | |
./${SCRIPT_NAME} run --seconds-per-day 5 -1280x720 --logo ../../../mediasource/gfx/logo/xonotic_icon.png | |
Roughly what I used for Xonotic's gource video: | |
./${SCRIPT_NAME} run --seconds-per-day 0.001 --start-date \"2010-01-01\" -1280x720 \\ | |
--logo ../../../mediasource/gfx/logo/xonotic_icon.png --title \"www.xonotic.org\" \\ | |
--camera-mode overview --file-idle-time 0 --max-files 99999999999 --max-file-lag 0.0001 \\ | |
--hide filenames,progress,mouse --highlight-users --bloom-multiplier 1.3 --bloom-intensity 0.3 \\ | |
--time-scale 2 /tmp/xon/gource.log -o - | ${SCRIPT_NAME} record - out.webm | |
VERSION: ${VERSION} | |
" | |
} | |
# Main | |
if [[ "$#" -eq "0" ]]; then _help_short; exit 0; fi | |
# Allow for overriding the path assumption | |
# XONOTIC_DIR=/some/other/path; ./xonotic/xonotic/misc/tools/gource.sh --version | |
if [[ -z ${XONOTIC_DIR} ]]; then | |
_get_xonotic_dir | |
else | |
_check_xonotic_dir ${XONOTIC_DIR} | |
fi | |
trap _cleanup SIGINT SIGTERM EXIT | |
case $1 in | |
# meta | |
'--help'|'help') shift; _help_long $@;; | |
'--version'|'version') shift; _version;; | |
# commands | |
'log') shift; gource_generate_log $@;; | |
'record') shift; gource_record $@;; | |
'run') shift; gource_run $@;; | |
'runonly') shift; gource_runonly $@;; | |
# default | |
*) shift; _help_short; exit 0;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment