-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (49 loc) · 1.79 KB
/
Copy pathProgram.cs
File metadata and controls
58 lines (49 loc) · 1.79 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
54
55
56
57
58
using System;
using System.Diagnostics;
using System.IO;
class WavToMp3Converter
{
static void Main(string[] args)
{
Console.WriteLine("Enter the full path to the .wav file:");
string? inputFilePath = Console.ReadLine()?.Trim()?.Trim('\"', '\'');
if (string.IsNullOrEmpty(inputFilePath))
{
Console.WriteLine("No file path provided.");
return;
}
if (!File.Exists(inputFilePath))
{
Console.WriteLine("The file does not exist: " + inputFilePath);
return;
}
string outputFilePath = Path.ChangeExtension(inputFilePath, ".mp3");
try
{
Console.WriteLine($"Starting conversion: {inputFilePath} -> {outputFilePath}");
Process ffmpeg = new Process();
ffmpeg.StartInfo.FileName = "ffmpeg";
ffmpeg.StartInfo.Arguments = $"-i \"{inputFilePath}\" \"{outputFilePath}\"";
ffmpeg.StartInfo.RedirectStandardOutput = true;
ffmpeg.StartInfo.RedirectStandardError = true;
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.Start();
string ffmpegOutput = ffmpeg.StandardError.ReadToEnd();
ffmpeg.WaitForExit();
Console.WriteLine("FFmpeg output:");
Console.WriteLine(ffmpegOutput);
if (ffmpeg.ExitCode == 0)
{
Console.WriteLine("Conversion complete. MP3 saved at: " + outputFilePath);
}
else
{
Console.WriteLine("FFmpeg failed. Check the output for details.");
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}