gpt4 book ai didi

c - 如何在 Shell FFmpeg 中转义单引号?

转载 作者:行者123 更新时间:2023-12-04 23:10:12 25 4
gpt4 key购买 nike

我的环境

  • zsh
  • 苹果 clang 版本 13.0.0

  • 我的问题总结
    我想使用 FFmpeg 在视频上绘制一些文本。
    我的命令行是由带有 system() 函数的 C 程序发送的。
    当我的字符串中有单引号时,文本不会显示,这是有道理的。
    我试过的
  • 保持原样 → 不绘制文本
  • 用\' 正常转义它 → 不绘制文本
  • 使用\\' 双重转义 → 不绘制文本
  • 三重逃避它,等等...
  • 使用 \0027\xE2\x80\x99符号 → 文本绘制为“0027”或“xE2x80x99”

  • 我的代码
    generateVideo() 函数
    void generateVideo(char sourceVideoPath[], char text[], int destinationFileName) {
    char line[1000];
    sprintf(line, "ffmpeg -i %s -vf \"drawtext=fontfile=/path/to/font/:text='%s':fontcolor=white:fontsize=28:borderw=2.8:x=(w-text_w)/2:y=(h-text_h)/2\" -codec:a copy ../%d.mp4", sourceVideoPath, text, destinationFileName);
    system(line);
    }
    我不知道问题是来自 FFmpeg 还是 Shell,但我暂时无法用引号绘制文本是一种痛苦。
    提前谢谢你们!

    最佳答案

    从您的问题中很难说出问题所在,但我相信在文本中的引号之前编码\之类的修复应该可以解决它。如果您从在 shell 中工作的命令行开始,然后尝试从您的 C 代码中使用“system”发出该命令,则可能会更容易提供帮助。这是一个 main.c,它演示了我认为应该起作用的方法:

    #import <stdio.h>
    #import <stdlib.h>

    int main(int argc, char **argv) {
    char *sourceVideoPath = "video";
    char *text = "text \\'quoted\\' text";
    int destinationFileName = 10;
    char line[1000];
    sprintf(line, "echo ffmpeg -i %s -vf \"drawtext=fontfile=/path/to/font/:text='%s':fontcolor=white:fontsize=28:borderw=2.8:x=(w-text_w)/2:y=(h-text_h)/2\" -codec:a copy ../%d.mp4", sourceVideoPath, text, destinationFileName);
    system(line);
    }

    关于c - 如何在 Shell FFmpeg 中转义单引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71347013/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com