ffmpegが異常終了した時は入力の書き込みの失敗より終了コードを返す

このコミットが含まれているのは:
routersys committed 2026-09-15 20:11:02 +09:00
1 親 9352e8e2c3
コミット 4f2e566ab8
2ファイル変更
+57 -4

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

+52
ファイルの表示
@@ -187,6 +187,20 @@ public sealed class ProxyEncoderTests
Assert.False(File.Exists(workspace.OutputPath));
}
[Fact]
public async Task AnOutputThatCannotBeOpenedIsReportedAsAnFFmpegFailure()
{
Ymm4TestEnvironment.Require();
using var workspace = new Workspace();
var encoder = workspace.CreateEncoder(640, 360, 30, 1, 10);
using var session = await encoder.OpenAsync(workspace.Request(50), TestContext.Current.CancellationToken);
var missing = Path.Combine(workspace.Path, "missing", "proxy.mp4");
var exception = await Assert.ThrowsAsync<ProxyEncodeException>(() => session.EncodeAsync(0, 10, missing, null, TestContext.Current.CancellationToken));
Assert.Equal(ProxyEncodeFailure.FFmpegFailed, exception.Failure);
}
[Fact]
public async Task ASoftEdgeIsNotMistakenForTransparency()
{
@@ -474,6 +488,44 @@ public sealed class ProxyEncoderTests
Assert.IsType<IOException>(failure.InnerException);
}
[Fact]
public async Task RunAsyncReportsTheExitOfFFmpegThatStoppedReadingTheInput()
{
Ymm4TestEnvironment.Require();
using var workspace = new Workspace();
var missing = Path.Combine(workspace.Path, "missing", "proxy.mp4");
Exception? failure = null;
var result = await FFmpegProcessRunner.RunAsync(
Ymm4TestEnvironment.FFmpegPath,
arguments =>
{
var request = new FFmpegEncodeRequest(missing, 32, 32, new FrameRate(30, 1), 100_000, 1, SoftwareEncoder);
FFmpegArguments.WriteEncode(arguments, in request);
},
workspace.Path,
(destination, cancellationToken) => Task.Run(() =>
{
var frame = new byte[32 * 32 * 4];
try
{
for (var index = 0; index < 1024; index++)
destination.Write(frame);
}
catch (IOException exception)
{
failure = exception;
throw;
}
}, cancellationToken),
ProcessPriorityClass.BelowNormal,
TestContext.Current.CancellationToken);
Assert.IsType<IOException>(failure);
Assert.False(result.IsSuccess);
Assert.Contains(missing, result.Diagnostics);
}
[Fact]
public async Task RunAsyncRethrowsOtherFailuresOfTheInputWriterUnchanged()
{
+5 -4
ファイルの表示
@@ -133,12 +133,13 @@ internal static class FFmpegProcessRunner
cancellationToken.ThrowIfCancellationRequested();
if (inputFailure is IOException)
throw new InvalidOperationException(string.Concat("Failed to send frames to FFmpeg. ", diagnostics.ToString()), inputFailure);
if (inputFailure is not null)
var result = new FFmpegProcessResult(process.ExitCode, diagnostics.ToString());
if (inputFailure is IOException && result.IsSuccess)
throw new InvalidOperationException(string.Concat("Failed to send frames to FFmpeg. ", result.Diagnostics), inputFailure);
if (inputFailure is not (null or IOException))
ExceptionDispatchInfo.Throw(inputFailure);
return new FFmpegProcessResult(process.ExitCode, diagnostics.ToString());
return result;
}
static async Task WriteStandardInputAsync(Process process, FFmpegInputWriter writer, CancellationToken cancellationToken)