From 3ced1c9f06b5479bb93e9c092d39f4d51acaf3df Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Wed, 24 Feb 2021 17:57:30 +0100 Subject: [PATCH] Fix keepAudio/keepSubs config options --- Code/Main/CreateVideo.cs | 20 ++------------------ Code/Main/Interpolate.cs | 17 +++++++++++------ Code/Media/FfmpegAudioAndMetadata.cs | 11 +++++------ 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/Code/Main/CreateVideo.cs b/Code/Main/CreateVideo.cs index a7e301f..2b6721f 100644 --- a/Code/Main/CreateVideo.cs +++ b/Code/Main/CreateVideo.cs @@ -207,31 +207,15 @@ namespace Flowframes.Main return times; } - public static async Task MergeAudio(string inputPath, string outVideo, int looptimes = -1) + public static async Task MergeAudio(string inputPath, string outVideo) { - if (!Config.GetBool("keepAudio")) return; - try { - string audioFileBasePath = Path.Combine(I.current.tempFolder, "audio"); - - if (inputPath != null && IOUtils.IsPathDirectory(inputPath) && !File.Exists(IOUtils.GetAudioFile(audioFileBasePath))) // Try loading out of same folder as input if input is a folder - audioFileBasePath = Path.Combine(I.current.tempFolder.GetParentDir(), "audio"); - - // if (!File.Exists(IOUtils.GetAudioFile(audioFileBasePath))) - // await FfmpegAudioAndMetadata.ExtractAudioTracks(inputPath, audioFileBasePath); // Extract from sourceVideo to audioFile unless it already exists - - // if (!File.Exists(IOUtils.GetAudioFile(audioFileBasePath)) || new FileInfo(IOUtils.GetAudioFile(audioFileBasePath)).Length < 4096) - // { - // Logger.Log("Can't merge audio as there's no extracted audio file in the temp folder.", true); - // return; - // } - await FfmpegAudioAndMetadata.MergeAudioAndSubs(outVideo, I.current.tempFolder); // Merge from audioFile into outVideo } catch (Exception e) { - Logger.Log("Failed to copy audio!"); + Logger.Log("Failed to merge audio/subtitles with output video!"); Logger.Log("MergeAudio() Exception: " + e.Message, true); } } diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index aafbc2b..b4a51b4 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -106,15 +106,20 @@ namespace Flowframes Utils.FixConsecutiveSceneFrames(Path.Combine(current.tempFolder, Paths.scenesDir), current.framesFolder); if (canceled) return; - Program.mainForm.SetStatus("Extracting audio from video..."); - //string audioFile = Path.Combine(current.tempFolder, "audio"); - //if (audioFile != null && !File.Exists(audioFile)) - await FfmpegAudioAndMetadata.ExtractAudioTracks(inPath, current.tempFolder); + if (Config.GetBool("keepAudio")) + { + Program.mainForm.SetStatus("Extracting audio from video..."); + await FfmpegAudioAndMetadata.ExtractAudioTracks(inPath, current.tempFolder); + } if (canceled) return; - Program.mainForm.SetStatus("Extracting subtitles from video..."); - await FfmpegAudioAndMetadata.ExtractSubtitles(inPath, current.tempFolder, current.outMode); + + if (Config.GetBool("keepSubs")) + { + Program.mainForm.SetStatus("Extracting subtitles from video..."); + await FfmpegAudioAndMetadata.ExtractSubtitles(inPath, current.tempFolder, current.outMode); + } } public static async Task PostProcessFrames (bool stepByStep) diff --git a/Code/Media/FfmpegAudioAndMetadata.cs b/Code/Media/FfmpegAudioAndMetadata.cs index d6e5e2d..d686bee 100644 --- a/Code/Media/FfmpegAudioAndMetadata.cs +++ b/Code/Media/FfmpegAudioAndMetadata.cs @@ -156,7 +156,6 @@ namespace Flowframes.Media public static async Task MergeAudioAndSubs(string inputFile, string tempFolder) // https://superuser.com/a/277667 { - // Logger.Log($"[FFCmds] Merging audio from {audioPath} into {inputFile}", true); string containerExt = Path.GetExtension(inputFile); string tempPath = Path.Combine(tempFolder, $"vid{containerExt}"); string outPath = Path.Combine(tempFolder, $"muxed{containerExt}"); @@ -164,8 +163,11 @@ namespace Flowframes.Media string inName = Path.GetFileName(tempPath); string outName = Path.GetFileName(outPath); - string[] audioTracks = IOUtils.GetFilesSorted(tempFolder, false, "*_audio.*"); // Find audio files - string[] subTracks = IOUtils.GetFilesSorted(tempFolder, false, "*.srt"); // Find subtitle files + bool audio = Config.GetBool("keepAudio"); + bool subs = Utils.ContainerSupportsSubs(containerExt, false) && Config.GetBool("keepSubs"); + + string[] audioTracks = audio ? IOUtils.GetFilesSorted(tempFolder, false, "*_audio.*") : new string[0]; // Find audio files + string[] subTracks = subs ? IOUtils.GetFilesSorted(tempFolder, false, "*.srt") : new string[0]; // Find subtitle files Dictionary trackFiles = new Dictionary(); // Dict holding all track files with their index @@ -175,9 +177,6 @@ namespace Flowframes.Media foreach (string subTrack in subTracks) // Loop through subtitle streams to add them to the dict trackFiles[Path.GetFileNameWithoutExtension(subTrack).Split('_')[0].GetInt()] = subTrack; // Add file, dict key is stream index - bool audio = Config.GetBool("keepSubs"); - bool subs = Utils.ContainerSupportsSubs(containerExt, false) && Config.GetBool("keepSubs"); - string trackInputArgs = ""; string trackMapArgs = ""; string trackMetaArgs = "";