From dca93717a5d46b873145f1750db5ae53956d60b1 Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Tue, 9 Jun 2026 09:02:32 -0500 Subject: [PATCH] fix: improve speed of motion graphics element compositing (#2922) * fix: improve speed of motion graphics element compositing * update changelog --- CHANGELOG.md | 1 + .../Graphics/Motion/MotionElement.cs | 21 +++---------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef94c183e..f5a03d1be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Use configured ffmpeg path for motion and subtitle graphics elements - Previously, these elements required ffmpeg to be on PATH - Fix erroneous warning `Unable to locate MPEG-TS Script in folder Default` on installations with case-sensitive file systems +- Improve speed of motion graphics element compositing ## [26.5.1] - 2026-05-08 ### Fixed diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/Motion/MotionElement.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/Motion/MotionElement.cs index ce587bd5b..ac9d62a94 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/Motion/MotionElement.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/Motion/MotionElement.cs @@ -25,7 +25,6 @@ public class MotionElement( private int _frameSize; private PipeReader _pipeReader; private SKPointI _point; - private SKBitmap _canvasBitmap; private SKBitmap _motionFrameBitmap; private TimeSpan _startTime; private TimeSpan _endTime; @@ -55,7 +54,6 @@ public class MotionElement( _cancellationTokenSource?.Dispose(); - _canvasBitmap?.Dispose(); _motionFrameBitmap?.Dispose(); } @@ -119,12 +117,6 @@ public class MotionElement( _frameSize = targetSize.Width * targetSize.Height * 4; - _canvasBitmap = new SKBitmap( - context.FrameSize.Width, - context.FrameSize.Height, - SKColorType.Bgra8888, - SKAlphaType.Unpremul); - _motionFrameBitmap = new SKBitmap( targetSize.Width, targetSize.Height, @@ -235,7 +227,7 @@ public class MotionElement( { if (contentTime <= _endTime) { - return new PreparedElementImage(_canvasBitmap, SKPointI.Empty, 1.0f, ZIndex, false); + return new PreparedElementImage(_motionFrameBitmap, _point, 1.0f, ZIndex, false); } _state = MotionElementState.Finished; @@ -260,18 +252,11 @@ public class MotionElement( sequence.CopyTo(pixmap.GetPixelSpan()); } - _canvasBitmap.Erase(SKColors.Transparent); - - using (var canvas = new SKCanvas(_canvasBitmap)) - { - canvas.DrawBitmap(_motionFrameBitmap, _point); - } - // mark this frame as consumed consumed = sequence.End; // we are done, return the frame - return new PreparedElementImage(_canvasBitmap, SKPointI.Empty, 1.0f, ZIndex, false); + return new PreparedElementImage(_motionFrameBitmap, _point, 1.0f, ZIndex, false); } if (readResult.IsCompleted) @@ -281,7 +266,7 @@ public class MotionElement( if (motionElement.EndBehavior is MotionEndBehavior.Hold) { _state = MotionElementState.Holding; - return new PreparedElementImage(_canvasBitmap, SKPointI.Empty, 1.0f, ZIndex, false); + return new PreparedElementImage(_motionFrameBitmap, _point, 1.0f, ZIndex, false); } else {