1.文字信息打到视频上面,倾斜覆盖视频效果。
ffmpeg -i a.avi -filter_complex "color=White:s=400x400[v1];[v1]drawtext=fontfile=simhei.ttf:text='abcdefg':x=60:y=50:fontsize=20,drawtext=fontfile=simhei.ttf:text='abcdefg':x=90:y=80:fontsize=20[o1];[o1]rotate=a=-PI*30/180:fillcolor=White@0[o1];[o1]colorkey=White:0.01:1[o2];[0:v][o2]overlay=x=(W-w)/2:y=(H-h)/2:shortest=1" -y b.mp4
2.文字信息打到视频上面,多行文字不倾斜。
ffmpeg -i a.avi -vf "[in]drawtext=text='abcdefg':fontcolor=white: borderw=2: fontfile=Arial Black: fontsize=w*0.04:x=(w-text_w)-(w*0.04): y=(h-text_h)-(w*0.04): enable='between(t,0,6)',drawtext=text='abcdefg':fontcolor=white: borderw=2:fontfile=Arial Black: fontsize=w*0.04: x=(w-text_w)/2: y=(h-text_h)/2:enable='between(t,7,10)'[out]" -codec:a copy b.mp4
3.文字信息打到视频上面,单行文字。
ffmpeg -i a.avi -vf "drawtext = fontfile = simhei.ttf: text = 'abcdef':x = 100:y = 10:fontsize = 15:fontcolor = yellow:shadowy = 2" b.mp4
/// <summary>
/// C#运行CMD操作视频文件打水印
/// </summary>
/// <param name="inFile">不带水印源文件视频</param>
/// <param name="outFile">输出带水印效果的文件名</param>
private void RunCmd(string inFile, string outFile)
{
try
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.CreateNoWindow = true;
psi.WorkingDirectory = FFmpegPath;//不带水印源文件视频所在目录
using (System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi))
{
System.IO.StreamWriter sIn = proc.StandardInput;
string wm = $@"{Common.LoginName}_{Common.LocalMac.Split(';')[0].Replace("-", "")}_{DateTime.Now.ToString("yyyyMMddHHmmss")}";//水印文本信息
sIn.WriteLine(Application.StartupPath + "\\ffmpeg.exe -i " + inFile + " -filter_complex \"color=White:s=400x400[v1];[v1]drawtext=fontfile=simhei.ttf:text='" + wm + "':x=" + 0 + ":y=" + 90 + ":fontsize=20,drawtext=fontfile=simhei.ttf:text='" + wm + "':x=" + -5 + ":y=" + 200 + ":fontsize=20,drawtext=fontfile=simhei.ttf:text='" + wm + "':x=" + -10 + ":y=" + 310 + ":fontsize=20[o1];[o1]rotate=a=-PI*30/180:fillcolor=White@0[o1];[o1]colorkey=White:0.01:1[o2];[0:v][o2]overlay=x=(W-w)/2:y=(H-h)/2:shortest=1\" -y " + outFile + ".mp4");
sIn.Close();
//proc.WaitForExit();
proc.Close();
}
}
catch (Exception e)
{
}
}