public static string FlvSum(Flv A, bool 是否直播结束) { List <string> DelFileList = new List <string>(); String path1 = A.File1Url; String path2 = A.File2Url; if (!File.Exists(path1)) { InfoLog.InfoPrintf("续录文件[" + path1 + "]文件不存在,不符合合并条件,文件合并取消", InfoLog.InfoClass.Debug); return(null); } else if (!File.Exists(path2)) { InfoLog.InfoPrintf("续录文件[" + path2 + "]文件不存在,不符合合并条件,文件合并取消", InfoLog.InfoClass.Debug); return(null); } string output = ""; if (是否直播结束) { string file = A.File1Url.Replace("_202", "⒂").Split('⒂')[0]; if (file.Substring(file.Length - 4, 4) == ".flv") { file = file.Substring(0, file.Length - 4); } if (!string.IsNullOrEmpty(file)) { output = file + $"_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}合并.flv"; } else { string T1 = A.File1Url.Replace("_202", "⒂").Split('⒂')[0]; if (T1.Substring(T1.Length - 4, 4) == ".flv") { T1 = T1.Substring(0, T1.Length - 4); } if (!string.IsNullOrEmpty(T1)) { output = T1 + $"_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}合并.flv"; } else { output = $"_{new Random().Next(10000,99999)}合并.flv"; } } } else { output = A.File1Url.Replace("_202", "⒂").Split('⒂')[0] + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".flv"; } if (File.Exists(output)) { output.Replace(".flv", new Random().Next(1000, 9999) + ".flv"); } using (FileStream fs1 = new FileStream(path1, FileMode.Open)) using (FileStream fs2 = new FileStream(path2, FileMode.Open)) //using (FileStream fs3 = new FileStream(path3, FileMode.Open)) using (FileStream fsMerge = new FileStream(output, FileMode.Create)) { if (GetFLVFileInfo(fs1) != null && GetFLVFileInfo(fs2) != null) { if (IsSuitableToMerge(GetFLVFileInfo(fs1), GetFLVFileInfo(fs2)) == false )//|| IsSuitableToMerge(GetFLVFileInfo(fs1), GetFLVFileInfo(fs3)) == false) { InfoLog.InfoPrintf("1该视频不适合合并,放弃合并", InfoLog.InfoClass.载必要提示); return(null); } int time = Merge(fs1, fsMerge, true, 0); time = Merge(fs2, fsMerge, false, time); //time = Merge(fs3, fsMerge, false, time); InfoLog.InfoPrintf("续录文件[" + output + "]合并完成", InfoLog.InfoClass.载必要提示); fs1.Close(); fs1.Dispose(); fs2.Close(); fs2.Dispose(); fsMerge.Close(); fsMerge.Dispose(); //if (是否直播结束) //{ // try // { // 转码(output); // } // catch (Exception) // { // } //} //else //{ // GC.Collect(); //} return(output); } else { InfoLog.InfoPrintf("2该视频不适合合并,放弃合并", InfoLog.InfoClass.载必要提示); return(null); } } }
public static string FlvSum(Flv A, bool 是否直播结束) { String path1 = A.File1Url; String path2 = A.File2Url; if (!File.Exists(path1)) { InfoLog.InfoPrintf("续录文件[" + path1 + "]文件不存在,不符合合并条件,文件合并取消", InfoLog.InfoClass.Debug); if (File.Exists(path2)) { return(path2); } else { return(null); } } else if (!File.Exists(path2)) { InfoLog.InfoPrintf("续录文件[" + path2 + "]文件不存在,不符合合并条件,文件合并取消", InfoLog.InfoClass.Debug); return(null); } String output; if (是否直播结束) { output = A.File1Url.Replace("_202", "⒂").Split('⒂')[0] + ".flv"; } else { output = A.File1Url.Replace("_202", "⒂").Split('⒂')[0] + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".flv"; } using (FileStream fs1 = new FileStream(path1, FileMode.Open)) using (FileStream fs2 = new FileStream(path2, FileMode.Open)) //using (FileStream fs3 = new FileStream(path3, FileMode.Open)) using (FileStream fsMerge = new FileStream(output, FileMode.Create)) { if (GetFLVFileInfo(fs1) != null && GetFLVFileInfo(fs2) != null) { if (IsSuitableToMerge(GetFLVFileInfo(fs1), GetFLVFileInfo(fs2)) == false )//|| IsSuitableToMerge(GetFLVFileInfo(fs1), GetFLVFileInfo(fs3)) == false) { InfoLog.InfoPrintf("1该视频不适合合并,放弃合并", InfoLog.InfoClass.载必要提示); return(null); } int time = Merge(fs1, fsMerge, true, 0); time = Merge(fs2, fsMerge, false, time); //time = Merge(fs3, fsMerge, false, time); InfoLog.InfoPrintf("续录文件[" + output + "]合并完成", InfoLog.InfoClass.载必要提示); fs1.Close(); fs1.Dispose(); fs2.Close(); fs2.Dispose(); fsMerge.Close(); fsMerge.Dispose(); try { File.Delete(path1); File.Delete(path2); } catch (Exception) { } if (是否直播结束) { try { 转码(output); } catch (Exception) { } } else { GC.Collect(); } return(output); } else { InfoLog.InfoPrintf("2该视频不适合合并,放弃合并", InfoLog.InfoClass.载必要提示); return(null); } } }