Imports System.Text Imports StaxRip.CommandLine Imports StaxRip.UI Class AMDEncoder Inherits BasicVideoEncoder Sub New() Name = "AMD H.264" End Sub Property ParamsStore As New PrimitiveStore Public Overrides ReadOnly Property DefaultName As String Get Return "AMD " + Params.Codec.OptionText End Get End Property Private ParamsValue As EncoderParams Property Params As EncoderParams Get If ParamsValue Is Nothing Then ParamsValue = New EncoderParams ParamsValue.Init(ParamsStore) End If Return ParamsValue End Get Set(value As EncoderParams) ParamsValue = value End Set End Property Overrides Sub ShowConfigDialog() Dim params1 As New EncoderParams Dim store = DirectCast(ObjectHelp.GetCopy(ParamsStore), PrimitiveStore) params1.Init(store) Using f As New CommandLineForm(params1) Dim saveProfileAction = Sub() Dim enc = ObjectHelp.GetCopy(Of AMDEncoder)(Me) Dim params2 As New EncoderParams Dim store2 = DirectCast(ObjectHelp.GetCopy(store), PrimitiveStore) params2.Init(store2) enc.Params = params2 enc.ParamsStore = store2 SaveProfile(enc) End Sub f.cms.Items.Add(New ActionMenuItem("Check Features", Sub() g.ShowCode("Check Features", ProcessHelp.GetStdOut(Package.VCEEncC.Path, "--check-features")))) f.cms.Items.Add(New ActionMenuItem("Check VCE Support", Sub() MsgInfo(ProcessHelp.GetStdOut(Package.VCEEncC.Path, "--check-vce")))) ActionMenuItem.Add(f.cms.Items, "Save Profile...", saveProfileAction, Symbol.Save) If f.ShowDialog() = DialogResult.OK Then Params = params1 ParamsStore = store OnStateChange() End If End Using End Sub Overrides ReadOnly Property OutputExt() As String Get Return Params.Codec.ValueText End Get End Property Overrides Sub Encode() p.Script.Synchronize() Dim batchPath = p.TempDir + p.TargetFile.Base + "_VCEEncC.bat" Dim batchCode = Proc.WriteBatchFile(batchPath, Params.GetCommandLine(True, True)) Using proc As New Proc proc.Init("Encoding using VCEEncC " + Package.VCEEncC.Version) proc.SkipStrings = {"%]", " frames: "} proc.WriteLine(batchCode + BR2) proc.File = "cmd.exe" proc.Arguments = "/C call """ + batchPath + """" proc.Start() End Using AfterEncoding() End Sub Overrides Function GetMenu() As MenuList Dim r As New MenuList r.Add("Encoder Options", AddressOf ShowConfigDialog) r.Add("Container Configuration", AddressOf OpenMuxerConfigDialog) Return r End Function Overrides Property QualityMode() As Boolean Get Return Params.Mode.OptionText = "CQP" End Get Set(Value As Boolean) End Set End Property Public Overrides ReadOnly Property CommandLineParams As CommandLineParams Get Return Params End Get End Property Class EncoderParams Inherits CommandLineParams Sub New() Title = "AMD Encoding Options" End Sub Property Mode As New OptionParam With { .Name = "Mode", .Text = "Mode:", .Options = {"CBR", "VBR", "CQP"}} Property Codec As New OptionParam With { .Switch = "--codec", .Text = "Codec:", .Options = {"H.264", "H.265"}, .Values = {"h264", "hevc"}} Property Decoder As New OptionParam With { .Text = "Decoder:", .Options = {"AviSynth/VapourSynth", "VCEEncC (VCE)", "QSVEncC (Intel)", "ffmpeg (Intel)", "ffmpeg (DXVA2)"}, .Values = {"avs", "vce", "qs", "ffqsv", "ffdxva"}} Property QPI As New NumParam With { .Text = "Constant QP I:", .Value = 22, .VisibleFunc = Function() "CQP" = Mode.OptionText, .MinMaxStep = {0, 51, 1}} Property QPP As New NumParam With { .Text = "Constant QP P:", .Value = 24, .VisibleFunc = Function() "CQP" = Mode.OptionText, .MinMaxStep = {0, 51, 1}} Property QPB As New NumParam With { .Text = "Constant QP B:", .Value = 27, .VisibleFunc = Function() "CQP" = Mode.OptionText, .MinMaxStep = {0, 51, 1}} Property Custom As New StringParam With { .Text = "Custom Switches:", .ArgsFunc = Function() Custom.Value} Private ItemsValue As List(Of CommandLineParam) Overrides ReadOnly Property Items As List(Of CommandLineParam) Get If ItemsValue Is Nothing Then ItemsValue = New List(Of CommandLineParam) Add("Basic", Decoder, Mode, Codec, New OptionParam With {.Switch = "--quality", .Text = "Quality:", .Options = {"fast", "balanced", "slow"}, .InitValue = 1}, New OptionParam With {.Switch = "--profile", .Name = "profile264", .VisibleFunc = Function() Codec.ValueText = "h264", .Text = "Profile:", .Options = {"Automatic", "Baseline", "Main", "High"}}, New OptionParam With {.Switch = "--profile", .Name = "profile265", .VisibleFunc = Function() Codec.ValueText = "hevc", .Text = "Profile:", .Options = {"Main"}}, New OptionParam With {.Switch = "--tier", .Text = "Tier:", .Options = {"main", "high"}, .VisibleFunc = Function() Codec.ValueText = "hevc"}, New OptionParam With {.Switch = "--level", .Name = "LevelH264", .Text = "Level:", .VisibleFunc = Function() Codec.ValueText = "h264", .Options = {"Unrestricted", "1", "1.1", "1.2", "1.3", "2", "2.1", "2.2", "3", "3.1", "3.2", "4", "4.1", "4.2", "5", "5.1", "5.2"}}, New OptionParam With {.Switch = "--level", .Name = "LevelH265", .Text = "Level:", .VisibleFunc = Function() Codec.ValueText = "hevc", .Options = {"Unrestricted", "1", "2", "2.1", "3", "3.1", "4", "4.1", "5", "5.1", "5.2", "6", "6.1", "6.2"}}, QPI, QPP, QPB) Add("Slice Decision", New NumParam With {.Switch = "--slices", .Text = "Slices:", .InitValue = 1}, New NumParam With {.Switch = "--bframes", .Text = "B-Frames:", .MinMaxStep = {0, 16, 1}}, New NumParam With {.Switch = "--ref", .Text = "Ref Frames:", .InitValue = 2, .MinMaxStep = {0, 16, 1}}, New NumParam With {.Switch = "--gop-len", .Text = "GOP Length:", .MinMaxStep = {0, Integer.MaxValue, 1}}, New NumParam With {.Switch = "--ltr", .Text = "LTR Frames:", .MinMaxStep = {0, Integer.MaxValue, 1}}, New BoolParam With {.Switch = "--b-pyramid", .Text = "B-Pyramid"}) Add("Rate Control", New NumParam With {.Switch = "--max-bitrate", .Text = "Max Bitrate:", .InitValue = 20000, .MinMaxStep = {0, Integer.MaxValue, 1}}, New NumParam With {.Switch = "--vbv-bufsize", .Text = "VBV Bufsize:", .MinMaxStep = {0, 1000000, 1}, .InitValue = 20000}, New NumParam With {.Switch = "--qp-min", .Text = "QP Min:", .MinMaxStep = {0, 100, 1}}, New NumParam With {.Switch = "--qp-max", .Text = "QP Max:", .MinMaxStep = {0, 100, 1}, .InitValue = 100}, New NumParam With {.Switch = "--b-deltaqp", .Text = "Non-ref bframe QP offset:"}, New NumParam With {.Switch = "--bref-deltaqp", .Text = "Ref bframe QP offset:"}, New BoolParam With {.Switch = "--vbaq", .Text = "VBAQ"}) Add("Other", New StringParam With {.Switch = "--chapter", .Text = "Chapters:", .Quotes = True, .BrowseFileFilter = "*.*|*.*"}, New StringParam With {.Switch = "--log", .Text = "Log File:", .Quotes = True, .BrowseFileFilter = "*.*|*.*"}, New OptionParam With {.Switch = "--log-level", .Text = "Log Level:", .Options = {"info", "debug", "warn", "error"}}, New OptionParam With {.Switch = "--motion-est", .Text = "Motion Estimation:", .Options = {"q-pel", "full-pel", "half-pel"}}, New OptionParam With {.Switch = "--pre-analysis", .Name = "pre-analysis-h264", .Text = "Pre Analysis:", .Options = {"none", "full", "half", "quarter"}, .VisibleFunc = Function() Codec.ValueText = "h264"}, New OptionParam With {.Switch = "--pre-analysis", .Name = "pre-analysis-h265", .Text = "Pre Analysis:", .Options = {"none", "auto"}, .VisibleFunc = Function() Codec.ValueText = "hevc"}, New OptionParam With {.Switches = {"--tff", "--bff"}, .Text = "Interlaced:", .Options = {"Progressive ", "Top Field First", "Bottom Field First"}, .Values = {"", "--tff", "--bff"}}, New BoolParam With {.Switch = "--chapter-copy", .Text = "Copy Chapters"}, New BoolParam With {.Switch = "--filler", .Text = "Use filler data"}, New BoolParam With {.Switch = "--fullrange", .Text = "Set yuv to fullrange", .VisibleFunc = Function() Codec.ValueText = "h264"}, New BoolParam With {.Switch = "--enforce-hrd", .Text = "Enforce HRD compatibility"}, Custom) End If Return ItemsValue End Get End Property Private Sub Add(path As String, ParamArray items As CommandLineParam()) For Each i In items i.Path = path ItemsValue.Add(i) Next End Sub Overrides Function GetCommandLine(includePaths As Boolean, includeExecutable As Boolean, Optional pass As Integer = 1) As String Dim ret As String Dim sourcePath As String Dim targetPath = p.VideoEncoder.OutputPath.ChangeExt(p.VideoEncoder.OutputExt) If includePaths AndAlso includeExecutable Then ret = Package.VCEEncC.Path.Quotes End If Select Case Decoder.ValueText Case "avs" sourcePath = p.Script.Path Case "qs" sourcePath = "-" If includePaths Then ret = If(includePaths, Package.QSVEncC.Path.Quotes, "QSVEncC") + " -o - -c raw" + " -i " + If(includePaths, p.SourceFile.Quotes, "path") + " | " + If(includePaths, Package.VCEEncC.Path.Quotes, "VCEEncC") Case "ffdxva" sourcePath = "-" If includePaths Then ret = If(includePaths, Package.ffmpeg.Path.Quotes, "ffmpeg") + " -threads 1 -hwaccel dxva2 -i " + If(includePaths, p.SourceFile.Quotes, "path") + " -f yuv4mpegpipe -pix_fmt yuv420p -loglevel error - | " + If(includePaths, Package.VCEEncC.Path.Quotes, "VCEEncC") Case "ffqsv" sourcePath = "-" If includePaths Then ret = If(includePaths, Package.ffmpeg.Path.Quotes, "ffmpeg") + " -threads 1 -hwaccel qsv -i " + If(includePaths, p.SourceFile.Quotes, "path") + " -f yuv4mpegpipe -pix_fmt yuv420p -loglevel error - | " + If(includePaths, Package.VCEEncC.Path.Quotes, "VCEEncC") Case "vce" sourcePath = p.LastOriginalSourceFile ret += " --avvce" End Select Dim q = From i In Items Where i.GetArgs <> "" If q.Count > 0 Then ret += " " + q.Select(Function(item) item.GetArgs).Join(" ") End If Select Case Mode.OptionText Case "CBR" ret += " --cbr " & p.VideoBitrate Case "VBR" ret += " --vbr " & p.VideoBitrate Case "CQP" ret += " --cqp " & QPI.Value & ":" & QPP.Value & ":" & QPB.Value End Select If CInt(p.CropLeft Or p.CropTop Or p.CropRight Or p.CropBottom) <> 0 AndAlso (p.Script.IsFilterActive("Crop", "Hardware Encoder") OrElse (Decoder.ValueText <> "avs" AndAlso p.Script.IsFilterActive("Crop"))) Then ret += " --crop " & p.CropLeft & "," & p.CropTop & "," & p.CropRight & "," & p.CropBottom End If If p.Script.IsFilterActive("Resize", "Hardware Encoder") OrElse (Decoder.ValueText <> "avs" AndAlso p.Script.IsFilterActive("Resize")) Then ret += " --output-res " & p.TargetWidth & "x" & p.TargetHeight ElseIf p.AutoARSignaling AndAlso p.SourceFile <> "" Then Dim par = Calc.GetTargetPAR If par <> New Point(1, 1) Then ret += " --sar " & par.X & ":" & par.Y End If If sourcePath = "-" Then ret += " --y4m" If includePaths Then ret += " -i " + sourcePath.Quotes + " -o " + targetPath.Quotes Return ret.Trim End Function Public Overrides Function GetPackage() As Package Return Package.VCEEncC End Function End Class End Class