ffmpegの実行から使われない標準出力の処理を取り除く

このコミットが含まれているのは:
routersys committed 2026-09-13 17:52:31 +09:00
1 親 f1e39b536f
コミット 26226fd0cf
5ファイル変更
+31 -62

検索条件に一致するファイルはありません

+13 -36
ファイルの表示
@@ -332,7 +332,6 @@ public sealed class ProxyEncoderTests
},
workspace.Path,
null,
null,
ProcessPriorityClass.BelowNormal,
cancellation.Token));
@@ -362,7 +361,6 @@ public sealed class ProxyEncoderTests
},
workspace.Path,
null,
null,
ProcessPriorityClass.BelowNormal,
TestContext.Current.CancellationToken);
@@ -396,7 +394,6 @@ public sealed class ProxyEncoderTests
},
workspace.Path,
null,
null,
ProcessPriorityClass.BelowNormal,
TestContext.Current.CancellationToken);
@@ -436,7 +433,6 @@ public sealed class ProxyEncoderTests
static arguments => arguments.Add("-version"),
workspace.Path,
null,
null,
ProcessPriorityClass.BelowNormal,
TestContext.Current.CancellationToken));
}
@@ -494,7 +490,6 @@ public sealed class ProxyEncoderTests
arguments.Add("-");
},
workspace.Path,
null,
writer,
ProcessPriorityClass.BelowNormal,
TestContext.Current.CancellationToken);
@@ -580,39 +575,22 @@ public sealed class ProxyEncoderTests
async Task<string[]> ProbeAsync(string showEntries)
{
var values = new List<string>();
void Collect(ReadOnlySpan<char> line)
var startInfo = new ProcessStartInfo(Ymm4TestEnvironment.FFprobePath)
{
var trimmed = line.Trim();
if (!trimmed.IsEmpty)
values.Add(new string(trimmed));
}
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
WorkingDirectory = Path,
};
foreach (var argument in new[] { "-hide_banner", "-loglevel", "error", "-select_streams", "v:0", "-show_entries", showEntries, "-of", "csv=p=0", "-i", OutputPath })
startInfo.ArgumentList.Add(argument);
var result = await FFmpegProcessRunner.RunAsync(
Ymm4TestEnvironment.FFprobePath,
arguments =>
{
arguments.Add("-hide_banner");
arguments.Add("-loglevel");
arguments.Add("error");
arguments.Add("-select_streams");
arguments.Add("v:0");
arguments.Add("-show_entries");
arguments.Add(showEntries);
arguments.Add("-of");
arguments.Add("csv=p=0");
arguments.Add("-i");
arguments.Add(OutputPath);
},
Path,
Collect,
null,
ProcessPriorityClass.BelowNormal,
CancellationToken.None);
using var process = Process.Start(startInfo)!;
var output = await process.StandardOutput.ReadToEndAsync(TestContext.Current.CancellationToken);
await process.WaitForExitAsync(TestContext.Current.CancellationToken);
Assert.True(result.IsSuccess, result.Diagnostics);
return [.. values];
Assert.Equal(0, process.ExitCode);
return output.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
}
async Task RunFFmpegAsync(Action<Collection<string>> argumentWriter)
@@ -622,7 +600,6 @@ public sealed class ProxyEncoderTests
argumentWriter,
Path,
null,
null,
ProcessPriorityClass.BelowNormal,
CancellationToken.None);
-1
ファイルの表示
@@ -109,7 +109,6 @@ internal static class FFmpegEncoderSelector
arguments => FFmpegArguments.WriteEncoderProbe(arguments, encoder, width, height),
workingDirectory,
null,
null,
ProcessPriorityClass.BelowNormal,
timeout.Token).ConfigureAwait(false);
+18 -18
ファイルの表示
@@ -9,8 +9,6 @@ using YukkuriMovieMaker.Commons;
namespace ProxyForge.Encoding;
internal delegate void FFmpegLineHandler(ReadOnlySpan<char> line);
internal delegate Task FFmpegInputWriter(Stream destination, CancellationToken cancellationToken);
internal readonly record struct FFmpegProcessResult(int ExitCode, string Diagnostics)
@@ -60,7 +58,6 @@ internal static class FFmpegProcessRunner
string executablePath,
Action<Collection<string>> argumentWriter,
string workingDirectory,
FFmpegLineHandler? standardOutputHandler,
FFmpegInputWriter? standardInputWriter,
ProcessPriorityClass priority,
CancellationToken cancellationToken)
@@ -102,8 +99,8 @@ internal static class FFmpegProcessRunner
Log.Default.Write("ProxyForge: ffmpeg の優先度を設定できませんでした。", exception);
}
var standardOutputTask = PumpLinesAsync(process.StandardOutput, standardOutputHandler);
var standardErrorTask = PumpLinesAsync(process.StandardError, diagnostics.Append);
var standardOutputTask = DrainAsync(process.StandardOutput);
var standardErrorTask = PumpLinesAsync(process.StandardError, diagnostics);
var registration = cancellationToken.CanBeCanceled
? cancellationToken.Register(static state => TryKill((Process)state!), process)
@@ -178,20 +175,26 @@ internal static class FFmpegProcessRunner
}
}
static async Task PumpLinesAsync(TextReader reader, FFmpegLineHandler? handler)
static async Task DrainAsync(TextReader reader)
{
var buffer = ArrayPool<char>.Shared.Rent(LineBufferLength);
try
{
if (handler is null)
while (await reader.ReadAsync(buffer).ConfigureAwait(false) > 0)
{
while (await reader.ReadAsync(buffer).ConfigureAwait(false) > 0)
{
}
return;
}
}
finally
{
ArrayPool<char>.Shared.Return(buffer);
}
}
static async Task PumpLinesAsync(TextReader reader, FFmpegDiagnosticsBuffer diagnostics)
{
var buffer = ArrayPool<char>.Shared.Rent(LineBufferLength);
try
{
var length = 0;
while (true)
{
@@ -209,7 +212,7 @@ internal static class FFmpegProcessRunner
if (index < 0)
break;
handler(TrimLineEnd(pending[..index]));
diagnostics.Append(pending[..index]);
consumed += index + 1;
}
@@ -220,20 +223,17 @@ internal static class FFmpegProcessRunner
}
else if (length == buffer.Length)
{
handler(buffer.AsSpan(0, length));
diagnostics.Append(buffer.AsSpan(0, length));
length = 0;
}
}
if (length > 0)
handler(TrimLineEnd(buffer.AsSpan(0, length)));
diagnostics.Append(buffer.AsSpan(0, length));
}
finally
{
ArrayPool<char>.Shared.Return(buffer);
}
}
static ReadOnlySpan<char> TrimLineEnd(ReadOnlySpan<char> line)
=> line.Length > 0 && line[^1] == '\r' ? line[..^1] : line;
}
-1
ファイルの表示
@@ -94,7 +94,6 @@ internal sealed class ProxyEncoder(FFmpegExecutables executables, VideoSourceFac
executables.FFmpegPath,
arguments => FFmpegArguments.WriteEncode(arguments, in encodeRequest),
request.WorkingDirectory,
null,
pump.WriteAsync,
ProcessPriorityClass.BelowNormal,
cancellationToken).ConfigureAwait(false);
-6
ファイルの表示
@@ -89,12 +89,6 @@
"find": "if (trimmed.IsEmpty || builder.Length >= capacity)",
"replace": "if (trimmed.IsEmpty)"
},
{
"name": "行末の復帰を取り除かない",
"file": "ProxyForge/Encoding/FFmpegProcessRunner.cs",
"find": "=> line.Length > 0 && line[^1] == '\\r' ? line[..^1] : line;",
"replace": "=> line;"
},
{
"name": "入力の失敗をすべて包む",
"file": "ProxyForge/Encoding/FFmpegProcessRunner.cs",