fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.89k stars 877 forks source link

single quote in drawtext #805

Closed stavn1 closed 6 years ago

stavn1 commented 6 years ago

How do you write a single quote with drawText and videoFilter?

command.videoFilters({
                filter: 'drawtext',
                options: {
                text: 'I\'m here'

            });

but the single quote is omitted, the written text became "Im here".

David-Development commented 4 years ago

For anyone else looking for the solution - you have to escape the string a couple times - this worked for me

text.replace("'", "\\\\\\'");

Reference: https://stackoverflow.com/a/10729560/13370504

jvzanatta15 commented 3 years ago

If anyone can't manage to make this work, try this string.replace(/'/g, "\u2019"); from https://stackoverflow.com/a/26963014/6605412

jrsousa2 commented 2 years ago

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"

christiangenco commented 1 year ago

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?

pkhuji commented 1 year ago

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, " ")