ffmpeg single quote in drawtext

前端 未结 6 990
粉色の甜心
粉色の甜心 2020-12-09 19:32

I haven\'t been able to get ffmpeg\'s drawtext video filter to draw apostrophes/single quotes when they are in drawtext\'s \"text=\" parameter, even when I escape them. Doub

相关标签:
6条回答
  • 2020-12-09 20:04

    // This works for me

    public function replaceSpecialFfmpegChars($text)
        {
            return str_replace(
                ":",
                "\\\\\\\\\\\:",
                str_replace(
                    "%",
                    "\\\\\\\\\\\%",
                    str_replace(
                        "'",
                        "'\\\\\\\\\\\\''",
                        str_replace(
                            "\"",
                            "\\\\\\\\\\\"",
                            str_replace(
                                "\\",
                                "\\\\\\\\\\\\\\\\",
                                $text
                            )
                        )
                    )
                )
            );
        }
    
    0 讨论(0)
  • 2020-12-09 20:16

    Just put your text into a file e.g. myText.txt and use textfile option:

    ->myText.txt This is my text with special characters :,(,),'

    Then instead of using :

    ffmpeg -i test.mpg -vf drawtext="This is my text with special characters :,(,),'"

    use the following command:

    ffmpeg -i test.mpg -vf textfile=textFile.txt

    0 讨论(0)
  • 2020-12-09 20:21

    I was able to insert Unicode \u2019 into argument string and it worked for single right quote.

    0 讨论(0)
  • 2020-12-09 20:22

    Special character escapes are like violence: if they're not solving your problem, you're not using enough.

    ffmpeg -i test.mpg -vf drawtext=text="It\\\\\'s so easy"
    

    Produces a textual overlay that includes an apostrophe. The text is being parsed a couple times, so you not only have to escape the quote, you also have to escape the slash escaping the quote. Twice.

    Your alternative of using a textfile might be a better method in this situation.

    0 讨论(0)
  • 2020-12-09 20:23

    In case someone needs this for python, this escape function is working for me (based on https://ffmpeg.org/ffmpeg-utils.html#Quoting-and-escaping + multi-escaping advice above):

    return "'" + text.replace(":", "\\:").replace("'", "'\\\\\\''") + "'"

    0 讨论(0)
  • 2020-12-09 20:23

    This is probably something to do with magic quotes. Through a bunch of testing I just did using Windows Command Line and MinGW on Windows, I ran into the same problem every time. Since ffmpeg drawtext uses Freetype (I would guess this is where magic quotes are enabled) I doubt there's much to be done to disable magic quotes. I'm not sure there's a way to remove the added slashes in the command line either, as everything I've seen involves PHP scripts. I could be wrong, since I'm no PHP guru, but I'm not aware of how to integrate them into an ffmpeg command.

    0 讨论(0)
提交回复
热议问题