ffmpeg使用记录

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)
            { 
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值