From 99cfd17ad2ce79a9e88fdad196ea2654155f27c6 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Mon, 16 Oct 2023 22:44:40 -0400 Subject: [PATCH] properly flesh out encoder API --- M64RPFW.Models/Media/Helpers/AVHelpers.cs | 2 - .../EmulatorViewModel_Commands.cs | 8 +-- .../Scripting/LuaEnvironment_Joypad.cs | 2 + .../Scripting/LuaEnvironment_VCR.cs | 53 +++++++++++++------ .../Scripting/LuaEnvironment_WGui.cs | 6 ++- 5 files changed, 47 insertions(+), 24 deletions(-) diff --git a/M64RPFW.Models/Media/Helpers/AVHelpers.cs b/M64RPFW.Models/Media/Helpers/AVHelpers.cs index 80c2664..0cce075 100644 --- a/M64RPFW.Models/Media/Helpers/AVHelpers.cs +++ b/M64RPFW.Models/Media/Helpers/AVHelpers.cs @@ -93,7 +93,6 @@ public static void Dispose(ref SwrContext* swr) /// /// The output format /// The stream type - /// If returning null, holds the reason why a fallback is needed /// A codec that /// The desired codec, or null if a fallback is required. public static AVCodec* CheckCodec(AVOutputFormat* ofmt, AVMediaType type, string? name = null) @@ -123,7 +122,6 @@ public static void Dispose(ref SwrContext* swr) /// /// The output format /// The stream type - /// Returns a reason if the method fails, unless it's because there is no default codec. /// The default codec, or null if no default codec exists or is supported. public static AVCodec* DefaultCodec(AVOutputFormat* ofmt, AVMediaType type) { diff --git a/M64RPFW.ViewModels/EmulatorViewModel_Commands.cs b/M64RPFW.ViewModels/EmulatorViewModel_Commands.cs index c454236..ab7da9c 100644 --- a/M64RPFW.ViewModels/EmulatorViewModel_Commands.cs +++ b/M64RPFW.ViewModels/EmulatorViewModel_Commands.cs @@ -298,14 +298,14 @@ private async void StartEncoder() FFmpegConfig config = new FFmpegConfig(); config.VideoOptions.Add("video_size", $"{result.EncodeSize ?? _frameCaptureService.GetWindowSize()}"); - await StartEncoderWithFile((result.Path, config)); + await StartEncoderWithFile((result.Path, null, config)); } [RelayCommand(CanExecute = nameof(EncoderIsInactive))] - private async Task StartEncoderWithFile((string, FFmpegConfig?) args) + private async Task StartEncoderWithFile((string path, string? mimeType, FFmpegConfig? config) args) { - string path = args.Item1; - FFmpegConfig config = args.Item2; + string path = args.path; + FFmpegConfig? config = args.config; Mupen64Plus.Log(LogSources.App, MessageLevel.Info, "Creating encoder..."); try { diff --git a/M64RPFW.ViewModels/Scripting/LuaEnvironment_Joypad.cs b/M64RPFW.ViewModels/Scripting/LuaEnvironment_Joypad.cs index a266509..68336d7 100644 --- a/M64RPFW.ViewModels/Scripting/LuaEnvironment_Joypad.cs +++ b/M64RPFW.ViewModels/Scripting/LuaEnvironment_Joypad.cs @@ -4,6 +4,8 @@ using M64RPFW.ViewModels.Scripting.Extensions; using NLua; +// ReSharper disable UnusedMember.Local + namespace M64RPFW.ViewModels.Scripting; public partial class LuaEnvironment diff --git a/M64RPFW.ViewModels/Scripting/LuaEnvironment_VCR.cs b/M64RPFW.ViewModels/Scripting/LuaEnvironment_VCR.cs index 7d541ce..72f7d9d 100644 --- a/M64RPFW.ViewModels/Scripting/LuaEnvironment_VCR.cs +++ b/M64RPFW.ViewModels/Scripting/LuaEnvironment_VCR.cs @@ -3,6 +3,8 @@ using M64RPFW.ViewModels.Scripting.Extensions; using NLua; +// ReSharper disable UnusedMember.Local + namespace M64RPFW.ViewModels.Scripting; public partial class LuaEnvironment @@ -30,29 +32,48 @@ private void Movie_StopMovie() } [LibFunction("ffmpeg.start_encode")] - private void FFmpeg_StartEncode(string path, string mimeType, LuaTable config) + private void FFmpeg_StartEncode(string path, string? mimeType, LuaTable? config) { if (EmulatorViewModel.Instance == null) return; var emu = EmulatorViewModel.Instance; - FFmpegConfig ffConfig = new(); - - _lua.IterateStringDict((LuaTable) config["format"], (key, value) => - { - ffConfig.FormatOptions[key] = value; - }); - _lua.IterateStringDict((LuaTable) config["audio"], (key, value) => + FFmpegConfig? ffConfig = null; + if (config != null) { - ffConfig.AudioOptions[key] = value; - }); - _lua.IterateStringDict((LuaTable) config["video"], (key, value) => - { - ffConfig.VideoOptions[key] = value; - }); - + ffConfig = new FFmpegConfig(); + if (config["format"] is LuaTable formatTable) + { + _lua.IterateStringDict(formatTable, (key, value) => + { + ffConfig.FormatOptions[key] = value; + }); + } + if (config["audio"] is LuaTable audioTable) + { + _lua.IterateStringDict(audioTable, (key, value) => + { + ffConfig.AudioOptions[key] = value; + }); + } + if (config["video"] is LuaTable videoTable) + { + _lua.IterateStringDict(videoTable, (key, value) => + { + ffConfig.VideoOptions[key] = value; + }); + } + if (config["audio_codec"] is string audioCodec) + { + ffConfig.AudioCodec = audioCodec; + } + if (config["video_codec"] is string videoCodec) + { + ffConfig.VideoCodec = videoCodec; + } + } - emu.StartEncoderCommand.ExecuteIfPossible(); + emu.StartEncoderWithFileCommand.ExecuteIfPossible((path, mimeType, ffConfig)); } [LibFunction("ffmpeg.stop_encode")] diff --git a/M64RPFW.ViewModels/Scripting/LuaEnvironment_WGui.cs b/M64RPFW.ViewModels/Scripting/LuaEnvironment_WGui.cs index 055a911..37d7e6f 100644 --- a/M64RPFW.ViewModels/Scripting/LuaEnvironment_WGui.cs +++ b/M64RPFW.ViewModels/Scripting/LuaEnvironment_WGui.cs @@ -2,6 +2,8 @@ using M64RPFW.ViewModels.Scripting.Extensions; using NLua; +// ReSharper disable UnusedMember.Local + namespace M64RPFW.ViewModels.Scripting; public partial class LuaEnvironment @@ -11,8 +13,8 @@ private LuaTable GetWindowSize() { var table = _lua.NewUnnamedTable(); var winSize = _luaInterfaceService.GetWindowSize(); - table["width"] = (int) winSize.Width; - table["height"] = (int) winSize.Height; + table["width"] = winSize.Width; + table["height"] = winSize.Height; return table; }