ffmpeg视频转码

   
string path = AppDomain.CurrentDomain.BaseDirectory;
List<VideoModel> list = new List<VideoModel>();
List<VideoResultModel> VideoResultList = new List<VideoResultModel>();
string FFIP = ConfigurationManager.AppSettings["FFIP"].ToString();
string FFport = ConfigurationManager.AppSettings["FFport"].ToString();
private string Test1(VideoModel model) { try { Process p = new Process(); p.StartInfo.FileName = path + "ffmpeg.exe"; p.StartInfo.UseShellExecute = false; //string srcFileName = ""; //string destFileName = ""; //srcFileName = "D:\\" + "1.dav"; //destFileName = "D:\\" + "2.mp4"; p.StartInfo.Arguments = "-i " + model.OldVideo + " -y -vcodec h264 -b 500000 " + model.NewVideo; //执行参数 p.StartInfo.UseShellExecute = false; ////不使用系统外壳程序启动进程 p.StartInfo.CreateNoWindow = true; //不显示dos程序窗口 p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中 // p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived); // p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived); p.StartInfo.UseShellExecute = false; p.Start(); // p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.BeginErrorReadLine();//开始异步读取 p.WaitForExit();//阻塞等待进程结束 p.Close();//关闭进程 p.Dispose();//释放资源 return ""; } catch (Exception ex) { RBILogs.WriteLog("error", ex.ToString()); return ex.ToString(); } }

或:建议用这种
Process procThumb = new Process();
procThumb.StartInfo.CreateNoWindow = true;//不显示dos程序窗口
procThumb.StartInfo.UseShellExecute = false;
procThumb.StartInfo.FileName = path + "ffmpeg.exe";
procThumb.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
procThumb.StartInfo.Arguments = "-rtsp_transport tcp -i \"" + model.RtspUri + "\" -c:a aac -c:v copy -acodec copy -f flv rtmp://" + "127.0.0.1" + ":1935/myapp/room" + model.CameraIp + "_" + model.CameraStream;
//procThumb.WaitForExit();
procThumb.Start();

  




  

posted @ 2021-01-12 17:29  飞鱼上树了  阅读(124)  评论(0编辑  收藏  举报
/* 看板娘 */