#!/bin/bash # Copyright Ken Fallon - Released into the public domain. http://creativecommons.org/publicdomain/ intro_clip_end="00:01:30" quality_clip_duration="90" outro_clip="90" #DEBUG="echo " cd /mnt/DUMP/hpr-for-archive.org/todo/ for FILEX in * do if [[ "$(file "$FILEX" | grep -i audio | wc -l )" -ne 1 && "$(mediainfo "$FILEX" | grep -i audio | wc -l )" -ne 1 ]] then echo "$FILEX is not an audio file" else echo "Processing $FILEX" fname=${FILEX%.*} ext=${FILEX/*./} # We get the druation from mediainfo in miliseconds and remove the last three digits to convert it to seconds # Then calculate the times of the end clip working back from the end of the file # We then pick a random segment between the intro and outro. # Finally we convert to hour minute second format and the date command is the easiest way to do that duration=$( mediainfo --full "${fname}.${ext}" | grep Duration | egrep -v ".*:.*:|ms|s|mn" | head -1 | awk -F ': ' '{print $2}' ) duration="${duration:0:${#duration}-3}" outro_clip_start="$(($duration-$outro_clip))" quality_clip_end="$(($outro_clip_start-$quality_clip_duration))" quality_clip_start=$(shuf -i ${intro_clip_end}-${quality_clip_end} -n 1) quality_clip_end="$(($quality_clip_start+$quality_clip_duration))" duration=$(\date -d@${duration} -u +%H:%M:%S) quality_clip_start=$(\date -d@${quality_clip_start} -u +%H:%M:%S) quality_clip_end=$(\date -d@${quality_clip_end} -u +%H:%M:%S) outro_clip_start=$(\date -d@${outro_clip_start} -u +%H:%M:%S) echo -e "\tExtracting spectrogram" ${DEBUG} sox "${fname}.${ext}" -n spectrogram -Y 130 -l -r -t "${fname}.${ext}" -o "${fname}_spectrogram.png" echo -e "\tExtracting intro clip from 0 to ${intro_clip_end}" ${DEBUG} ffmpeg -y -ss 0 -t ${intro_clip_end} -i "${fname}.${ext}" "${fname}_intro_clip".wav 2>/dev/null echo -e "\tExtracting quality clip from ${quality_clip_start} to ${quality_clip_end}" ${DEBUG} ffmpeg -y -ss ${quality_clip_start} -t ${quality_clip_end} -i "${fname}.${ext}" "${fname}_quality_clip".wav 2>/dev/null echo -e "\tExtracting outro clip from ${outro_clip_start} ${duration}" ${DEBUG} ffmpeg -y -ss ${outro_clip_start} -t ${duration} -i "${fname}.${ext}" "${fname}_outro_clip".wav 2>/dev/null echo -e "\tCreating low fidelity version" ${DEBUG} ffmpeg -y -i "${fname}.${ext}" temp.wav 2>/dev/null ${DEBUG} sox "temp.wav" -c 1 -r 16000 -t wav - 2>/dev/null | speexenc - "${fname}_low_fidelity.spx" 2>/dev/null ${DEBUG} rm temp.wav fi done