From efd6cf6d43ae618034bbdbebc7e398fe24104937 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sun, 29 Sep 2019 01:44:23 +0200 Subject: [PATCH] nvenc command line import fixes --- Changelog.md | 1 + Encoding/NVEnc.vb | 12 +++++++++--- Encoding/QSVEnc.vb | 34 +++++++++++++++++----------------- Encoding/Rav1e.vb | 2 +- Encoding/VideoEncoder.vb | 11 ++++++++--- Encoding/x264Enc.vb | 2 +- Encoding/x265Enc.vb | 8 ++++---- Forms/CommandLineForm.vb | 2 +- General/CommandLine.vb | 2 +- 9 files changed, 43 insertions(+), 31 deletions(-) diff --git a/Changelog.md b/Changelog.md index dff19746..b44fafa4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -38,6 +38,7 @@ Thanks to Patman for providing the download links of the tools !!! In the script editor there is a new 'Script Info' menu item (Ctrl+I) doing the same. - fix: docs weren't built automatically +- fix: some bugs were fixed in the nvenc command line import feature ### 2.0.4.4 Beta diff --git a/Encoding/NVEnc.vb b/Encoding/NVEnc.vb index 9344cdea..531c6c22 100644 --- a/Encoding/NVEnc.vb +++ b/Encoding/NVEnc.vb @@ -129,13 +129,19 @@ Public Class NVEnc .Switches = {"--cqp", "--cbr", "--cbrhq", "--vbr", "--vbrhq"}, .Options = {"CQP - Constant QP", "CBR - Constant Bitrate", "CBR HQ - Constant Bitrate HQ", "VBR - Variable Bitrate", "VBR HQ - Variable Bitrate HQ"}, .VisibleFunc = Function() Not Lossless.Value, - .ArgsFunc = AddressOf GetModeArgs} + .ArgsFunc = AddressOf GetModeArgs, + .ImportAction = Sub(param, arg) + If Mode.Switches.Contains(param) Then + Mode.Value = Array.IndexOf(Mode.Switches.ToArray, param) + End If + End Sub} Property Codec As New OptionParam With { .Switch = "--codec", .Text = "Codec", .Options = {"Nvidia H.264", "Nvidia H.265"}, - .Values = {"h264", "h265"}} + .Values = {"h264", "h265"}, + .ImportAction = Sub(param, arg) Codec.Value = If(arg.EqualsAny("h264", "avc"), 0, 1)} Property Profile As New OptionParam With { .Switch = "--profile", @@ -204,7 +210,7 @@ Public Class NVEnc .VisibleFunc = Function() Codec.ValueText = "h265", .Config = {0, Integer.MaxValue, 50}, .ArgsFunc = Function() If(MaxCLL.Value <> 0 OrElse MaxFALL.Value <> 0, "--max-cll """ & MaxCLL.Value & "," & MaxFALL.Value & """", ""), - .ImportAction = Sub(arg As String) + .ImportAction = Sub(param, arg) If arg = "" Then Exit Sub Dim a = arg.Trim(""""c).Split(","c) MaxCLL.Value = a(0).ToInt diff --git a/Encoding/QSVEnc.vb b/Encoding/QSVEnc.vb index 2d73bf81..5e8f2360 100644 --- a/Encoding/QSVEnc.vb +++ b/Encoding/QSVEnc.vb @@ -180,27 +180,27 @@ Public Class QSVEnc .Config = {0, 20}} Property Chromaloc As New NumParam With { - .Switch = "--chromaloc", - .Text = "Chromaloc", - .Config = {0, 5}} + .Switch = "--chromaloc", + .Text = "Chromaloc", + .Config = {0, 5}} Property VBVbufsize As New NumParam With { - .Switch = "--vbv-bufsize", - .Text = "VBV Bufsize", - .Config = {0, 1000000, 100}} + .Switch = "--vbv-bufsize", + .Text = "VBV Bufsize", + .Config = {0, 1000000, 100}} Property MaxCLL As New NumParam With { - .Text = "Maximum CLL", - .VisibleFunc = Function() Codec.ValueText = "hevc", - .Switch = "--max-cll", - .Config = {0, Integer.MaxValue, 50}, - .ImportAction = Sub(arg As String) - If arg = "" Then Exit Sub - Dim a = arg.Trim(""""c).Split(","c) - MaxCLL.Value = a(0).ToInt - MaxFALL.Value = a(1).ToInt - End Sub, - .ArgsFunc = Function() If(MaxCLL.Value <> 0 OrElse MaxFALL.Value <> 0, "--max-cll """ & MaxCLL.Value & "," & MaxFALL.Value & """", "")} + .Text = "Maximum CLL", + .VisibleFunc = Function() Codec.ValueText = "hevc", + .Switch = "--max-cll", + .Config = {0, Integer.MaxValue, 50}, + .ArgsFunc = Function() If(MaxCLL.Value <> 0 OrElse MaxFALL.Value <> 0, "--max-cll """ & MaxCLL.Value & "," & MaxFALL.Value & """", ""), + .ImportAction = Sub(param, arg) + If arg = "" Then Exit Sub + Dim a = arg.Trim(""""c).Split(","c) + MaxCLL.Value = a(0).ToInt + MaxFALL.Value = a(1).ToInt + End Sub} Property MaxFALL As New NumParam With { .Switches = {"--max-cll"}, diff --git a/Encoding/Rav1e.vb b/Encoding/Rav1e.vb index 3887b554..95819441 100644 --- a/Encoding/Rav1e.vb +++ b/Encoding/Rav1e.vb @@ -217,7 +217,7 @@ Public Class Rav1eParams .Path = "VUI", .Config = {0, Integer.MaxValue, 50}, .ArgsFunc = Function() If(Light.Value <> 0 OrElse MaxFALL.Value <> 0, "--content_light """ & Light.Value & "," & MaxFALL.Value & """", ""), - .ImportAction = Sub(arg As String) + .ImportAction = Sub(param, arg) If arg = "" Then Exit Sub Dim a = arg.Trim(""""c).Split(","c) Light.Value = a(0).ToInt diff --git a/Encoding/VideoEncoder.vb b/Encoding/VideoEncoder.vb index ac515291..59d393c5 100644 --- a/Encoding/VideoEncoder.vb +++ b/Encoding/VideoEncoder.vb @@ -427,7 +427,10 @@ Public MustInherit Class BasicVideoEncoder For Each i In {"tune", "preset", "profile"} Dim match = Regex.Match(commandLine, "(.*)(--" + i + "\s\w+)(.*)") - If match.Success Then commandLine = match.Groups(2).Value + " " + match.Groups(1).Value + " " + match.Groups(3).Value + + If match.Success Then + commandLine = match.Groups(2).Value + " " + match.Groups(1).Value + " " + match.Groups(3).Value + End If Next Dim a = commandLine.SplitNoEmptyAndWhiteSpace(" ") @@ -437,7 +440,7 @@ Public MustInherit Class BasicVideoEncoder If Not param.ImportAction Is Nothing AndAlso param.GetSwitches.Contains(a(x)) AndAlso a.Length - 1 > x Then - param.ImportAction.Invoke(a(x + 1)) + param.ImportAction.Invoke(a(x), a(x + 1)) params.RaiseValueChanged(param) Exit For End If @@ -477,7 +480,9 @@ Public MustInherit Class BasicVideoEncoder Next Else For xOpt = 0 To optionParam.Options.Length - 1 - If a(x + 1).Trim(""""c).ToLower = optionParam.Options(xOpt).ToLower.Replace(" ", "") Then + Dim values = If(optionParam.Values.NothingOrEmpty, optionParam.Options, optionParam.Values) + + If a(x + 1).Trim(""""c).ToLower = values(xOpt).ToLower.Replace(" ", "") Then optionParam.Value = xOpt params.RaiseValueChanged(param) exitFor = True diff --git a/Encoding/x264Enc.vb b/Encoding/x264Enc.vb index 0e496dc0..ae06f5fa 100644 --- a/Encoding/x264Enc.vb +++ b/Encoding/x264Enc.vb @@ -268,7 +268,7 @@ Public Class x264Params .Switch = "--deblock", .NoSwitch = "--no-deblock", .Text = "Deblocking", - .ImportAction = Sub(arg As String) + .ImportAction = Sub(param, arg) Dim a = arg.Split(":"c) DeblockA.Value = a(0).ToInt DeblockB.Value = a(1).ToInt diff --git a/Encoding/x265Enc.vb b/Encoding/x265Enc.vb index 8c3a0e73..186fa053 100644 --- a/Encoding/x265Enc.vb +++ b/Encoding/x265Enc.vb @@ -691,13 +691,13 @@ Public Class x265Params .Text = "Maximum CLL", .Switch = "--max-cll", .Config = {0, Integer.MaxValue, 50}, - .ImportAction = Sub(arg As String) + .ArgsFunc = Function() If(MaxCLL.Value <> 0 OrElse MaxFALL.Value <> 0, "--max-cll """ & MaxCLL.Value & "," & MaxFALL.Value & """", ""), + .ImportAction = Sub(param, arg) If arg = "" Then Exit Sub Dim a = arg.Trim(""""c).Split(","c) MaxCLL.Value = a(0).ToInt MaxFALL.Value = a(1).ToInt - End Sub, - .ArgsFunc = Function() If(MaxCLL.Value <> 0 OrElse MaxFALL.Value <> 0, "--max-cll """ & MaxCLL.Value & "," & MaxFALL.Value & """", "")} + End Sub} Property MaxFALL As New NumParam With { .Switches = {"--max-cll"}, @@ -755,7 +755,7 @@ Public Class x265Params Return "--no-deblock" End If End Function, - .ImportAction = Sub(arg As String) + .ImportAction = Sub(param, arg) Dim a = arg.Split(":"c) DeblockA.Value = a(0).ToInt DeblockB.Value = a(1).ToInt diff --git a/Forms/CommandLineForm.vb b/Forms/CommandLineForm.vb index 8ada4a94..abea4bcb 100644 --- a/Forms/CommandLineForm.vb +++ b/Forms/CommandLineForm.vb @@ -41,7 +41,7 @@ Public Class CommandLineForm cms.Add("Execute Command Line", Sub() params.Execute(), p.SourceFile <> "").SetImage(Symbol.fa_terminal) cms.Add("Copy Command Line", Sub() Clipboard.SetText(params.GetCommandLine(True, True))) cms.Add("Show Command Line...", Sub() g.ShowCommandLinePreview("Command Line", params.GetCommandLine(True, True))) - cms.Add("Import Command Line...", Sub() If MsgQuestion("Import command line from clipboard?") = DialogResult.OK Then BasicVideoEncoder.ImportCommandLine(Clipboard.GetText, params)) + cms.Add("Import Command Line...", Sub() If MsgQuestion("Import command line from clipboard?", Clipboard.GetText) = DialogResult.OK Then BasicVideoEncoder.ImportCommandLine(Clipboard.GetText, params)) cms.Add("Help", AddressOf ShowHelp).SetImage(Symbol.Help) cms.Add(params.GetPackage.Name + " Help", Sub() g.StartProcess(params.GetPackage.GetHelpPath)) diff --git a/General/CommandLine.vb b/General/CommandLine.vb index df14d85c..0dccbe97 100644 --- a/General/CommandLine.vb +++ b/General/CommandLine.vb @@ -94,7 +94,7 @@ Namespace CommandLine Property Text As String Property URLs As List(Of String) Property VisibleFunc As Func(Of Boolean) - Property ImportAction As Action(Of String) + Property ImportAction As Action(Of String, String) Friend Store As PrimitiveStore Friend Params As CommandLineParams