nluug-video-intro-generator/generate.sh
2024-11-06 19:43:59 +01:00

110 lines
3.5 KiB
Bash
Executable file

#!/bin/bash
SOURCEDIR=`pwd`
PROJECT=$1
BASETEMPLATE="nluug-title-template.svg"
SOURCEFILE="event.svg"
VIDEODIR=${SOURCEDIR}/output
PROJDIR=/tmp/nluug-intro-${PROJECT}
if [ -z "${PROJECT}" ]; then
echo "Usage: $0 <project>"
exit 1;
fi
if [ -z "$EVENTNAME" ]; then
echo "Specify EVENTNAME env-var"
exit 2;
fi
if [ -z "$SPEAKERNAME" ]; then
echo "Specify SPEAKERNAME env-var"
exit 3;
fi
if [ -z "$TITLE1" -o -z "$TITLE2" -o -z "$TITLE3" ]; then
echo "Specify TITLE1/TITLE2/TITLE3 env-vars"
exit 4;
fi
# EVENTNAME="NLUUG Najaar 5 November 2024"
# MAXLENGTH="SPEAKERSPEAKERSPEAKERSPEAKERSPEAKER"
#SPEAKERNAME="Example Speaker Name"
# MAX="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
#TITLE1="Keynote: Some example title"
#TITLE2="With 3 lines, or use some whitespace"
#TITLE3="If less are needed"
CONV="convert -background black -fill black -alpha off"
FRAMENUM=0
# Make project directory
mkdir -p ${PROJDIR}; cd ${PROJDIR}
# Customize tempalte to this event from base template
cat ${SOURCEDIR}/$BASETEMPLATE | sed -e "s/EVENTNAMEEVENTNAMEEVENTNAMEEVENTNAME/$EVENTNAME/" > ${SOURCEFILE}
# Create initial image without title/speaker info
cat ${SOURCEFILE} | sed -e 's/SPEAKERSPEAKERSPEAKERSPEAKERSPEAKER//' -e 's/TITLE[123]//' > frameclear.svg
# Fade this image in from 100% transparant to 'normal'
echo "Generate fade-in-from-black sequence"
for i in `seq 100 -3 0`
do
echo "Generate frame ${FRAMENUM}"
${CONV} -colorize ${i}% frameclear.svg frame-${FRAMENUM}.webp
((FRAMENUM++))
done
echo "Add speakername sequence"
SLEN=${#SPEAKERNAME} # Length of name
# Copy a new frame, and fill in the speaker name 1 character at a time
for i in `seq 0 ${SLEN}`
do
echo "Generate frame ${FRAMENUM}"
SN="${SPEAKERNAME::$i}"
cat ${SOURCEFILE} | sed -e "s/TITLE[123]//" -e "s/SPEAKERSPEAKERSPEAKERSPEAKERSPEAKER/$SN/" > ${PROJDIR}/frame-${FRAMENUM}.svg
${CONV} frame-${FRAMENUM}.svg frame-${FRAMENUM}.webp
((FRAMENUM++))
done
echo "Add title sequence"
# With speakername, not add the title, 1 char (per line) at a time
for i in `seq 0 40`
do
echo "Generate frame ${FRAMENUM}"
T1="${TITLE1::$i}" # Substring, first i characters
T2="${TITLE2::$i}"
T3="${TITLE3::$i}"
cat ${SOURCEFILE} | sed -e "s/TITLE1/$T1/" -e "s/TITLE2/$T2/" -e "s/TITLE3/$T3/" -e "s/SPEAKERSPEAKERSPEAKERSPEAKERSPEAKER/$SN/" > ${PROJDIR}/frame-${FRAMENUM}.svg
${CONV} frame-${FRAMENUM}.svg frame-${FRAMENUM}.webp
((FRAMENUM++))
done
# Generate final frame, with full speakername + title
echo "Generate completed title"
cat ${SOURCEFILE} | sed -e "s/TITLE1/$TITLE1/" -e "s/TITLE2/$TITLE2/" -e "s/TITLE3/$TITLE3/" -e "s/SPEAKERSPEAKERSPEAKERSPEAKERSPEAKER/$SPEAKERNAME/" > ${PROJDIR}/frame-${FRAMENUM}.svg
${CONV} frame-${FRAMENUM}.svg frame-${FRAMENUM}.webp
LASTFRAME=$FRAMENUM
((FRAMENUM++))
# Now copy the rendered output of the last frame a few more times so we can read it before the video ends
for i in `seq 0 1 100`
do
echo "Duplicating frame ${FRAMENUM}"
cp frame-${LASTFRAME}.webp frame-${FRAMENUM}.webp
((FRAMENUM++))
done
# Fade this image out over 100 frames back to the normal view
echo "Generate fade-out-sequence"
for i in `seq 0 3 100`
do
echo "Generate frame ${FRAMENUM}"
${CONV} -colorize ${i}% frame-${LASTFRAME}.svg frame-${FRAMENUM}.webp
((FRAMENUM++))
done
echo "Rendering to video"
ffmpeg -framerate 30 -i frame-%d.webp -c:v libx264 -r 30 ${VIDEODIR}/${PROJECT}-x264.mkv
ffmpeg -framerate 30 -i frame-%d.webp -c:v vp9 -r 30 ${VIDEODIR}/${PROJECT}-vp9.webm
rm *.svg frame-*.webp