fix video stream selection for remote streams (#2176)

This commit is contained in:
Jason Dove
2025-07-20 17:31:21 +00:00
committed by GitHub
parent 5c43ae47b1
commit 79496e688b
4 changed files with 38 additions and 12 deletions
@@ -295,6 +295,16 @@ public class GetPlayoutItemProcessByChannelNumberHandler : FFmpegProcessHandler<
audioPath = string.Empty;
}
bool hlsRealtime = request.HlsRealtime;
if (playoutItemWithPath.PlayoutItem.MediaItem is RemoteStream remoteStream)
{
// duration implies live input which we cannot burst
if (remoteStream.Duration.HasValue)
{
hlsRealtime = true;
}
}
bool saveReports = await dbContext.ConfigElements
.GetValue<bool>(ConfigElementKey.FFmpegSaveReports)
.Map(result => result.IfNone(false));
@@ -329,7 +339,7 @@ public class GetPlayoutItemProcessByChannelNumberHandler : FFmpegProcessHandler<
channel.FFmpegProfile.VaapiDriver,
channel.FFmpegProfile.VaapiDevice,
Optional(channel.FFmpegProfile.QsvExtraHardwareFrames),
request.HlsRealtime,
hlsRealtime,
playoutItemWithPath.PlayoutItem.FillerKind,
inPoint,
outPoint,
@@ -93,6 +93,16 @@ public class PrepareTroubleshootingPlaybackHandler(
duration = TimeSpan.FromSeconds(30);
}
var hlsRealtime = false;
if (mediaItem is RemoteStream remoteStream)
{
// duration implies live input which we cannot burst
if (remoteStream.Duration.HasValue)
{
hlsRealtime = true;
}
}
Command process = await ffmpegProcessService.ForPlayoutItem(
ffmpegPath,
ffprobePath,
@@ -122,7 +132,7 @@ public class PrepareTroubleshootingPlaybackHandler(
ffmpegProfile.VaapiDriver,
ffmpegProfile.VaapiDevice,
Option<int>.None,
false,
hlsRealtime,
FillerKind.None,
TimeSpan.Zero,
duration,
@@ -58,14 +58,6 @@ public class OutputFormatHls : IPipelineStep
_segmentTemplate
];
if (_isTroubleshooting)
{
result.AddRange(
[
"-hls_playlist_type", "vod"
]);
}
string pdt = _isTroubleshooting ? string.Empty : "program_date_time+omit_endlist+";
if (_isFirstTranscode)
@@ -167,7 +167,7 @@ public class LocalStatisticsProvider : ILocalStatisticsProvider
"-i", filePath
];
//_logger.LogDebug("ffprobe arguments {FFProbeArguments}", arguments);
//_logger.LogDebug("ffprobe arguments {FFProbeArguments}", arguments.ToList());
BufferedCommandResult probe = await Cli.Wrap(ffprobePath)
.WithArguments(arguments)
@@ -335,7 +335,10 @@ public class LocalStatisticsProvider : ILocalStatisticsProvider
version.Streams.Add(stream);
}
FFprobeStreamData videoStream = json.streams?.FirstOrDefault(s => s.codec_type == "video");
FFprobeStreamData videoStream = json.streams?
.Where(s => s.codec_type == "video")
.OrderByDescending(s => ParseBitRate(s.bit_rate))
.FirstOrDefault();
if (videoStream != null)
{
version.SampleAspectRatio = string.IsNullOrWhiteSpace(videoStream.sample_aspect_ratio)
@@ -494,6 +497,16 @@ public class LocalStatisticsProvider : ILocalStatisticsProvider
return Task.FromResult(path);
}
private static long ParseBitRate(string bitRate)
{
if (long.TryParse(bitRate, out long result))
{
return result;
}
return 0;
}
// ReSharper disable InconsistentNaming
public record FFprobe(FFprobeFormat format, List<FFprobeStreamData> streams, List<FFprobeChapter> chapters);
@@ -520,6 +533,7 @@ public class LocalStatisticsProvider : ILocalStatisticsProvider
string color_primaries,
string field_order,
string r_frame_rate,
string bit_rate,
string bits_per_raw_sample,
FFprobeDisposition disposition,
FFprobeTags tags);