From 51a3e2d462f9417ab9302b07e220b3eceb503143 Mon Sep 17 00:00:00 2001 From: albarago <178173160+albarago@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:51:52 -0600 Subject: Merge pull request #18761 from albarago/probe-cancel Stop ffprobe when a metadata probe is cancelled or returns bad output --- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'MediaBrowser.MediaEncoding/Encoder') diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index a751baf8b4..95095088c5 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -549,28 +549,28 @@ namespace MediaBrowser.MediaEncoding.Encoder { StartProcess(processWrapper); using var reader = process.StandardOutput; - await reader.BaseStream.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false); - memoryStream.Seek(0, SeekOrigin.Begin); InternalMediaInfoResult result; try { + await reader.BaseStream.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false); + memoryStream.Seek(0, SeekOrigin.Begin); result = await JsonSerializer.DeserializeAsync( memoryStream, _jsonSerializerOptions, cancellationToken).ConfigureAwait(false); + if (result is null || (result.Streams is null && result.Format is null)) + { + throw new FfmpegException("ffprobe failed - streams and format are both null."); + } } catch { + // Cancellation while copying stdout must stop the probe before the wrapper unregisters it. StopProcess(processWrapper, 100); throw; } - if (result is null || (result.Streams is null && result.Format is null)) - { - throw new FfmpegException("ffprobe failed - streams and format are both null."); - } - if (result.Streams is not null) { // Normalize aspect ratio if invalid -- cgit v1.2.3