我正在使用C#执行一些FFMPEG命令。
我有一个这样的FFMPEG命令-
ffmpeg -i C:\\Users\\Alan\\source\\repos\\TEST\\Tem_Videos/24d4a5be-5615-7930-5a38-c4e191aa8c48.mp4
-i C:\\Users\\Alan\\source\\repos\\TEST\\Video_Templates/Redacted.png -filter_complex "[0:v][1:v]overlay=0:0:enable='between(t,2,3)',drawtext=fontfile='C\\:\\Users\\Alan\\source\\repos\\TEST\\FFMPEG\\FreeSerif.ttf':enable='between(t,2,3)':fontcolor=white:fontsize=50:text='This section has been redacted':x=(w-text_w)/2:y=(h-text_h)/2[v];[0]volume=0:enable='between(t,2,3)'[a]" -map "[v]" -map "[a]" -preset ultrafast C:\\Users\\Alan\\source\\repos\\TEST\\Tem_Videos/6b70aeea-26fb-45ad-b7ad-254803f3e610.mp4"
我在生成路径时添加了转义字符。但是在使用drawtext时,命令-drawtext=fontfile='C\\:\\Users\\Alan\\source\\repos\\TEST\\FFMPEG\\FreeSerif.ttf'
它总是在运行时失败。
如果在将“ C //:”更改为“ C /:”后在cmd中运行命令,则它可以工作。
当我需要为字体添加自定义路径时,我们该如何解决?
这是我在C#中设置命令的方式
string fontpath = System.Web.HttpContext.Current.Server.MapPath("~/FFMPEG/FreeSerif.ttf");
fontpath = fontpath.Replace(":", @"\:");
string ffmpegfile = System.Web.HttpContext.Current.Server.MapPath("~/FFMPEG/ffmpeg.exe");
string commandtorun = " -i " + inputvideo + " -i " + overlay + " -filter_complex \"[0:v][1:v] overlay=0:0:" +
"enable='between(t," + starttime + "," + endtime + ")',drawtext=fontfile='" + fontpath + "':enable='between(t," + starttime + "," + endtime + ")':fontcolor=white:fontsize=50:text='This section has been redacted':x=(w-text_w)/2:y=(h-text_h)/2[v];[0]volume=0:" +
"enable='between(t," + starttime + "," + endtime + ")'[a]\" -map \"[v]\" -map \"[a]\" " +
"-preset ultrafast " + finaloutput;