Example #1
0
        public int OnDvr(ReqSrsDvr dvr)
        {
            DateTime currentTime = DateTime.Now;

            DvrVideo tmpDvrVideo = new DvrVideo()
            {
                Device_Id  = dvr.Device_Id,
                Client_Id  = dvr.Client_Id,
                ClientIp   = dvr.Ip,
                ClientType = ClientType.Monitor,
                VideoPath  = dvr.File,
                App        = dvr.App,
                Stream     = dvr.Stream,
                Param      = dvr.Param,
                Vhost      = dvr.Vhost,
                Dir        = Path.GetDirectoryName(dvr.File),
            };

            FileInfo dvrFile = new FileInfo(dvr.File);

            tmpDvrVideo.FileSize = dvrFile.Length;
            if (FFmpegGetDuration.GetDuration(Program.CommonFunctions.FFmpegBinPath, dvr.File !, out long duration))
            {
                tmpDvrVideo.Duration  = duration;
                tmpDvrVideo.StartTime = currentTime.AddMilliseconds(duration * (-1));
                tmpDvrVideo.EndTime   = currentTime;
            }
Example #2
0
 static void Main(string[] args)
 {
     Console.WriteLine("Hello World!");
     FFmpegGetDuration.GetDuration("/usr/local/bin/ffmpeg",
                                   "/Users/qiuzhouwei/Downloads/iAETAqNtcDQDAQQABQAG2gAjhAGkC1ijNgKqjQN_hy6n5qQn_APPAAABcjCTN0AEzgAOpOcHzg4ccE0IAA.mp4",
                                   out long i);
     Console.WriteLine(
         Path.GetDirectoryName(
             "/root/StreamNode/eb1d30e2-1c69-4047-a08b-0003b66f430c/wwwroot/dvr/20200528/__defaultVhost__/live/34020000001330000001@34020000001320000001/23/20200528232737___defaultVhost___live_34020000001330000001@34020000001320000001.flv")
         );
     Console.WriteLine("时长(毫秒)" + i);
 }
Example #3
0
        /// <summary>
        /// 对文件进行操作
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public static CutMergeTaskResponse CutMerge(CutMergeTask task)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start(); //  开始监视代码运行时间
            LogWriter.WriteLog("合并请求任务开始(CutMerge)...", task.TaskId !);
            string taskPath = "";

            if (task != null && task.CutMergeFileList != null && task.CutMergeFileList.Count > 0)
            {
                taskPath = Common.WorkPath + "CutMergeDir/" + task.TaskId;
                if (!Directory.Exists(taskPath))
                {
                    Directory.CreateDirectory(taskPath);
                }

                try
                {
                    task            = packageToTsStreamFile(task); //转ts文件
                    task.TaskStatus = TaskStatus.Cutting;

                    List <CutMergeStruct> cutFileList = task.CutMergeFileList !
                                                        .FindAll(x => x.CutEndPos != null && x.CutStartPos != null).ToList();
                    for (int i = 0; i <= task.CutMergeFileList !.Count - 1; i++)
                    {
                        if (task.CutMergeFileList[i].CutStartPos != null && task.CutMergeFileList[i].CutEndPos != null)
                        {
                            task.ProcessPercentage += ((double)1 / (double)cutFileList.Count * 100f) * 0.15f;

                            //做剪切
                            task.CutMergeFileList[i] = cutProcess(task.CutMergeFileList[i]);
                            Thread.Sleep(20);
                        }
                    }

                    string filePath = mergeProcess(task);
                    task.ProcessPercentage = 100f;
                    task.TaskStatus        = TaskStatus.Closed;
                    stopwatch.Stop(); //  停止监视
                    TimeSpan timespan = stopwatch.Elapsed;
                    if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
                    {
                        long   duration = -1;
                        string newPath  = "";
                        FFmpegGetDuration.GetDuration(Common.FFmpegBinPath, filePath, out duration, out newPath);
                        var ret = CutMergeTaskStatusList.FindLast(x => x.TaskId == task.TaskId);
                        if (ret != null)
                        {
                        }
                        return(new CutMergeTaskResponse
                        {
                            FilePath = newPath,
                            FileSize = new FileInfo(filePath).Length,
                            Duration = duration,
                            Status = CutMergeRequestStatus.Succeed,
                            Task = task,
                            TimeConsuming = timespan.TotalMilliseconds,
                        });
                    }

                    return(new CutMergeTaskResponse
                    {
                        FilePath = "",
                        Status = CutMergeRequestStatus.Failed,
                        FileSize = -1,
                        Duration = -1,
                        Task = task,
                        TimeConsuming = timespan.TotalMilliseconds,
                    });
                }
                catch (Exception ex)
                {
                    LogWriter.WriteLog("裁剪合并视频文件时出现异常...", ex.Message + "\r\n" + ex.StackTrace, ConsoleColor.Yellow);
                    return(null !);
                }
                finally
                {
                    if (!string.IsNullOrEmpty(taskPath) && Directory.Exists(taskPath)) //清理战场
                    {
                        Directory.Delete(taskPath, true);
                    }

                    if (File.Exists(Common.WorkPath + "CutMergeDir/" + task !.TaskId + "files.txt")
                        ) //清理战场
                    {
                        File.Delete(Common.WorkPath + "CutMergeDir/" + task !.TaskId + "files.txt");
                    }
                }
            }


            return(null !);
        }