public void PublishAndCleanUpAfterCapture(string category, int preMinutes) { //If NAS path exists, move file mp4 file there if (!string.IsNullOrEmpty(configuration["nasPath"])) { string publishedPath = configuration["nasPath"]; //Category passed in? If so, let's publish to there instead if (!string.IsNullOrEmpty(category)) { publishedPath = Path.Combine(publishedPath, category); string invalidChars = new string(Path.GetInvalidPathChars()); foreach (char c in invalidChars) { publishedPath = publishedPath.Replace(c.ToString(), ""); } if (!Directory.Exists(publishedPath)) { Directory.CreateDirectory(publishedPath); } } //Ok, ready to publish files.SetPublishedFile(publishedPath); logWriter.WriteLine($"{DateTime.Now}: Moving {files.muxedFile.GetFullFile()} to {files.publishedFile.GetFullFile()}"); VideoFileManager.MoveFile(files.muxedFile.GetFullFile(), files.publishedFile.GetFullFile()); //Create poster string cmdLineArgs = configuration["artCmdLine"]; cmdLineArgs = cmdLineArgs.Replace("[SECONDS]", ((preMinutes + 1) * 60).ToString()); cmdLineArgs = cmdLineArgs.Replace("[VIDEOFILE]", files.publishedFile.GetFullFile()); cmdLineArgs = cmdLineArgs.Replace("[FULLOUTPUTPATH]", files.posterFile.GetFullFile()); logWriter.WriteLine($"{DateTime.Now}: Creating poster: {configuration["ffmpegPath"]} {cmdLineArgs}"); new ProcessManager(configuration).ExecProcess(logWriter, configuration["ffmpegPath"], cmdLineArgs); //Create fan art cmdLineArgs = configuration["artCmdLine"]; cmdLineArgs = cmdLineArgs.Replace("[SECONDS]", (((preMinutes) * 60) + 15).ToString()); cmdLineArgs = cmdLineArgs.Replace("[VIDEOFILE]", files.publishedFile.GetFullFile()); cmdLineArgs = cmdLineArgs.Replace("[FULLOUTPUTPATH]", files.fanartFile.GetFullFile()); logWriter.WriteLine($"{DateTime.Now}: Creating fan art: {configuration["ffmpegPath"]} {cmdLineArgs}"); new ProcessManager(configuration).ExecProcess(logWriter, configuration["ffmpegPath"], cmdLineArgs); } //If final file exist, delete old .ts file/s files.DeleteNonPublishedFiles(logWriter, configuration); }
public void MuxFile(string metadata) { //Set files.SetMuxedFile(configuration["outputPath"]); //If NAS path does not exist, set published file to this output too if (string.IsNullOrEmpty(configuration["nasPath"])) { files.SetPublishedFile(configuration["outputPath"]); } //Get the right input file VideoFileInfo inputFile; if (files.numberOfFiles > 1) { inputFile = files.concatFile; } else { inputFile = files.fileCaptureList[0]; } //Mux file is cmdline is there, otherwise, just rename it to mp4 if (!string.IsNullOrEmpty(configuration["muxCmdLine"])) { // "muxCmdLine": "[FULLFFMPEGPATH] -i [VIDEOFILE] -acodec copy -vcodec copy [FULLOUTPUTPATH]" string cmdLineArgs = configuration["muxCmdLine"]; cmdLineArgs = cmdLineArgs.Replace("[VIDEOFILE]", inputFile.GetFullFile()); cmdLineArgs = cmdLineArgs.Replace("[FULLOUTPUTPATH]", files.muxedFile.GetFullFile()); cmdLineArgs = cmdLineArgs.Replace("[DESCRIPTION]", metadata); //Run mux command logWriter.WriteLine($"{DateTime.Now}: Starting Mux: {configuration["ffmpegPath"]} {cmdLineArgs}"); new ProcessManager(configuration).ExecProcess(logWriter, configuration["ffmpegPath"], cmdLineArgs); } else { VideoFileManager.MoveFile(inputFile.GetFullFile(), files.muxedFile.GetFullFile()); } }