I have a quick shell script that is taking a list of input and output names line by line and providing them to ffmpeg for conversion. Some of the output paths have spaces in them, and I receive one of two errors, no matter how I escape or double quote the path with spaces.
Input File
file1.avi "output path"/file1.mp4
file1.avi "output\ path"/file1.mp4
file1.avi "output path/file1.mp4"
file1.avi output\ path/file1.mp4
convert.sh
while read -r file1 file2; do ffmpeg -i "$file1" -c copy -bsf:a aac_adtstoasc $file2; done <list
One error that I receive is:
"output path"/file1.mp4: No such file or directory
The other error that I receive is:
Unable to find a suitable output format for '"output'
The variations in the input file lines are there to show the things that I have tried in order to escape the space. I have also tried the same with adding double quotes around file2 in the shell script.
output\ path
should enable you to read the output file name correctly. In the ffmpeg command, you also have to use quotes around the shell variable to protect the space. You put quotes around$file1
, why not$file2
?read
command is documented at gnu.org/software/bash/manual/html_node/Bash-Builtins.html: "The backslash character ‘\’ may be used to remove any special meaning for the next character read and for line continuation".