fix placing watermarks within source content (#2297)

* fix placing watermarks within source content

* formatting
This commit is contained in:
Jason Dove
2025-08-11 16:02:16 +00:00
committed by GitHub
parent 1cac210765
commit 8cbc3b083a
7 changed files with 126 additions and 87 deletions
@@ -375,84 +375,6 @@ public class FFmpegLibraryProcessService : IFFmpegProcessService
graphicsElementContexts.AddRange(watermarks.Values);
}
foreach (var playoutItemGraphicsElement in graphicsElements)
{
switch (playoutItemGraphicsElement.GraphicsElement.Kind)
{
case GraphicsElementKind.Text:
{
var maybeElement =
await TextGraphicsElement.FromFile(playoutItemGraphicsElement.GraphicsElement.Path);
if (maybeElement.IsNone)
{
_logger.LogWarning(
"Failed to load text graphics element from file {Path}; ignoring",
playoutItemGraphicsElement.GraphicsElement.Path);
}
foreach (var element in maybeElement)
{
var variables = new Dictionary<string, string>();
if (!string.IsNullOrWhiteSpace(playoutItemGraphicsElement.Variables))
{
variables = JsonConvert.DeserializeObject<Dictionary<string, string>>(
playoutItemGraphicsElement.Variables);
}
graphicsElementContexts.Add(new TextElementContext(element, variables));
}
break;
}
case GraphicsElementKind.Image:
{
var maybeElement =
await ImageGraphicsElement.FromFile(playoutItemGraphicsElement.GraphicsElement.Path);
if (maybeElement.IsNone)
{
_logger.LogWarning(
"Failed to load image graphics element from file {Path}; ignoring",
playoutItemGraphicsElement.GraphicsElement.Path);
}
foreach (var element in maybeElement)
{
// var variables = new Dictionary<string, string>();
// if (!string.IsNullOrWhiteSpace(playoutItemGraphicsElement.Variables))
// {
// variables = JsonConvert.DeserializeObject<Dictionary<string, string>>(
// playoutItemGraphicsElement.Variables);
// }
graphicsElementContexts.Add(new ImageElementContext(element));
}
break;
}
default:
_logger.LogInformation(
"Ignoring unsupported graphics element kind {Kind}",
nameof(playoutItemGraphicsElement.GraphicsElement.Kind));
break;
}
}
// only use graphics engine when we have elements
if (graphicsElementContexts.Count > 0)
{
graphicsEngineInput = new GraphicsEngineInput();
graphicsEngineContext = new GraphicsEngineContext(
audioVersion.MediaItem,
graphicsElementContexts,
channel.FFmpegProfile.Resolution,
await playbackSettings.FrameRate.IfNoneAsync(24),
ChannelStartTime: channelStartTime,
ContentStartTime: start,
await playbackSettings.StreamSeek.IfNoneAsync(TimeSpan.Zero),
finish - now);
}
HardwareAccelerationMode hwAccel = GetHardwareAccelerationMode(playbackSettings, fillerKind);
string videoFormat = GetVideoFormat(playbackSettings);
@@ -525,6 +447,85 @@ public class FFmpegLibraryProcessService : IFFmpegProcessService
playbackSettings.VideoTrackTimeScale,
playbackSettings.Deinterlace);
foreach (var playoutItemGraphicsElement in graphicsElements)
{
switch (playoutItemGraphicsElement.GraphicsElement.Kind)
{
case GraphicsElementKind.Text:
{
var maybeElement =
await TextGraphicsElement.FromFile(playoutItemGraphicsElement.GraphicsElement.Path);
if (maybeElement.IsNone)
{
_logger.LogWarning(
"Failed to load text graphics element from file {Path}; ignoring",
playoutItemGraphicsElement.GraphicsElement.Path);
}
foreach (var element in maybeElement)
{
var variables = new Dictionary<string, string>();
if (!string.IsNullOrWhiteSpace(playoutItemGraphicsElement.Variables))
{
variables = JsonConvert.DeserializeObject<Dictionary<string, string>>(
playoutItemGraphicsElement.Variables);
}
graphicsElementContexts.Add(new TextElementContext(element, variables));
}
break;
}
case GraphicsElementKind.Image:
{
var maybeElement =
await ImageGraphicsElement.FromFile(playoutItemGraphicsElement.GraphicsElement.Path);
if (maybeElement.IsNone)
{
_logger.LogWarning(
"Failed to load image graphics element from file {Path}; ignoring",
playoutItemGraphicsElement.GraphicsElement.Path);
}
foreach (var element in maybeElement)
{
// var variables = new Dictionary<string, string>();
// if (!string.IsNullOrWhiteSpace(playoutItemGraphicsElement.Variables))
// {
// variables = JsonConvert.DeserializeObject<Dictionary<string, string>>(
// playoutItemGraphicsElement.Variables);
// }
graphicsElementContexts.Add(new ImageElementContext(element));
}
break;
}
default:
_logger.LogInformation(
"Ignoring unsupported graphics element kind {Kind}",
nameof(playoutItemGraphicsElement.GraphicsElement.Kind));
break;
}
}
// only use graphics engine when we have elements
if (graphicsElementContexts.Count > 0)
{
graphicsEngineInput = new GraphicsEngineInput();
graphicsEngineContext = new GraphicsEngineContext(
audioVersion.MediaItem,
graphicsElementContexts,
new Resolution { Width = desiredState.ScaledSize.Width, Height = desiredState.ScaledSize.Height },
channel.FFmpegProfile.Resolution,
await playbackSettings.FrameRate.IfNoneAsync(24),
ChannelStartTime: channelStartTime,
ContentStartTime: start,
await playbackSettings.StreamSeek.IfNoneAsync(TimeSpan.Zero),
finish - now);
}
var ffmpegState = new FFmpegState(
saveReports,
hwAccel,