Closed stavn1 closed 6 years ago
For anyone else looking for the solution - you have to escape the string a couple times - this worked for me
text.replace("'", "\\\\\\'");
If anyone can't manage to make this work, try this
string.replace(/'/g, "\u2019");
from https://stackoverflow.com/a/26963014/6605412
That doesn't work at all, unless you are using double quotes in your syntax. My syntax doesn't accept double quotes. So it's really dumb, how this lousy program has no way to get around that. Really frustrated since this crap accepts escaping the single quote with two single quotes, but it doesn't work.
"C:\ffmpeg\bin\ffmpeg.exe" -y -i "D:\100\Sexo\S06\SATC - S06E02 - Models and Mortals.mkv" -ss 00:00:35 -to 00:01:01 -c:v libx265 -c:a copy -vf "[in]drawtext=fontfile=C\\:/Windows/fonts/arial.ttf:text='S06E02 - Models and Mortals':fontcolor=yellow:fontsize=45:x=(w-text_w)/2:y=(h-text_h)/2:enable='between(t,60*00+35,5+60*00+35)',drawtext=fontfile=C\\:/Windows/fonts/arial.ttf:text='Barkley''s modelizer':fontcolor=yellow:fontsize=35:x=(w-text_w)/2:y=40+(h-text_h)/2:enable='between(t,60*00+35,5+60*00+35)'[out]" "D:\100\Converter\001-SATC - S06E02 - Models and Mortals-00_00_35-00_01_01x.mp4"
Based on @David-Development's answer and the linked stackoverflow post, here's my function to escape all the potentially bad characters in the drawtext
filter:
function escape(text) {
return text
.replaceAll("\\", "\\\\\\\\\\\\\\\\")
.replaceAll("'", "\\\\\\'")
.replaceAll("%", "\\\\\\\\\\%")
.replaceAll(":", "\\\\\\\\\\\\:");
}
I don't see a strong reason why options.text
for filter: drawtext
shouldn't be automatically escaped. Should this be a pull request?
For
text = "sample-text%'"
this works
text = text.split("%").join("\\\\%")
but this doesn't work
text = text.split("'").join("\\\\\\'")
So I am using
text = text.replace(/[\\\%\'\:]+/g, " ")
How do you write a single quote with drawText and videoFilter?
but the single quote is omitted, the written text became "Im here".