我的环境
我的问题总结
我想使用 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/