Esempio n. 1
0
        static void Main(string[] args)
        {
            List <string> old_sns   = new List <string>();
            List <string> old_rtmps = new List <string>();

            while (true)
            {
                List <string> new_sns   = new List <string>();
                List <string> new_rtmps = new List <string>();
                using (SmartBuildingEntities sme = new SmartBuildingEntities())
                {
                    foreach (var item in sme.CamRTMP)
                    {
                        new_sns.Add(item.SN);
                        new_rtmps.Add(item.RTMPhd);
                    }
                }
                string[] sns   = new_sns.Except(old_sns).ToArray();
                string[] rtmps = new_rtmps.Except(old_rtmps).ToArray();
                if (sns.Length > 0)
                {
                    old_sns   = new_sns;
                    old_rtmps = new_rtmps;
                    for (var i = 0; i < rtmps.Length; i++)
                    {
                        video temp = new video();
                        temp.SN     = sns[i];
                        temp.RTMPhd = rtmps[i];
                        Task.Factory.StartNew(SetTimer, temp);
                        //SetTimer(temp);
                    }
                    ;
                }
                System.Threading.Thread.Sleep(1000);
            }
            Console.Read();
        }
Esempio n. 2
0
        //private static void SaveVideo(object sender, ElapsedEventArgs e)
        private static bool SaveVideo(string sn, string RTMPhd)
        {
            string baseDir = @"D:\ffmpeg\";

            //string baseDir = @"K:\1.1\ffmpeg-20170731-b664d1f-win64-static\bin\";
            if (!Directory.Exists(baseDir + sn))
            {
                Directory.CreateDirectory(baseDir + sn);
            }
            DateTime Now  = DateTime.Now;
            string   date = DateTime.Now.ToString("yyMMddHHmm");

            using (SmartBuildingEntities sme = new SmartBuildingEntities()) {
                VideoPath vp = new VideoPath()
                {
                    VideoName = date + ".mp4",
                    StartTime = Now,
                    SN        = sn
                };
                sme.VideoPath.Add(vp);
                sme.SaveChanges();
            }

            string spath  = baseDir;
            string topath = baseDir + sn + @"\";

            RTMPhd = RTMPhd.Replace("\r\n", "");
            string cmd = @"D: && cd " + spath + " &&  ffmpeg -y -i " + RTMPhd + " -t 1200 -vcodec copy -acodec copy -f mp4 " + topath + date + ".mp4";

            Console.WriteLine("****************S*****************");
            Console.WriteLine(cmd);
            Console.WriteLine("****************E*****************");
            //string cmd = @"-y -i rtmp://live.hkstv.hk.lxdns.com/live/hks -vcodec copy -acodec copy -f mp4 K:\Project\姚门项目\智慧工地\管理系统\demo1\Mag\video\"+date+".mp4";
            EXECMD(cmd);
            return(true); //表示执行完了
        }