From 209e3f94f2948d5315c709b279564c95d698bf3c Mon Sep 17 00:00:00 2001 From: schlick7 Date: Sat, 17 Jan 2026 10:11:37 -0600 Subject: [PATCH 1/2] Enhance audio extraction for non-Windows platforms Added support for non-Windows platforms by using ffmpeg for audio extraction. Updated ffmpeg path handling to use Path.Combine for better compatibility. --- AudioExtractor.cs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/AudioExtractor.cs b/AudioExtractor.cs index 8149bd3..5b04f67 100644 --- a/AudioExtractor.cs +++ b/AudioExtractor.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices; using NAudio.Wave; namespace SubtitleCreator @@ -28,6 +29,12 @@ public static string ExtractAudioFromVideoFile(string videoFilePath, bool attemp string newVideoFilePath = videoFilePath; bool tempFileCreated = false; + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + Utilities.ConsoleWithLog("Running on non-Windows platform, using ffmpeg for audio extraction."); + return ExtractAudioWithFfmpeg(videoFilePath, ffmpegPath); + } + if (Path.GetExtension(videoFilePath).ToLower() == ".mkv") { Utilities.ConsoleWithLog("Input file is in a MKV container. Extracting the video."); @@ -129,7 +136,7 @@ private static string RepairAudio(string videoFilePath, string ffmpegPath) // Set up the process to run FFmpeg using (Process ffmpeg = new Process()) { - ffmpeg.StartInfo.FileName = $"\"{ffmpegPath}\\ffmpeg\""; + ffmpeg.StartInfo.FileName = Path.Combine(ffmpegPath, "ffmpeg"); ffmpeg.StartInfo.Arguments = ffmpegArgs; ffmpeg.StartInfo.RedirectStandardError = true; ffmpeg.StartInfo.UseShellExecute = false; @@ -155,7 +162,7 @@ private static string ExtractVideoFromMKV(string videoFilePath, string ffmpegPat // Set up the process to run FFmpeg using (Process ffmpeg = new Process()) { - ffmpeg.StartInfo.FileName = $"\"{ffmpegPath}\\ffmpeg\""; + ffmpeg.StartInfo.FileName = Path.Combine(ffmpegPath, "ffmpeg"); ffmpeg.StartInfo.Arguments = ffmpegArgs; ffmpeg.StartInfo.RedirectStandardError = true; ffmpeg.StartInfo.UseShellExecute = false; @@ -171,5 +178,26 @@ private static string ExtractVideoFromMKV(string videoFilePath, string ffmpegPat return intermediateFilePath; } + + private static string ExtractAudioWithFfmpeg(string videoFilePath, string ffmpegPath) + { + outputFilePath = Path.Combine(Path.GetDirectoryName(videoFilePath) ?? string.Empty, $"{Path.GetFileNameWithoutExtension(videoFilePath)}{fileNameIdentifier}.wav"); + string ffmpegArgs = $"-i \"{videoFilePath}\" -vn -acodec pcm_s16le -ar 16000 -ac 1 \"{outputFilePath}\""; + + using (Process ffmpeg = new Process()) + { + ffmpeg.StartInfo.FileName = Path.Combine(ffmpegPath, "ffmpeg"); + ffmpeg.StartInfo.Arguments = ffmpegArgs; + ffmpeg.StartInfo.RedirectStandardError = true; + ffmpeg.StartInfo.UseShellExecute = false; + ffmpeg.StartInfo.CreateNoWindow = true; + + ffmpeg.Start(); + string output = ffmpeg.StandardError.ReadToEnd(); + ffmpeg.WaitForExit(); + } + + return outputFilePath; + } } } From b7938f6bff18fd1f5916c513b9c19ce5c5227a1a Mon Sep 17 00:00:00 2001 From: schlick7 Date: Sat, 17 Jan 2026 10:12:11 -0600 Subject: [PATCH 2/2] Refactor FFmpeg path setup to use Path.Combine --- CreateTheSubtitles.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CreateTheSubtitles.cs b/CreateTheSubtitles.cs index 2d07e6c..bdc4aab 100644 --- a/CreateTheSubtitles.cs +++ b/CreateTheSubtitles.cs @@ -301,7 +301,7 @@ public bool DoWorkMergeSubtitles(string srtFile, string inFile, string finalFile // Set up the process to run FFmpeg using (Process ffmpeg = new Process()) { - ffmpeg.StartInfo.FileName = $"\"{ffmpegPath}\\ffmpeg\""; + ffmpeg.StartInfo.FileName = Path.Combine(ffmpegPath, "ffmpeg"); ffmpeg.StartInfo.Arguments = ffmpegArgs; ffmpeg.StartInfo.RedirectStandardError = true; ffmpeg.StartInfo.UseShellExecute = false;