4 Commits
6 changed files with 65 additions and 24 deletions

No files matched your search

+4 -12
View File
@@ -364,9 +364,10 @@ internal class RenderManager : MonoBehaviour
private IEnumerator SetupPlay() private IEnumerator SetupPlay()
{ {
if (Configuration.AudioConfig.RenderAudio && Configuration.VideoConfig.Codec is Codec.VP9 or Codec.AV1 or Codec.VVC) if (Configuration.AudioConfig.RenderAudio)
{ {
if (Configuration.AudioConfig.AudioSampleRate == 44100) Configuration.AudioConfig.AudioSampleRate = 48000; if (!CodecUtil.AvailableSampleRate[CodecUtil.AudioCodecMatch[Configuration.VideoConfig.Codec]].Contains(Configuration.AudioConfig.AudioSampleRate))
Configuration.AudioConfig.AudioSampleRate = 48000; // most compatible value
} }
for (; countdown > 0; countdown--) for (; countdown > 0; countdown--)
@@ -463,7 +464,7 @@ internal class RenderManager : MonoBehaviour
try try
{ {
var effectiveVideoFps = Math.Min(videoFPS, renderFPS); var effectiveVideoFps = Math.Min(videoFPS, renderFPS);
var codecId = AudioCodecMatch[Configuration.VideoConfig.Codec]; var codecId = CodecUtil.AudioCodecMatch[Configuration.VideoConfig.Codec];
var settings = new FFmpegNativeEncoder.EncoderSettings var settings = new FFmpegNativeEncoder.EncoderSettings
{ {
Width = Configuration.RenderWidth, Width = Configuration.RenderWidth,
@@ -816,13 +817,4 @@ internal class RenderManager : MonoBehaviour
Melon<RenderMod>.Logger.Error($"OnLastUpdate callback caused error: {err}"); Melon<RenderMod>.Logger.Error($"OnLastUpdate callback caused error: {err}");
} }
} }
private static readonly Dictionary<Codec, AVCodecID> AudioCodecMatch = new()
{
[Codec.H264] = AVCodecID.AV_CODEC_ID_AAC,
[Codec.H265] = AVCodecID.AV_CODEC_ID_AAC,
[Codec.VP9] = AVCodecID.AV_CODEC_ID_OPUS,
[Codec.AV1] = AVCodecID.AV_CODEC_ID_OPUS,
[Codec.VVC] = AVCodecID.AV_CODEC_ID_OPUS
};
} }
+2 -2
View File
@@ -57,8 +57,8 @@ public class AudioEncodingConfig
public int AudioSampleRate public int AudioSampleRate
{ {
get => _audioSampleRate <= 0 ? 44100 : _audioSampleRate; get => _audioSampleRate <= 0 ? 48000 : _audioSampleRate;
set => _audioSampleRate = value <= 0 ? 44100 : value; set => _audioSampleRate = value <= 0 ? 48000 : value;
} }
public int AudioChannels public int AudioChannels
+2 -2
View File
@@ -21,9 +21,9 @@ public static class PlanetRendererPatch
return; return;
void ApplyColor(ref PlanetColor planetColor, scrPlanet targetPlanet, Color? customColor) void ApplyColor(ref PlanetColor planetColor, scrPlanet? targetPlanet, Color? customColor)
{ {
if (__instance == targetPlanet.planetRenderer && customColor != null) if (targetPlanet != null && __instance == targetPlanet.planetRenderer && customColor != null)
planetColor = new PlanetColor(customColor.Value); planetColor = new PlanetColor(customColor.Value);
} }
} }
+34 -5
View File
@@ -102,6 +102,20 @@ internal static class RenderConfigWindow
double[] audioBitrateSnap = { 64, 96, 128, 192, 256, 320, 384 }; double[] audioBitrateSnap = { 64, 96, 128, 192, 256, 320, 384 };
double[] renderWidthSnap = {
256, 426, 640, 854, 960, 1280, 1366, 1600, 1920, 2048, 2560, 3200, 3840, 4096, 5120, 5760, 6016, 7680, 10240, 15360, // 16:9
230, 384, 576, 768, 1152, 1440, 1680, 2880, 3072, // 16:10
192, 320, 480, 800, 1024, 1400, 2732, 6400, 11520 // 4:3
};
double[] renderHeightSnap = {
144, 240, 360, 480, 540, 720, 768, 900, 1080, 1152, 1440, 1800, 2160, 2304, 2880, 3240, 3384, 4320, 5760, 8640, // 16:9
400, 600, 800, 1050, 1200, 1600, 1920, 2400, 3200, 4800, 9600, // 16:10
864, 960, 1536, 2048, 3072 // 4:3
};
// TODO: Presets
// 1-3. Top section: 좌/우 컨테이너 1개씩으로 3행을 쌓는다 (중앙선 1개) // 1-3. Top section: 좌/우 컨테이너 1개씩으로 3행을 쌓는다 (중앙선 1개)
var (topLeft, topRight) = CreateTwoColumnPanel(scrollContent, spacing: 8f, columnSpacing: 10f); var (topLeft, topRight) = CreateTwoColumnPanel(scrollContent, spacing: 8f, columnSpacing: 10f);
@@ -132,7 +146,7 @@ internal static class RenderConfigWindow
defaultValue: 2560, min: 0, max: 15360, value: 2560, defaultValue: 2560, min: 0, max: 15360, value: 2560,
format: "F0", clampMode: ClampMode.All, format: "F0", clampMode: ClampMode.All,
sliderFilter: value => Math.Max(value, 2), inputFilter: value => Math.Max(value, 2), sliderFilter: value => renderWidthSnap.OrderBy(n => Math.Abs(n - value)).First(), inputFilter: value => Math.Max(value, 2),
onComplete: null, onChanged: val => { config.RenderWidth = (int)Math.Round(val); }, onComplete: null, onChanged: val => { config.RenderWidth = (int)Math.Round(val); },
text: LocalizationManager.Get("ui.render_config.render_width"), text: LocalizationManager.Get("ui.render_config.render_width"),
id: "slider_render_width", showFill: true id: "slider_render_width", showFill: true
@@ -143,7 +157,7 @@ internal static class RenderConfigWindow
defaultValue: 1440, min: 0, max: 8640, value: 1440, defaultValue: 1440, min: 0, max: 8640, value: 1440,
format: "F0", clampMode: ClampMode.All, format: "F0", clampMode: ClampMode.All,
sliderFilter: value => Math.Max(value, 2), inputFilter: value => Math.Max(value, 2), sliderFilter: value => renderHeightSnap.OrderBy(n => Math.Abs(n - value)).First(), inputFilter: value => Math.Max(value, 2),
onComplete: null, onChanged: val => { config.RenderWidth = (int)Math.Round(val); }, onComplete: null, onChanged: val => { config.RenderWidth = (int)Math.Round(val); },
text: LocalizationManager.Get("ui.render_config.render_height"), text: LocalizationManager.Get("ui.render_config.render_height"),
id: "slider_render_height", showFill: true id: "slider_render_height", showFill: true
@@ -188,8 +202,12 @@ internal static class RenderConfigWindow
Codec.H264, config.VideoConfig.Codec, Codec.H264, config.VideoConfig.Codec,
codecs, c => c.ToString(), codecs, c => c.ToString(),
"dd_video_codec", "dd_video_codec",
c => config.VideoConfig.Codec = c c =>
); {
config.VideoConfig.Codec = c;
UpdateVideoCodec(c);
});
_bitrateInput = CreateInputField( _bitrateInput = CreateInputField(
ctx, CreateFieldSlot(videoLeft), ctx, CreateFieldSlot(videoLeft),
LocalizationManager.Get("ui.render_config.bitrate"), LocalizationManager.Get("ui.render_config.bitrate"),
@@ -198,6 +216,7 @@ internal static class RenderConfigWindow
TMPro.TMP_InputField.CharacterValidation.Integer, TMPro.TMP_InputField.CharacterValidation.Integer,
val => { if (int.TryParse(val, out var b) && b > 0) config.VideoConfig.Bitrate = b; } val => { if (int.TryParse(val, out var b) && b > 0) config.VideoConfig.Bitrate = b; }
); );
_qpInput = CreateInputField( _qpInput = CreateInputField(
ctx, CreateFieldSlot(videoLeft), ctx, CreateFieldSlot(videoLeft),
LocalizationManager.Get("ui.render_config.qp"), LocalizationManager.Get("ui.render_config.qp"),
@@ -216,6 +235,7 @@ internal static class RenderConfigWindow
"dd_rate_control", "dd_rate_control",
m => config.VideoConfig.RateControlMode = m m => config.VideoConfig.RateControlMode = m
); );
_maxBitrateInput = CreateInputField( _maxBitrateInput = CreateInputField(
ctx, CreateFieldSlot(videoRight), ctx, CreateFieldSlot(videoRight),
LocalizationManager.Get("ui.render_config.max_bitrate"), LocalizationManager.Get("ui.render_config.max_bitrate"),
@@ -227,7 +247,7 @@ internal static class RenderConfigWindow
_forceSoftwareToggle = CreateToggleField( _forceSoftwareToggle = CreateToggleField(
ctx, CreateFieldSlot(videoRight), "", ctx, CreateFieldSlot(videoRight), "",
true, config.VideoConfig.ForceSoftwareEncoder, false, config.VideoConfig.ForceSoftwareEncoder,
LocalizationManager.Get("ui.render_config.force_software"), LocalizationManager.Get("ui.render_config.force_software"),
"toggle_force_software", "toggle_force_software",
val => config.AudioConfig.RenderAudio = val, val => config.AudioConfig.RenderAudio = val,
@@ -384,6 +404,7 @@ internal static class RenderConfigWindow
"dd_adv_file_extension", "dd_adv_file_extension",
e => { if (!string.IsNullOrEmpty(e)) config.AdvancedConfig.FileExtension = e; } e => { if (!string.IsNullOrEmpty(e)) config.AdvancedConfig.FileExtension = e; }
); );
_processAudioToggle = CreateToggleField( _processAudioToggle = CreateToggleField(
ctx, CreateFieldSlot(advLeft), "", ctx, CreateFieldSlot(advLeft), "",
true, config.AdvancedConfig.ProcessAudio, true, config.AdvancedConfig.ProcessAudio,
@@ -405,6 +426,7 @@ internal static class RenderConfigWindow
else if (string.IsNullOrWhiteSpace(val)) config.AdvancedConfig.RandomSeed = null; else if (string.IsNullOrWhiteSpace(val)) config.AdvancedConfig.RandomSeed = null;
} }
); );
_nonTileToggle = CreateToggleField( _nonTileToggle = CreateToggleField(
ctx, CreateFieldSlot(advRight), "", ctx, CreateFieldSlot(advRight), "",
false, config.AdvancedConfig.NonTile, false, config.AdvancedConfig.NonTile,
@@ -422,6 +444,13 @@ internal static class RenderConfigWindow
"btn_go_render", "btn_go_render",
height: 48f height: 48f
); );
return;
void UpdateVideoCodec(Codec codec)
{
_sampleRateDropdown?.SetValues(CodecUtil.AvailableSampleRate[CodecUtil.AudioCodecMatch[codec]]);
}
} }
private static void EnsureDefaultConfig(RenderConfig config) private static void EnsureDefaultConfig(RenderConfig config)
+21 -1
View File
@@ -1,4 +1,6 @@
using System.Diagnostics.CodeAnalysis; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using FFmpeg.AutoGen;
namespace ADOFAIRenderer.Util.FFmpeg namespace ADOFAIRenderer.Util.FFmpeg
{ {
@@ -7,4 +9,22 @@ namespace ADOFAIRenderer.Util.FFmpeg
{ {
H264, H265, VP9, AV1, VVC H264, H265, VP9, AV1, VVC
} }
internal static class CodecUtil
{
public static readonly Dictionary<Codec, AVCodecID> AudioCodecMatch = new()
{
[Codec.H264] = AVCodecID.AV_CODEC_ID_AAC,
[Codec.H265] = AVCodecID.AV_CODEC_ID_AAC,
[Codec.VP9] = AVCodecID.AV_CODEC_ID_OPUS,
[Codec.AV1] = AVCodecID.AV_CODEC_ID_OPUS,
[Codec.VVC] = AVCodecID.AV_CODEC_ID_OPUS
};
public static readonly Dictionary<AVCodecID, List<int>> AvailableSampleRate = new()
{
[AVCodecID.AV_CODEC_ID_AAC] = new List<int> { 44100, 48000, 96000 },
[AVCodecID.AV_CODEC_ID_OPUS] = new List<int> { 48000, 96000 }
};
}
} }
+2 -2
View File
@@ -1536,9 +1536,9 @@ namespace ADOFAIRenderer.Util.FFmpeg
if (_pAudioCodecContext == null) if (_pAudioCodecContext == null)
throw new Exception("Failed to allocate audio codec context."); throw new Exception("Failed to allocate audio codec context.");
var sampleRate = audioSettings.SampleRate > 0 ? audioSettings.SampleRate : 44100; var sampleRate = audioSettings.SampleRate > 0 ? audioSettings.SampleRate : 48000;
var channels = audioSettings.Channels > 0 ? audioSettings.Channels : 2; var channels = audioSettings.Channels > 0 ? audioSettings.Channels : 2;
var bitrate = audioSettings.Bitrate > 0 ? audioSettings.Bitrate : 128000; var bitrate = audioSettings.Bitrate > 0 ? audioSettings.Bitrate : 256000;
// Select the first sample format supported by the encoder. // Select the first sample format supported by the encoder.
// Most encoders prefer AV_SAMPLE_FMT_FLTP (float planar). // Most encoders prefer AV_SAMPLE_FMT_FLTP (float planar).