Beispiel #1
0
        public static bool Convert(string sSrcFile, string sDescFile)
        {
            sSrcFile  = Path.GetFullPath(sSrcFile);
            sDescFile = Path.GetFullPath(sDescFile);
            if (!File.Exists(sSrcFile))
            {
                return(false);
            }
            if (File.Exists(sDescFile))
            {
                File.Delete(sDescFile);
            }

            string sFFmpegPath = "ffmpeg.exe";
            string sCmd        = "-i \"" + sSrcFile + "\" -c copy \"" + sDescFile + "\"";
            int    exitCode    = CmdHelper.StartExe(sFFmpegPath, sCmd, IsShowWindow: false, IsWatiForExit: true);

            return(exitCode == 0);
        }
Beispiel #2
0
        /// <summary>
        /// 合并文件
        /// </summary>
        /// <param name="pFiles">源文件列表</param>
        /// <param name="sToFilePath">目标文件地址</param>
        /// <returns>True/False</returns>
        public static bool MergerByFiles(string[] pFiles, string sToFilePath)
        {
            if (sToFilePath.IsBlank() || pFiles == null)
            {
                return(false);
            }

            string sFileName = PathHelper.ReplaceLimitChar(Path.GetFileNameWithoutExtension(sToFilePath), "-");

            //创建目录
            string sTmpPath = Path.GetDirectoryName(sToFilePath);
            var    di       = new DirectoryInfo(sTmpPath);

            if (!di.Exists)
            {
                di.Create();
            }

            //创建临时文件
            string sTmpFile = sTmpPath + "\\" + sFileName + "TMP.txt";

            foreach (string item in pFiles)
            {
                FileHelper.Write("file \'" + item + "\'\n", false, sTmpPath + "\\" + sFileName + "TMP.txt");
            }

            //删除旧文件
            if (File.Exists(sToFilePath))
            {
                File.Delete(sToFilePath);
            }

            //启动合并转换进程
            string cmd      = "-f concat -safe 0 -i \"" + sTmpFile + "\" -c copy \"" + sToFilePath + "\"";
            int    exitCode = CmdHelper.StartExe("ffmpeg.exe", cmd, IsShowWindow: false, IsWatiForExit: true);

            //删除临时文件
            File.Delete(sTmpFile);
            return(exitCode == 0);
        }