wav파일들이 있는데 크기를 줄일려고 flac으로 바꾸려고 하는데
샤나인코더를 쓰다가 flac으로 변환할 때는 멀티스레드도 안 쓰는 것도 있고
매번 파일에 있는 것을 드래그 해서 넣는 것도 번거로워서 만듦.
원래는 python으로 만들까 했는데 나는 C#이 더 편해서 C#으로 짬
잘 되더라.
using System.Diagnostics;
var files = new List<string>();
foreach (var arg in args)
{
files.AddRange(Directory.EnumerateFiles(arg, "*.wav", SearchOption.AllDirectories));
}
var tasks = new List<Task<bool>>();
foreach (var filePathString in files)
{
var dir = Path.GetDirectoryName(filePathString);
var outputFilePathString = Path.GetFileNameWithoutExtension(filePathString) + ".flac";
if (!string.IsNullOrEmpty(dir))
{
outputFilePathString = Path.Combine(dir, outputFilePathString);
}
var task = Task.Run(async () =>
{
var process = Process.Start("ffmpeg", $"-i \"{filePathString}\" \"{outputFilePathString}\"");
process.OutputDataReceived += (sender, e) =>
{
Console.WriteLine($"File: {filePathString}\n Message: {e.Data}\n");
};
await process.WaitForExitAsync();
Console.WriteLine($"File {filePathString} convert success");
return true;
});
tasks.Add(task);
}
foreach (var task in tasks)
{
task.Wait();
}
? Task를 리스트에 넣고 순차적으로 Wait하는게 맞는거임? WaitAll 같은거 써야 의미 있는거 아니냐
순차적으로 Wait하나 WaitAll을 쓰나 다를 게 뭐가 있음
WaitAll이 IEnumerable을 받는 것로 기억하는데 내부에서 순회하면서 Wait하지 않겠음?
Parallel.ForEach(files, file => { ffmpeg }); 는 어떨까요
바꿔보겠음
공앱 다크모드에서 코드 안보이노