[FFmpeg-user] help with quotes in bash script

DopeLabs dopelabs at dubstep.fm
Wed May 21 11:13:14 CEST 2014


heres a bash script i wrote to batch process audio files into waveform.

ffmpeg
-randomly selects from a pre-defined list of ffmpeg commands
-applies a text logo in the top left corner
-alters color balance using random generated filter values
-creates report log

youtube-upload
-convert filename to title and url in description
-log the returned yt url

took me a few tries to get the quoting to the point of successful execution.

either way quoting can get crazy and confusing sometimes, maybe you can use my script as reference and get it sorted =]

also, this: https://ffmpeg.org/ffmpeg-utils.html#Quoting-and-escaping


#######

./script.sh ARCHIVE_-_2014-05-21_-_Artist_-_Title.mp3 # single file
./script.sh *2014-05*.mp3 # globbing too

#######

#!/bin/bash

for f in "$@"; do


RANGE1=9
rs=$RANDOM
let "rs %= $RANGE1"

RANGE2=9
gs=$RANDOM
let "gs %= $RANGE2"

RANGE3=9
bs=$RANDOM
let "bs %= $RANGE3"

RANGE4=9
rm=$RANDOM
let "rm %= $RANGE4"

RANGE5=9
gm=$RANDOM
let "gm %= $RANGE5"

RANGE6=9
bm=$RANDOM
let "bm %= $RANGE6"

RANGE7=9
rh=$RANDOM
let "rh %= $RANGE7"

RANGE8=9
gh=$RANDOM
let "gh %= $RANGE8"

RANGE9=9
bh=$RANDOM
let "bh %= $RANGE9"

shadows=$(echo rs=."$rs":gs=."$gs":bs=."$bs");
midtones=$(echo rm=."$rm":gm=."$gm":bm=."$bm");
highlights=$(echo rh=."$rh":gh=."$gh":bh=."$bh");

case $((RANDOM%3+1)) in
    1 ) ffmpeg -i "$f" -r 30 -filter_complex showwaves=s=1280x720:mode=line:r=30,drawtext=fontfile=font.ttf:fontsize=28:fontcolor=white:textfile=text.txt:y=10:x=10,colorbalance="$shadows":"$midtones":"$highlights" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -c:a libfdk_aac -b:a 256k -report -f mp4 "$f".mp4 && youtube-upload -p pass -m email at address.com -t "PRE: $(echo "$f" | sed 's/_/ /g'| sed 's/\.[^.]*$//')" -c Music -d "$(echo "Audio: http://direct.download.com/$f\niTunes: http://itunes.apple.com/link")" --keywords="key,words,go,here" "$f".mp4 >> "$f".yt-url.log;;
    2 ) ffmpeg -i "$f" -r 30 -filter_complex showwaves=s=1280x720:mode=line:r=30,drawtext=fontfile=font.ttf:fontsize=28:fontcolor=white:textfile=text.txt:y=10:x=10,colorbalance="$shadows":"$midtones":"$highlights" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -c:a libfdk_aac -b:a 256k -report -f mp4 "$f".mp4 && youtube-upload -p pass -m email at address.com -t "PRE: $(echo "$f" | sed 's/_/ /g'| sed 's/\.[^.]*$//')" -c Music -d "$(echo "Audio: http://direct.download.com/$f\niTunes: http://itunes.apple.com/link")" --keywords="key,words,go,here" "$f".mp4 >> "$f".yt-url.log;;
    3 ) ffmpeg -i "$f" -r 30 -filter_complex showwaves=s=1280x720:mode=line:r=30,drawtext=fontfile=font.ttf:fontsize=28:fontcolor=white:textfile=text.txt:y=10:x=10,colorbalance="$shadows":"$midtones":"$highlights" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -c:a libfdk_aac -b:a 256k -report -f mp4 "$f".mp4 && youtube-upload -p pass -m email at address.com -t "PRE: $(echo "$f" | sed 's/_/ /g'| sed 's/\.[^.]*$//')" -c Music -d "$(echo "Audio: http://direct.download.com/$f\niTunes: http://itunes.apple.com/link")" --keywords="key,words,go,here" "$f".mp4 >> "$f".yt-url.log;;
    4 ) ffmpeg -i "$f" -r 30 -filter_complex showwaves=s=1280x720:mode=line:r=30,drawtext=fontfile=font.ttf:fontsize=28:fontcolor=white:textfile=text.txt:y=10:x=10,colorbalance="$shadows":"$midtones":"$highlights" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -c:a libfdk_aac -b:a 256k -report -f mp4 "$f".mp4 && youtube-upload -p pass -m email at address.com -t "PRE: $(echo "$f" | sed 's/_/ /g'| sed 's/\.[^.]*$//')" -c Music -d "$(echo "Audio: http://direct.download.com/$f\niTunes: http://itunes.apple.com/link")" --keywords="key,words,go,here" "$f".mp4 >> "$f".yt-url.log;;
esac
done

##########

to see some examples of  output...
http://www.youtube.com/dubstepfm

##########

all avail via apt/ports/macports

youtube-upload
python-gdata
python-progressbar


More information about the ffmpeg-user mailing list