-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExtractAudio.cs
More file actions
53 lines (43 loc) · 1.89 KB
/
ExtractAudio.cs
File metadata and controls
53 lines (43 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Spectre.Console;
using System;
using System.Diagnostics;
namespace CurseWordExtractor
{
internal static class ExtractAudio
{
public static string GetAudio16khz(string videoFilePath)
{
string outputWavPath = "temp_16khz_audio.wav";
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "ffmpeg";
// Added aresample=async=1:first_pts=0 to force perfect synchronization
// and pad any missing start-time gaps with silence.
psi.Arguments = $"-i \"{videoFilePath}\" -vn -ar 16000 -ac 1 -c:a pcm_s16le -af \"aresample=async=1:first_pts=0\" -y \"{outputWavPath}\"";
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
using (Process process = Process.Start(psi))
{
process.WaitForExit();
}
AnsiConsole.MarkupLine("\n\n\t\t[blue]:small_blue_diamond:[/]16kHz Audio extraction complete.");
return outputWavPath;
}
public static string GetHighQualityAudio(string videoFilePath)
{
string outputWavPath = "temp_hq_audio.wav";
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "ffmpeg";
// Added first_pts=0 here as well so the high-quality audio aligns perfectly
// with the 16kHz audio and the original MKV container.
psi.Arguments = $"-i \"{videoFilePath}\" -vn -c:a pcm_s16le -af \"aresample=async=1:first_pts=0\" -y \"{outputWavPath}\"";
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
using (Process process = Process.Start(psi))
{
process.WaitForExit();
}
AnsiConsole.MarkupLine("\n\n\t[blue]:small_blue_diamond:[/][white] High-Quality extraction complete.[/]");
return outputWavPath;
}
}
}