Ejemplo n.º 1
0
        public static void KillProcess(int pid)
        {
            string cmd = "kill -9 " + pid.ToString();

            LinuxShell.Run(cmd, 1000);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 输出视频的时长(毫秒)
        /// </summary>
        /// <param name="ffmpegBinPath"></param>
        /// <param name="videoFilePath"></param>
        /// <param name="duartion"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static bool GetDuration(string ffmpegBinPath, string videoFilePath, out long duartion, out string path)
        {
            duartion = -1;
            if (File.Exists(ffmpegBinPath) && File.Exists(videoFilePath))
            {
                string newPath = "";
                var    ret     = ifNotMp4(ffmpegBinPath, videoFilePath, out newPath);
                if (ret)
                {
                    videoFilePath = newPath;
                }
                path = videoFilePath;
                string cmd = ffmpegBinPath + " -i " + videoFilePath;
                if (LinuxShell.Run(cmd, 1000, out string std, out string err))
                {
                    if (!string.IsNullOrEmpty(std) || !string.IsNullOrEmpty(err))
                    {
                        string tmp = "";
                        if (!string.IsNullOrEmpty(std))
                        {
                            tmp = Common.GetValue(std, "Duration:", ",");
                        }

                        if (string.IsNullOrEmpty(tmp))
                        {
                            tmp = Common.GetValue(err, "Duration:", ",");
                        }

                        if (!string.IsNullOrEmpty(tmp))
                        {
                            string[] tmpArr = tmp.Split(':', StringSplitOptions.RemoveEmptyEntries);
                            if (tmpArr.Length == 3)
                            {
                                int hour = int.Parse(tmpArr[0]);
                                int min  = int.Parse(tmpArr[1]);
                                int sec  = 0;
                                int msec = 0;
                                if (tmpArr[2].Contains('.'))
                                {
                                    string[] tmpArr2 = tmpArr[2].Split('.', StringSplitOptions.RemoveEmptyEntries);
                                    sec  = int.Parse(tmpArr2[0]);
                                    msec = int.Parse(tmpArr2[1]);
                                }
                                else
                                {
                                    sec = int.Parse(tmpArr[2]);
                                }

                                hour     = hour * 3600;              //换成秒数
                                min      = min * 60;
                                sec      = sec + hour + min;         //合计秒数
                                duartion = sec * 1000 + (msec * 10); //算成毫秒
                                LogWriter.WriteLog("获取视频时长:" + duartion.ToString() + "毫秒", videoFilePath);
                                return(true);
                            }
                        }
                    }
                }
            }

            path = videoFilePath;
            return(false);
        }