I'm working on a bash script to convert my music library to ogg* but executing the right command is somehow eluding me. This is the line that should accomplish it:
ffmpeg -i "${file}" -f flac pipe:1 | oggenc - -o "${NEWOGGFILE}"
In fact, if I copy the output of this line, it encodes as expected:
echo "ffmpeg -i \"${file}\" -f flac pipe:1 | oggenc - -o \"${NEWOGGFILE}\""
E.g.:
ffmpeg -i "./Music/Oldies/Sam Cooke/23 Shake.m4a" -f flac pipe:1 | oggenc - -o "/mnt/Primary/Audio_OGG_Cache/./Music/Oldies/Sam Cooke/23 Shake.ogg"
But, when I run the script, ffmpeg gives me error messages, including: Unable to find a suitable output format for 'pipe:1' pipe:1: Invalid argument Parse error, at least 3 arguments were expected, only 1 given in string 'al Warmups/Voice Lessons To Go - V1 Vocalize & Breath/01-05- 123454321.mp3'
So, how is the first line not executing the command if the second line echos it correctly? The complete script is as follows:
#!/bin/bash
pushd "${1}"
find ./ | while read file
do
BASENAME=`basename "${file}"`
NEWOGGFILE=${2}`dirname "${file}"`/${BASENAME%.*}.ogg
NEWFILE=${2}`dirname "${file}"`/${BASENAME}
# Ignore directories, and don't re-copy existing files.
if [ ! -d "${file}" ] && [ ! -f "${NEWFILE}" ] && [ ! -f "${NEWOGGFILE}" ]; then
mkdir -p "`dirname "${NEWFILE}"`"
# m4a, mp3, and flac get converted
if [ "${file##*.}" = "flac" ]; then
oggenc "${file}" -o "${NEWOGGFILE}"
elif [ "${file##*.}" = "m4a" ] || [ "${file##*.}" = "mp3" ]; then
ffmpeg -i "${file}" -f flac pipe:1 | oggenc - -o "${NEWOGGFILE}"
# any other remaining types of files (typically album art) are copied directly.
else
cp "${file}" "${NEWFILE}"
fi
else
echo "${NEWFILE}" already exists.
fi
done
popd
*In a separate, cached directory; don't have a heart attack, audiophiles!
ffmpeg -loglevel debug -i ...
; see if you get anything useful afterSplitting the commandline
...bash
script debugging withset -x
./mnt/Primary/Audio/Vocal\ Warmups/Voice\ Lessons\ To\ Go\ -\ V1\ Vocalize\ \&\ Breath/01-05-\ 123454321.mp3
Since there's no single quote, my money is on the ampersand being the culprit. I'm going to try a tweak using single-quotes to encapsulate it.