using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace cmdCreate
{
class Program
{
static void Main(string[] args)
{
var p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.Start();
p.StandardInput.WriteLine("cd D:\\BaiduNetdiskDownload\\Titanic - 副本");
p.StandardInput.WriteLine("ffmpeg -i 1.mp4 -ss 00:26:56 -to 00:26:59 -c copy d1.mp4");
p.StandardInput.WriteLine("exit");
p.StandardInput.Flush();
}
}
}
确实执行了cmd命令,没有报错。但是“p.StandardInput.WriteLine("ffmpeg -i 1.mp4 -ss 00:26:56 -to 00:26:59 -c copy d1.mp4");”这一步生成的文件是损坏的,程序貌似并没有给第二条命令足够的执行时间,因为我在cmd上打这条命令它需要执行10秒,但是在c#上边瞬间就完成了。
可以用Process执行ffmpeg,然后等待结束,要不就算可以用线程暂停当前代码执行,但是等待时间不好确定
using System;
using System.Diagnostics;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.WorkingDirectory = "D:\\BaiduNetdiskDownload\\Titanic - 副本\\";
p.StartInfo.FileName = p.StartInfo.WorkingDirectory+"ffmpeg.exe";//注意修改ffmpeg路径,这里是将ffmpeg放到和mp4目录下了
p.StartInfo.Arguments = "-i 1.mp4 -ss 00:26:56 -to 00:26:59 -c copy d1.mp4";
p.Start();
p.WaitForExit();////////等待转换完毕
p.Close();
p.Dispose();
}
}
}
那加个readkey等个十几秒看看能不能正常完成,能的话就想办法判断一下