From bd24152a2e741c6bbe7213ec5bce1e0cdfbe81426afb868d1aaf908f2cd01bb7 Mon Sep 17 00:00:00 2001 From: copecone Date: Sun, 11 Oct 2026 16:45:18 +0900 Subject: [PATCH] Move NTSC Handling --- UI/Window/RenderConfigWindow.cs | 18 ++++++++++++++++++ Util/Audio/AudioSyncCalculator.cs | 5 ----- Util/FFmpeg/FFmpegNativeEncoder.cs | 7 +------ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/UI/Window/RenderConfigWindow.cs b/UI/Window/RenderConfigWindow.cs index 6666ef3..34c4950 100644 --- a/UI/Window/RenderConfigWindow.cs +++ b/UI/Window/RenderConfigWindow.cs @@ -840,6 +840,10 @@ internal static class RenderConfigWindow { if (_renderFpsSlider != null) target.RenderFPS = _renderFpsSlider.Value; if (_videoFPSSlider != null) target.VideoFPS = _videoFPSSlider.Value; + + target.RenderFPS = AlignNTSCFramerate(target.RenderFPS); + target.VideoFPS = AlignNTSCFramerate(target.VideoFPS); + if (_renderWidthSlider != null) target.RenderWidth = (int)Math.Round(_renderWidthSlider.Value); if (_renderHeightSlider != null) target.RenderHeight = (int)Math.Round(_renderHeightSlider.Value); if (_delayAfterEndSlider != null) target.DelayAfterEnd = _delayAfterEndSlider.Value; @@ -895,6 +899,20 @@ internal static class RenderConfigWindow target.AdvancedConfig.windPlanetColor = (_windPlanetToggle?.Value == true && _windPlanetPicker != null) ? _windPlanetPicker.Value : null; + + return; + + // ReSharper disable once InconsistentNaming + double AlignNTSCFramerate(double framerate) + { + const double tolerance = 0.001; + + if (Math.Abs(framerate - 29.97) < tolerance) framerate = 30000.0 / 1001; + else if (Math.Abs(framerate - 59.94) < tolerance) framerate = 60000.0 / 1001; + else if (Math.Abs(framerate - 23.976) < tolerance || Math.Abs(framerate - 23.98) < tolerance) framerate = 24000.0 / 1001; + + return framerate; + } } private static string CustomPresetLabel => LocalizationManager.Get("ui.render_config.preset_custom"); diff --git a/Util/Audio/AudioSyncCalculator.cs b/Util/Audio/AudioSyncCalculator.cs index 8aafc04..21e7bd4 100644 --- a/Util/Audio/AudioSyncCalculator.cs +++ b/Util/Audio/AudioSyncCalculator.cs @@ -15,11 +15,6 @@ internal class AudioSyncCalculator { _sampleRate = sampleRate; _fpsRational = RationalUtil.Double2MaxPrecisionInt(fps); - - // NTSC - if (Math.Abs(fps - 29.97) < 0.001) _fpsRational = (30000, 1001); - if (Math.Abs(fps - 59.94) < 0.001) _fpsRational = (60000, 1001); - if (Math.Abs(fps - 23.976) < 0.001 || Math.Abs(fps - 23.98) < 0.001) _fpsRational = (24000, 1001); } public void Reset() diff --git a/Util/FFmpeg/FFmpegNativeEncoder.cs b/Util/FFmpeg/FFmpegNativeEncoder.cs index 474de15..81efbbf 100644 --- a/Util/FFmpeg/FFmpegNativeEncoder.cs +++ b/Util/FFmpeg/FFmpegNativeEncoder.cs @@ -437,16 +437,11 @@ namespace ADOFAIRenderer.Util.FFmpeg // framerate: Framerate value giving hints to the encoder (reciprocal of time_base). // // RationalUtil: Converts FPS (double) into fractional form (numerator/denominator). - // e.g., 29.97 → 30000/1001 (NTSC standard) + // e.g., 60.00 -> 60/1 // // Reference: https://ffmpeg.org/doxygen/trunk/structAVCodecContext.html var fpsRational = RationalUtil.Double2MaxPrecisionInt(_settings.FPS); - // NTSC - if (Math.Abs(_settings.FPS - 29.97) < 0.001) fpsRational = (30000, 1001); - if (Math.Abs(_settings.FPS - 59.94) < 0.001) fpsRational = (60000, 1001); - if (Math.Abs(_settings.FPS - 23.976) < 0.001 || Math.Abs(_settings.FPS - 23.98) < 0.001) fpsRational = (24000, 1001); - _pCodecContext->time_base = new AVRational { num = fpsRational.Denominator, den = fpsRational.Numerator }; _pCodecContext->framerate = new AVRational