#!/bin/bash
# name: encode-demos.sh
-# version: 0.6.1
-# author: Tyler "-z-" Mulligan
+# version: 0.6.2
+# author: Tyler "-z-" Mulligan <z@xnz.me>
# license: GPL & MIT
-# date: 24-02-2017
+# date: 26-02-2017
# description: headless encoding of demo files to HD video concurrently with Xfvb and parallel
#
# The encoding is done with a full Xonotic client inside Xfvb.
#
# Customize
-XONDIR=${HOME}/xonotic/xonotic # path to ./all
USERDIR=${HOME}/.xonotic-clean # path to Xonotic userdir for client that does encoding
+GAMEDIR=${USERDIR}/data # path to Xonotic userdir for client that does encoding
XONOTIC_BIN="./all" # binary used to launch Xonotic
-JOB_TIMEOUT="1h" # if demo doesn't quit itself or hangs
+JOB_TIMEOUT="4h" # if demo doesn't quit itself or hangs
JOBS=4 # number of concurrent jobs
DEFAULT_DEMO_LIST_FILE="demos.txt" # for batch
DISPLAY=:1.0 # display for Xvfb
# State
export KILLER_KEYWORD_WATCHING=true
+# Xonotic 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)
+}
+
+_kill_xonotic() {
+ pkill -f "\-simsound \-sessionid xonotic_${SCRIPT_NAME}_"
+}
+
# Data Helpers
###############
local demo_file=$1
local index=$2
name_format=$(basename "${demo_file}" .dem)
- command="${XONDIR}/${XONOTIC_BIN} run sdl -simsound -sessionid xonotic_${SCRIPT_NAME}_${index} -userdir \"${USERDIR}\" \
+ command="${XONOTIC_DIR}/${XONOTIC_BIN} run sdl -simsound -sessionid xonotic_${SCRIPT_NAME}_${index} -userdir \"${USERDIR}\" \
+log_file \"xonotic_${SCRIPT_NAME}_${index}_${name_format}.log\" \
+cl_capturevideo_nameformat \"${name_format}_\" \
+cl_capturevideo_number 0 \
local type=$1; shift
local videos="$@"
for video_file in ${videos[@]}; do
- local command=$(_get_compression_command ${USERDIR}/data/${video_file} ${type})
+ local command=$(_get_compression_command ${GAMEDIR}/${video_file} ${type})
_queue_add_job ${queue_file} "${command}" ${video_file}
done
}
_cleanup() {
rm -f ${QUEUE_FILE_DEMOS}
rm -f ${LOCK_FILE}
- rm -f ${USERDIR}/data/*.log
+ rm -f ${GAMEDIR}/*.log
export KILLER_KEYWORD_WATCHING=false
sleep 1
_kill_xonotic
rm -f ${QUEUE_FILE_COMPRESSING}
}
-_kill_xonotic() {
- pkill -f "\-simsound \-sessionid xonotic_${SCRIPT_NAME}_"
-}
-
# Application Helpers
######################
fi
# compress
- local command=$(_get_compression_command ${USERDIR}/data/${video_file} ${type})
+ local command=$(_get_compression_command ${GAMEDIR}/${video_file} ${type})
echo ${command}
echo "[ INFO ] Compressing '${video_file}'"
_queue_add_compression_jobs ${QUEUE_FILE_COMPRESSING} ${type} ${video_file[@]}
local keyword="$@"
for worker in $(_get_active_demo_workers); do
local log_file="${worker}.log"
- local keyword_count=$(grep -c "${keyword}" "${USERDIR}/data/${log_file}")
+ local keyword_count=$(grep -c "${keyword}" "${GAMEDIR}/${log_file}")
if [[ ${keyword_count} > 0 ]]; then
if [[ ${type} == "worker" ]]; then
echo "${worker}"
else
echo "[ worker ] ${worker}"
- grep "${keyword}" "${USERDIR}/data/${log_file}"
+ grep "${keyword}" "${GAMEDIR}/${log_file}"
fi
fi
done
# follow a completed job log
./encode-demos.sh log -f
+
+ # Override the path to Xonotic (assumed from relative location of this script)
+ XONOTIC_DIR=\$HOME/some/other/dir; ./misc/tools/encode-demos.sh --version
"
}
+# Init
+######
+
+# Allow for overriding the path assumption
+# XONOTIC_DIR=$HOME/some/other/dir; ./misc/tools/encode-demos.sh --version
+if [[ -z ${XONOTIC_DIR} ]]; then
+ _get_xonotic_dir
+else
+ _check_xonotic_dir ${XONOTIC_DIR}
+fi
+
case $1 in
# flags
'--version') _version;;