diff --git a/Component/RenderManager.cs b/Component/RenderManager.cs index a63a243..e644e64 100644 --- a/Component/RenderManager.cs +++ b/Component/RenderManager.cs @@ -246,14 +246,16 @@ namespace ADOFAIRenderer.Component { try { - var workingFps = (float)(targetFps % videoFps == 0.0 ? videoFps : targetFps); - var videoFFmpeg = new VideoFFmpeg(Configuration.RenderWidth, Configuration.RenderHeight, (int)workingFps, (int)videoFps, selectedCodec); + var quotient = targetFps / videoFps; + var isMultiple = Math.Abs(quotient - Math.Round(quotient)) < 1e-9; + var workingFps = isMultiple ? videoFps : targetFps; + var videoFFmpeg = new VideoFFmpeg(Configuration.RenderWidth, Configuration.RenderHeight, workingFps, videoFps, selectedCodec); SetupCaptureDirectory(); videoFFmpeg.Start(_currentOutPath, bitrate); - int num = targetFps % videoFps != 0.0 ? 1 : (int)(targetFps / videoFps); + var num = isMultiple ? (int)Math.Round(quotient) : 1; while (true) { diff --git a/RenderMod.cs b/RenderMod.cs index 7297d22..e247886 100644 --- a/RenderMod.cs +++ b/RenderMod.cs @@ -95,14 +95,15 @@ namespace ADOFAIRenderer // 60회 초과 시 최후의 블랙 프레임 삽입하여 전체 파이프라인 마비 방지 Melon.Logger.Error($"[Render Skipped] Frame {RenderManager.FrameCount} rendering failed after 60 retries. Supplying black frame."); - var targetFps = (int)RenderManager.Configuration.TargetFPS; - var videoFps = (int)RenderManager.Configuration.VideoFPS; - var num = targetFps % videoFps != 0 ? 1 : targetFps / videoFps; + var targetFps = RenderManager.Configuration.TargetFPS; + var videoFps = RenderManager.Configuration.VideoFPS; + var quotient = targetFps / videoFps; + var num = Math.Abs(quotient - Math.Round(quotient)) < 1e-9 ? (int)Math.Round(quotient) : 1; if (FrameCountForVideo % num == 0) { - int byteSize = RenderManager.Configuration.RenderWidth * RenderManager.Configuration.RenderHeight * 4; - byte[] blackFrame = System.Buffers.ArrayPool.Shared.Rent(byteSize); + var byteSize = RenderManager.Configuration.RenderWidth * RenderManager.Configuration.RenderHeight * 4; + var blackFrame = System.Buffers.ArrayPool.Shared.Rent(byteSize); Array.Clear(blackFrame, 0, byteSize); lock (RenderManager.ImageQueue) @@ -119,10 +120,10 @@ namespace ADOFAIRenderer RenderCheck = true; // 다음 프레임 검사용으로 초기화 RenderManager.FrameCount++; - if (realDeltaTime > 0) + /*if (realDeltaTime > 0) { Time.timeScale = (float)(Time.deltaTime / realDeltaTime); - } + }*/ } public static int FrameCountForVideo; @@ -163,7 +164,8 @@ namespace ADOFAIRenderer var targetFps = RenderManager.Configuration.TargetFPS; var videoFps = RenderManager.Configuration.VideoFPS; - var num = targetFps % videoFps != 0.0 ? 1 : (int)(targetFps / videoFps); + var quotient = targetFps / videoFps; + var num = Math.Abs(quotient - Math.Round(quotient)) < 1e-9 ? (int)Math.Round(quotient) : 1; if (currentFrame % num != 0) { diff --git a/Util/VideoFFmpeg.cs b/Util/VideoFFmpeg.cs index fc69812..f3c20d0 100644 --- a/Util/VideoFFmpeg.cs +++ b/Util/VideoFFmpeg.cs @@ -25,8 +25,8 @@ namespace ADOFAIRenderer.Util public int Width; public int Height; - public int FrameRate; - public int VideoFPS; + public double FrameRate; + public double VideoFPS; public Codec VideoCodec; private static string Codec2String(Codec c) @@ -48,7 +48,7 @@ namespace ADOFAIRenderer.Util }; } - public VideoFFmpeg(int w, int h, int frame, int videoFrame, Codec codec) + public VideoFFmpeg(int w, int h, double frame, double videoFrame, Codec codec) { Width = w; Height = h;