From a7bdd454aaa29f201f8c482e81de8d8546d2c424 Mon Sep 17 00:00:00 2001 From: Dubtempo Date: Tue, 10 Aug 2021 03:00:25 -0700 Subject: [PATCH] Added Script File --- .gitignore | 54 +++++++++++++------------ html5vid.sh | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 26 deletions(-) create mode 100755 html5vid.sh diff --git a/.gitignore b/.gitignore index 432775d..5201dff 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/html5vid.sh b/html5vid.sh new file mode 100755 index 0000000..52ae7ed --- /dev/null +++ b/html5vid.sh @@ -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 "" > "$directory/$outputDir/$filename/$filename.html" + + echo "All Done!" + else + echo "Error with input. Please check what you are passing to this script." + fi + +done \ No newline at end of file