114 lines
3.3 KiB
Bash
Executable File
114 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# ===========================================================
|
|
# Script for Generating HTML5 Video Files and Markup
|
|
# ===========================================================
|
|
#
|
|
: '
|
|
|
|
Title :
|
|
|
|
html5vid.sh
|
|
|
|
|
|
Usage :
|
|
|
|
Pass FFMPEG-supported video files to this script as standard input.
|
|
This scrip will generate html5 video files and markup in a sub directory.
|
|
|
|
|
|
Requires:
|
|
|
|
FFMPEG : libx264, libvorbis, libfaac
|
|
|
|
';
|
|
|
|
|
|
##################### VARS ######################
|
|
|
|
|
|
outputDir="output" # you may want to update gitignore if you change this
|
|
|
|
|
|
##################### MAIN ######################
|
|
|
|
# get script dir
|
|
|
|
cd $(dirname "${BASH_SOURCE[0]}")
|
|
directory=$(pwd)
|
|
|
|
# loop input
|
|
|
|
for f in "$@"
|
|
do
|
|
|
|
if [[ $f && -f "$f" ]]; then
|
|
|
|
# grab duration data from file and determine hours, minutes, seconds
|
|
|
|
duration=$(ffmpeg -i "$f" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,)
|
|
minutes=${duration%:*}
|
|
hours=${minutes%:*}
|
|
minutes=${minutes##*:}
|
|
seconds=${duration##*:}
|
|
seconds=${seconds%.*}
|
|
|
|
# get file and path info
|
|
|
|
filename=$(basename "$f")
|
|
filename=${filename%.*}
|
|
|
|
hours=$((hours*3600))
|
|
minutes=$((minutes*60))
|
|
|
|
total=$(expr $hours + $minutes + $seconds)
|
|
|
|
# make dirs if needed
|
|
|
|
if [ ! -d "$directory/$outputDir/$filename" ]; then
|
|
mkdir -p "$directory/$outputDir/$filename"
|
|
fi
|
|
|
|
# move to source file's directory and begin process
|
|
|
|
cd "$directory/$outputDir/$filename"
|
|
|
|
# Thumbnail
|
|
|
|
echo "Generating thumbnail"
|
|
ffmpeg -i "$f" -deinterlace -an -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg -y "$directory/$outputDir/$filename/$filename.jpg" 2>&1
|
|
|
|
# OGV
|
|
|
|
echo "Converting $filename to ogv"
|
|
ffmpeg -i "$f" -c:a libvorbis -ac 2 -b:a 96k -ar 44100 -c:v libvpx -b:v 4500k -y "$directory/$outputDir/$filename/$filename.ogv"
|
|
echo "Finished ogv"
|
|
|
|
# WEBM
|
|
|
|
echo "Converting $filename to webm"
|
|
ffmpeg -i "$f" -c:a libvorbis -ac 2 -b:a 96k -ar 44100 -c:v libtheora -b:v 4500k -y "$directory/$outputDir/$filename/$filename.webm"
|
|
echo "Finished webm"
|
|
|
|
# X264
|
|
|
|
echo "Converting $filename to h264"
|
|
ffmpeg -i "$f" -b:a 96k -c:v libx264 -preset slow -level 21 -refs 2 -b:v 4500k -bt 4500k -threads 0 -y "$directory/$outputDir/$filename/$filename.mp4"
|
|
echo "Finished h264"
|
|
|
|
# HTML
|
|
|
|
echo "Writing HTML..."
|
|
|
|
echo "<video controls poster=\"$filename.jpg\" preload>" > "$directory/$outputDir/$filename/$filename.html"
|
|
echo " <source type=\"video/ogg\" src=\"$filename.ogv\">" >> "$directory/$outputDir/$filename/$filename.html"
|
|
echo " <source type=\"video/webm\" src=\"$filename.webm\">" >> "$directory/$outputDir/$filename/$filename.html"
|
|
echo " <source type=\"video/mp4\" src=\"$filename.mp4\">" >> "$directory/$outputDir/$filename/$filename.html"
|
|
echo " Sorry, your browser does not support HTML5 video" >> "$directory/$outputDir/$filename/$filename.html"
|
|
echo "</video>" > "$directory/$outputDir/$filename/$filename.html"
|
|
|
|
echo "All Done!"
|
|
else
|
|
echo "Error with input. Please check what you are passing to this script."
|
|
fi
|
|
|
|
done |