From 311b09cc6363d28efff98c69e1bb686f1cfb32d6 Mon Sep 17 00:00:00 2001 From: ww-rm Date: Thu, 24 Jul 2025 17:58:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Spine/Exporters/CustomFFmpegExporter.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Spine/Exporters/CustomFFmpegExporter.cs b/Spine/Exporters/CustomFFmpegExporter.cs index 174a70b..b1c5507 100644 --- a/Spine/Exporters/CustomFFmpegExporter.cs +++ b/Spine/Exporters/CustomFFmpegExporter.cs @@ -1,5 +1,6 @@ using FFMpegCore; using FFMpegCore.Pipes; +using SFML.Graphics; using SFML.System; using System; using System.Collections.Generic; @@ -63,6 +64,22 @@ namespace Spine.Exporters else options.WithCustomArgument("-vf unpremultiply=inplace=1"); } + /// + /// 获取的一帧, 结果是预乘的 + /// + protected override SFMLImageVideoFrame GetFrame(SpineObject[] spines) + { + // BUG: 也许和 SFML 多线程或者 FFmpeg 调用有关, 当渲染线程也在运行的时候此处并行渲染会导致和 SFML 有关的内容都卡死 + // 不知道为什么用 FFmpeg 必须临时创建 RenderTexture, 否则无法正常渲染, 会导致画面帧丢失 + using var tex = new RenderTexture(_renderTexture.Size.X, _renderTexture.Size.Y); + using var view = _renderTexture.GetView(); + tex.SetView(view); + tex.Clear(_backgroundColorPma); + foreach (var sp in spines.Reverse()) tex.Draw(sp); + tex.Display(); + return new(tex.Texture.CopyToImage()); + } + public override void Export(string output, CancellationToken ct, params SpineObject[] spines) { var videoFramesSource = new RawVideoPipeSource(GetFrames(spines, output, ct)) { FrameRate = _fps };