Skip to content

Commit

Permalink
properly flesh out encoder API
Browse files Browse the repository at this point in the history
  • Loading branch information
jgcodes2020 committed Oct 17, 2023
1 parent 15a9fbf commit 99cfd17
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 24 deletions.
2 changes: 0 additions & 2 deletions M64RPFW.Models/Media/Helpers/AVHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public static void Dispose(ref SwrContext* swr)
/// </summary>
/// <param name="ofmt">The output format</param>
/// <param name="type">The stream type</param>
/// <param name="reason">If returning null, holds the reason why a fallback is needed</param>
/// <param name="name">A codec that </param>
/// <returns>The desired codec, or null if a fallback is required.</returns>
public static AVCodec* CheckCodec(AVOutputFormat* ofmt, AVMediaType type, string? name = null)
Expand Down Expand Up @@ -123,7 +122,6 @@ public static void Dispose(ref SwrContext* swr)
/// </summary>
/// <param name="ofmt">The output format</param>
/// <param name="type">The stream type</param>
/// <param name="reason">Returns a reason if the method fails, unless it's because there is no default codec.</param>
/// <returns>The default codec, or null if no default codec exists or is supported.</returns>
public static AVCodec* DefaultCodec(AVOutputFormat* ofmt, AVMediaType type)
{
Expand Down
8 changes: 4 additions & 4 deletions M64RPFW.ViewModels/EmulatorViewModel_Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions M64RPFW.ViewModels/Scripting/LuaEnvironment_Joypad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using M64RPFW.ViewModels.Scripting.Extensions;
using NLua;

// ReSharper disable UnusedMember.Local

namespace M64RPFW.ViewModels.Scripting;

public partial class LuaEnvironment
Expand Down
53 changes: 37 additions & 16 deletions M64RPFW.ViewModels/Scripting/LuaEnvironment_VCR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using M64RPFW.ViewModels.Scripting.Extensions;
using NLua;

// ReSharper disable UnusedMember.Local

namespace M64RPFW.ViewModels.Scripting;

public partial class LuaEnvironment
Expand Down Expand Up @@ -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")]
Expand Down
6 changes: 4 additions & 2 deletions M64RPFW.ViewModels/Scripting/LuaEnvironment_WGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using M64RPFW.ViewModels.Scripting.Extensions;
using NLua;

// ReSharper disable UnusedMember.Local

namespace M64RPFW.ViewModels.Scripting;

public partial class LuaEnvironment
Expand All @@ -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;
}

Expand Down

0 comments on commit 99cfd17

Please sign in to comment.