Sample Header Ad - 728x90

Why are quotation marks and backslashes not working as expected in variables?

0 votes
0 answers
51 views
I'm trying to pass a command through to ffmpeg, but I'm struggling to get it to work with spaces in the name. I've tried this: filters="-vf subtitles='$filename.$format':force_style=Fontsize=24" And this: fn=$(echo $filename | sed 's: :\\ :g') filters="-vf subtitles=$fn.$format:force_style=Fontsize=24" Then ultimately executed like this: ffmpeg_command="ffmpeg -y -threads 8 -movflags +faststart $filters -pix_fmt $pfmt -c:a $acodec -c:v $codec $qualitycmd $quality $speed" echo $ffmpeg_command \"$fileout\" -i \"$filename.$format\" #Execute: $($ffmpeg_command "$fileout" -i "$filename.$format") In both of the above cases, if I do echo $filters it shows the expected result (the filename encased in ' or the spaces escaped with \) However upon execution for some reason it will fail (it will interpret the spaces in the filename as a separator for arguments and throw an error that some part of the name is not a valid argument in spite of the quotation marks or backslashes). I've confirmed the syntax should work though, if I execute it outside of a script ffmpeg -i '/path/to/Some File.mkv' -vf subtitles='/path/to/Some File.mkv':force_style=Fontsize=24 out.mp4 That works just fine, so why doesn't it in the script? And how can I work around that?
Asked by Cestarian (2438 rep)
May 17, 2025, 09:20 AM
Last activity: May 17, 2025, 11:02 AM