winform用FFMPEG将RTSP摄像头数据流转成MP4,进程间调用
下载地址:https://download.csdn.net/download/jsweiwei0702A/19543628
程序中已经包含ffmpeg所需要的dll,可以直接引用
下载源码文件后,打开后运行,就可以看到在E盘下创建了1.MP4了,大家可以试试,因为程序是在programe.CS下写的,因此没有画面,根据需要可以创建winform的画面。
以下为部分代码:
class Program
{
static DateTime tmpjiangetm = DateTime.Now; //录像时间,15分钟后停止
static RTSPHelper rtmp = new RTSPHelper();
static string camno = "0";
static bool boolloop = true;
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Thread VMSThread = new Thread(new ThreadStart(rcdadd));
VMSThread.IsBackground = true;
VMSThread.Start();
try
{
//string dstr = args[0]; ///其他程序调用该进程传递参数(3个参数,逗号隔开)例如: rtsp://192.168.1.168/stream1,E:\1.mp4,1
string dstr = "";
dstr = @"rtsp://192.168.1.168/stream1,E:\1.mp4,1";
if (dstr.Contains(","))
{
string filename = Regex.Split(dstr, ",", RegexOptions.IgnoreCase)[1];
string url = Regex.Split(dstr, ",", RegexOptions.IgnoreCase)[0];
camno = Regex.Split(dstr, ",", RegexOptions.IgnoreCase)[2];
if (filename.Contains(".mp4") && url.ToLower().Contains("stream"))
{
rtmp.StartSave(url, filename);
}
}
}
catch(Exception ex)
{
//MessageBox.Show(ex.Message);
}
finally
{
Application.Exit();
}
}
public static void rcdadd()
{
while (boolloop)
{
Thread.Sleep(100);
if (getSecond(tmpjiangetm, DateTime.Now) >= 900)
{
rtmp.Stop();
boolloop = false;
}
//程序文件加下常见close1.txt则会关闭1号录像,用来在多进程中调用(简单方法)
if (File.Exists(System.AppDomain.CurrentDomain.BaseDirectory + "close" + camno + ".txt"))
{
rtmp.Stop();
File.Delete(System.AppDomain.CurrentDomain.BaseDirectory + "close" + camno + ".txt");
boolloop = false;
}
}
}
#region 计算日期相差秒
public static int getSecond(DateTime bDate, DateTime eDate)
{
TimeSpan ts = new TimeSpan();
ts = eDate - bDate;
return (int)ts.TotalSeconds;
}
#endregion
}
其他进程传值调用方法:
string filename =“1.mp4";
string url = "rtsp://192.168.1.168/stream1";
string MainAppPath = System.AppDomain.CurrentDomain.BaseDirectory
+ "rcdsave\\Rcd_save.exe"; //the path of the exe file
System.Diagnostics.Process pro = new System.Diagnostics.Process();
pro.StartInfo.FileName = MainAppPath;
//传入4个字符串
pro.StartInfo.Arguments = string.Format("{0}", url + "," + filename+",1");
pro.Start();//开启程序