Added Script File

master
Dubtempo 2021-08-10 03:00:25 -07:00
parent db301a6672
commit a7bdd454aa
2 changed files with 142 additions and 26 deletions

54
.gitignore vendored
View File

@ -1,3 +1,5 @@
output/
# ---> Linux
*~
@ -14,32 +16,32 @@
.nfs*
# ---> macOS
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# ---> Windows
# Windows thumbnail cache files

114
html5vid.sh Executable file
View File

@ -0,0 +1,114 @@
#!/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