Код: Выделить всё
private static async Task RunFFmpegProcessAsync(string arguments, CancellationToken cancellationToken = default)
{
var psi = new ProcessStartInfo
{
FileName = Path.Combine(GetFFMpegDirectory(), _ffmpegFileName),
Arguments = arguments,
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
};
using (var process = new Process { StartInfo = psi })
{
if (!process.Start())
{
throw new InvalidOperationException("Failed to start FFmpeg process.");
}
// Read output/error streams to avoid deadlocks
string output = await process.StandardOutput.ReadToEndAsync(cancellationToken);
string error = await process.StandardError.ReadToEndAsync(cancellationToken);
await process.WaitForExitAsync(cancellationToken);
process.Close();
}
}
< /code>
Затем я называю это так: < /p>
public async Task GetStrictWaveStreamAsync(IFileInfo fileInfo)
{
var tempOutput = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav");
var ffmpegArgs = $"""-i "{fileInfo.PhysicalPath}" -ar 16000 -ac 1 -c:a pcm_s16le -y "{tempOutput}" """;
try
{
await RunFFmpegProcessAsync(ffmpegArgs);
File.Delete(fileInfo.PhysicalPath); //
проблема: < /strong>
File.Delete(fileInfo.PhysicalPath)Процесс не может получить доступ к файлу '...', потому что он используется другим процессом. /> Вопрос: < /strong>
Как я могу гарантировать, что процесс FFMPEG и его потоки полностью выпущены, чтобы я мог безопасно удалить входной файл сразу после обработки?>
Подробнее здесь: https://stackoverflow.com/questions/797 ... immediatly
Мобильная версия