commit 42f6a4ef5eb824b4ca6688fa11718f6bbbde6bf1 Author: Kar Date: Thu Oct 27 19:36:51 2022 +0530 init diff --git a/DASH-ffmpeg-VP9-encoder.sh b/DASH-ffmpeg-VP9-encoder.sh new file mode 100644 index 0000000..4d70bdc --- /dev/null +++ b/DASH-ffmpeg-VP9-encoder.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +# Prepare the videos to be used over http with the MPEG-DASH protocol +# The vp9 codec is used for the videos because h265 is not supported by chrome and h264 is too big +# This script generates webm files + +## DOCS +# https://developers.google.com/media/vp9/settings/vod/ +# https://developer.mozilla.org/en-US/docs/Web/HTML/DASH_Adaptive_Streaming_for_HTML_5_Video +# http://wiki.webmproject.org/adaptive-streaming/instructions-to-playback-adaptive-webm-using-dash + +# ffprobe: https://trac.ffmpeg.org/wiki/FFprobeTips + +## PRE-REQUIRED-INSTALLATION : ffmpeg and libwebm +# OSX: brew install ffmpeg --with-libvpx --with-libvorbis +# Debian: + +set -eo pipefail + +INPUT=$1 +OUTPUT_DIR=$2 +DASH_PARAMS="-keyint_min 150 -g 150 -an -f webm -dash 1" +LOG_LEVEL="-hide_banner -loglevel info" + +# Checks +if [[ -z $(which ffmpeg) ]]; then echo "Error: ffmpeg is not installed"; exit 1; fi +if [[ $# -ne 2 ]]; then echo "Usage: mp4_to_dash input_file.mp4 output_directory"; exit 1; fi +if [[ ! -f ${INPUT} ]]; then echo "Error: input_file not found"; exit 1; fi +if [[ ! -d ${OUTPUT_DIR} ]]; then echo "Error: output_directory not found"; exit 1; fi + +# create new directory using the name of the video +f=$(basename $INPUT) +f=${f%.*} # name without extension, and without base +rm -rf ${OUTPUT_DIR}/${f} +mkdir -p ${OUTPUT_DIR}/${f} +prefix=${OUTPUT_DIR}/${f}/${f} + +encode_audio() { + ffmpeg $LOG_LEVEL -i "$INPUT" -c:a libvorbis -b:a 128k -vn -f webm -dash 1 -y "${prefix}-audio-128k.webm" +} + +getHeight() { + ffprobe -v error -select_streams v:0 -show_entries stream=height -of default=noprint_wrappers=1:nokey=1 "$INPUT" +} + +encode(){ + size_params=$1 + output=$2 + echo "ffmpeg $LOG_LEVEL -i $INPUT -c:v libvpx-vp9 $size_params $DASH_PARAMS -pass 1 -speed 4 -y $output" + ffmpeg $LOG_LEVEL -i $INPUT -c:v libvpx-vp9 $size_params $DASH_PARAMS -pass 1 -speed 4 -y $output && \ + ffmpeg $LOG_LEVEL -i $INPUT -c:v libvpx-vp9 $size_params $DASH_PARAMS -pass 2 -speed 4 -y $output +} + +encode_240p() { + size="320x240" + size_params="-s ${size} -b:v 150k -minrate 75k -maxrate 218k -tile-columns 0 -threads 2 -quality good -crf 37" + encode "$size_params" "${prefix}-${size}.webm" +} + +encode_360p() { + size="640x360" + size_params="-s ${size} -b:v 276k -minrate 138k -maxrate 400k -tile-columns 1 -threads 4 -quality good -crf 36" + encode "$size_params" "${prefix}-${size}.webm" +} + +encode_720p() { + size="1280x720" + size_params_30f="-s ${size} -b:v 1024k -minrate 512k -maxrate 1485k -tile-columns 2 -threads 8 -quality good -crf 32" + encode "size_params_30f" "${prefix}-${size}-30f.webm" + + size_params_60f="-s ${size} -b:v 1800k -minrate 900k -maxrate 2610k -tile-columns 2 -threads 8 -quality good -crf 32" + encode "$size_params_60f" "${prefix}-${size}-60f.webm" +} + +video_original_height=$(getHeight) +encode_audio +encode_360p +if [[ "$video_original_height" -ge "720" ]]; then encode_720p; fi diff --git a/check-mime b/check-mime new file mode 100644 index 0000000..ea36d20 --- /dev/null +++ b/check-mime @@ -0,0 +1,8 @@ +#!/bin/bash + +# mime=$(file -b --mime-type dog.jpeg) +mime=$(mimetype https://bscdn.sgp1.digitaloceanspaces.com/CurriculumApp/IK3/Week8/Core/Day4/AudioVisual/1RBE12.wmv) +echo $mime +if [[ $mime = video/@(x-ms-wmv|wmv) ]]; then + echo "need conversion" +fi diff --git a/do-conversion-wmv b/do-conversion-wmv new file mode 100644 index 0000000..0308b0f --- /dev/null +++ b/do-conversion-wmv @@ -0,0 +1,41 @@ +#!/bin/bash + +#./filter-wmv tree.txt > tree-wmv.txt +rclone lsf -R bscdn:bscdn/CurriculumApp-og > tree.list +touch tree-wmv.list +touch wmv-converted.list +touch wmv-converted-uploaded.list +touch wmv-removed.list + +#filename=$1 +filename=tree.list +#echo Start +while read p; do +if [ "${p: -4}" == ".wmv" ]; then + fileog="https://bscdn.sgp1.digitaloceanspaces.com/CurriculumApp-og/${p}" + filetarget="https://bscdn.sgp1.digitaloceanspaces.com/CurriculumApp/${p}" + fName="$(basename -- $fileog)" + fDir="$(dirname -- $p)" + #echo F- "$fileog" -F + fWebm="${fName}.webm" + MediaType=$(mediainfo --Inform="General;%Format%" $filetarget) + if [ "$MediaType" == "WebM" ]; then + #echo $'\u2714\u274c' + echo -e $'\u2714' "$fileog" + else + echo -e $'\u274c' "$fileog\n Downloading" + wget "$fileog" + echo "converting $fName to $fWebm" + ffmpeg -loglevel error -i "$fName" -c:v libvpx-vp9 -c:a libopus "$fWebm" 2> /dev/null + echo "$fName" >> wmv-converted.list + mv "$fWebm" "$fName" + rclone delete bscdn:bscdn/CurriculumApp/"$p" + echo "$fName" >> wmv-removed.list + rclone copy "$fName" bscdn:bscdn/CurriculumApp/"$fDir" + echo "$fName" >> wmv-converted-uploaded.list + rm "$fName" + #sleep 100 + #read -p "Press enter to continue" + fi +fi +done < "$filename" diff --git a/filter-file-ext-from-text-file b/filter-file-ext-from-text-file new file mode 100644 index 0000000..9e9c3ec --- /dev/null +++ b/filter-file-ext-from-text-file @@ -0,0 +1,12 @@ +#!/bin/bash + +#./filter-wmv tree.txt > tree-wmv.txt +rclone ls bscdn:bscdn/CurriculumApp > tree.txt +#filename=$1 +filename=tree.txt +echo Start +while read p; do +if [ "${p: -4}" == ".wmv" ]; then + echo "$p" +fi +done < "$filename"