2021-06-10

winform用FFMPEG将RTSP摄像头数据流转成MP4,进程间调用
下载地址:https://download.csdn.net/download/jsweiwei0702A/19543628
程序中已经包含ffmpeg所需要的dll,可以直接引用

下载源码文件后,打开后运行,就可以看到在E盘下创建了1.MP4了,大家可以试试,因为程序是在programe.CS下写的,因此没有画面,根据需要可以创建winform的画面。
dll及部分类
生成的MP4
以下为部分代码:


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();//开启程序

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值