Skip to content

Instantly share code, notes, and snippets.

@bockel
Created August 22, 2012 15:00
Show Gist options
  • Select an option

  • Save bockel/3426432 to your computer and use it in GitHub Desktop.

Select an option

Save bockel/3426432 to your computer and use it in GitHub Desktop.
Generates an ogv video container from PDF slides and Audacity audio stream
#!/bin/sh
# Convert a PDF slide presentation and audio track into an OGV video
# Copyright (C) 2012 William Heinbockel <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if [ $# -ne 3 ]
then echo "Usage: $0 slides.pdf audacity.aup soundtrack.wav"
exit 1
fi
if [ ! -r "$1" ]
then echo "Error: cannot find PDF slides: $1"
exit 1
fi
if [ ! -r "$2" ]
then echo "Error: cannot find audacity file: $2"
exit 1
fi
if [ ! -r "$3" ]
then echo "Error: cannot find soundtrack: $3"
exit 1
fi
DEFAULT_TIME=2 #seconds
name=${1%.*}
tdir=$(mktemp -d -p .)
cd "$tdir"
# 1. Convert pdf into slide*.png
convert "../$1" slide%03d.png
# 2. Get track lengths
slidetimes=($(cat <<- EOF | xsltproc --novalid --nonet - "../$2"
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:a="http://audacity.sourceforge.net/xml/">
<xsl:output method="text"/>
<xsl:variable name="rate" select="/a:project/@rate"/>
<xsl:template match="/a:project/a:wavetrack">
<xsl:value-of select="round(sum(a:waveclip/a:sequence/@numsamples) div \$rate)"/>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
EOF
))
# 3. Generate dvd-slideshow slide time config
cnt=0
echo "background:0::black" > "$name.txt"
echo "fadein:1" >> "$name.txt"
for img in $(ls *.png)
do
if [ "$cnt" -lt "${#slidetimes[*]}" ]
then echo "$img:${slidetimes[$cnt]}" >> "$name.txt"
else echo "$img:$DEFAULT_TIME" >> "$name.txt"
fi
let cnt+=1
done
echo "fadeout:1" >> "$name.txt"
echo "background:2" >> "$name.txt"
# 4. Use dvd-slideshow to generate a VOB file
dvd-slideshow -n "$name" -f "$name.txt" -a "../$3"
# 5. Convert the VOB into an Ogg OGV container
# Option 1. Use vorbis audio - supported by Firefox, Chrome, and possibly other platforms
ffmpeg -y -loglevel quiet -i "$name.vob" -filter:a earwax -ac 1 -c:a libvorbis -r 10 "../$name.ogv"
# Option 2. Use speex audio codec - smaller size, better quality, not widely supported
# ffmpeg -y -loglevel quiet -i "$name.vob" -filter:a earwax -ac 2 -c:a libspeex -r 10 "../$name.ogv"
cd ..
rm -rf "$tdir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment