From 209d35e95d0c5098e2e4a43d8815e57fae53e4a1 Mon Sep 17 00:00:00 2001 From: moisesmcardona Date: Mon, 1 Apr 2019 09:24:31 -0400 Subject: [PATCH] Added ffmpeg native opus encoder --- README.md | 10 ++-- opus_gui/App.config | 3 ++ opus_gui/Form1.Designer.vb | 44 ++++++++++------ opus_gui/Form1.vb | 64 +++++++++++++++--------- opus_gui/My Project/AssemblyInfo.vb | 4 +- opus_gui/My Project/Settings.Designer.vb | 12 +++++ opus_gui/My Project/Settings.settings | 3 ++ 7 files changed, 95 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 60a4db4..f404e3f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,15 @@ # Opus GUI -A GUI to process music files into Opus. +A GUI to encode music files into Opus. ![v1.9 Screenshot](https://moisescardona.me/wp-content/uploads/2019/03/Opus-GUI-v1.9.png) -I wrote this software to convert my FLAC music collection to the Opus format. +It allows you to encode files to Opus using the following encoding methods: -The software comes bundled with the Opus encoder. You will need to download ffmpeg if it is not in your system. +* opusenc (libopus) +* ffmpeg - libopus +* ffmpeg - opus (native ffmpeg opus library, using CELT only) + +The software comes bundled with the Opus encoder. You will need to download ffmpeg to use it if it is not in your system. You can get updated Opus Tools builds at my site here: [https://moisescardona.me/opusenc-builds/](https://moisescardona.me/opusenc-builds/). diff --git a/opus_gui/App.config b/opus_gui/App.config index eb225cd..eb09934 100644 --- a/opus_gui/App.config +++ b/opus_gui/App.config @@ -25,6 +25,9 @@ False + + False + \ No newline at end of file diff --git a/opus_gui/Form1.Designer.vb b/opus_gui/Form1.Designer.vb index c7bff43..bd776fa 100644 --- a/opus_gui/Form1.Designer.vb +++ b/opus_gui/Form1.Designer.vb @@ -38,7 +38,8 @@ Partial Class Form1 Me.BitrateNumberBox = New System.Windows.Forms.NumericUpDown() Me.enableMultithreading = New System.Windows.Forms.CheckBox() Me.GroupBox1 = New System.Windows.Forms.GroupBox() - Me.EncFfmpeg = New System.Windows.Forms.RadioButton() + Me.EncFFmpeg2 = New System.Windows.Forms.RadioButton() + Me.EncFfmpeg1 = New System.Windows.Forms.RadioButton() Me.EncOpusenc = New System.Windows.Forms.RadioButton() Me.InputFileBtn = New System.Windows.Forms.Button() Me.ffmpegVersionLabel = New System.Windows.Forms.Label() @@ -155,9 +156,9 @@ Partial Class Form1 Me.Label6.AutoSize = True Me.Label6.Location = New System.Drawing.Point(529, 300) Me.Label6.Name = "Label6" - Me.Label6.Size = New System.Drawing.Size(28, 13) + Me.Label6.Size = New System.Drawing.Size(34, 13) Me.Label6.TabIndex = 12 - Me.Label6.Text = "v1.9" + Me.Label6.Text = "v1.10" ' 'OpusVersionLabel ' @@ -188,25 +189,37 @@ Partial Class Form1 ' 'GroupBox1 ' - Me.GroupBox1.Controls.Add(Me.EncFfmpeg) + Me.GroupBox1.Controls.Add(Me.EncFFmpeg2) + Me.GroupBox1.Controls.Add(Me.EncFfmpeg1) Me.GroupBox1.Controls.Add(Me.EncOpusenc) Me.GroupBox1.Location = New System.Drawing.Point(12, 12) Me.GroupBox1.Name = "GroupBox1" - Me.GroupBox1.Size = New System.Drawing.Size(151, 48) + Me.GroupBox1.Size = New System.Drawing.Size(271, 48) Me.GroupBox1.TabIndex = 17 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Encoder: " ' - 'EncFfmpeg + 'EncFFmpeg2 ' - Me.EncFfmpeg.AutoSize = True - Me.EncFfmpeg.Location = New System.Drawing.Point(81, 19) - Me.EncFfmpeg.Name = "EncFfmpeg" - Me.EncFfmpeg.Size = New System.Drawing.Size(57, 17) - Me.EncFfmpeg.TabIndex = 1 - Me.EncFfmpeg.TabStop = True - Me.EncFfmpeg.Text = "ffmpeg" - Me.EncFfmpeg.UseVisualStyleBackColor = True + Me.EncFFmpeg2.AutoSize = True + Me.EncFFmpeg2.Location = New System.Drawing.Point(180, 19) + Me.EncFFmpeg2.Name = "EncFFmpeg2" + Me.EncFFmpeg2.Size = New System.Drawing.Size(83, 17) + Me.EncFFmpeg2.TabIndex = 2 + Me.EncFFmpeg2.TabStop = True + Me.EncFFmpeg2.Text = "ffmpeg opus" + Me.EncFFmpeg2.UseVisualStyleBackColor = True + ' + 'EncFfmpeg1 + ' + Me.EncFfmpeg1.AutoSize = True + Me.EncFfmpeg1.Location = New System.Drawing.Point(81, 19) + Me.EncFfmpeg1.Name = "EncFfmpeg1" + Me.EncFfmpeg1.Size = New System.Drawing.Size(93, 17) + Me.EncFfmpeg1.TabIndex = 1 + Me.EncFfmpeg1.TabStop = True + Me.EncFfmpeg1.Text = "ffmpeg libopus" + Me.EncFfmpeg1.UseVisualStyleBackColor = True ' 'EncOpusenc ' @@ -289,8 +302,9 @@ End Sub Friend WithEvents BitrateNumberBox As NumericUpDown Friend WithEvents enableMultithreading As CheckBox Friend WithEvents GroupBox1 As GroupBox - Friend WithEvents EncFfmpeg As RadioButton + Friend WithEvents EncFfmpeg1 As RadioButton Friend WithEvents EncOpusenc As RadioButton Friend WithEvents InputFileBtn As Button Friend WithEvents ffmpegVersionLabel As Label + Friend WithEvents EncFFmpeg2 As RadioButton End Class diff --git a/opus_gui/Form1.vb b/opus_gui/Form1.vb index 15b41b7..be473b5 100644 --- a/opus_gui/Form1.vb +++ b/opus_gui/Form1.vb @@ -45,16 +45,16 @@ Return outputPath End Function Private Sub StartThreads() - If Not String.IsNullOrEmpty(OutputTxt.Text) Then If Not My.Computer.FileSystem.DirectoryExists(OutputTxt.Text) Then My.Computer.FileSystem.CreateDirectory(OutputTxt.Text) + If Not String.IsNullOrEmpty(OutputTxt.Text) Then If Not IO.Directory.Exists(OutputTxt.Text) Then IO.Directory.CreateDirectory(OutputTxt.Text) Dim ItemsToProcess As List(Of String) = New List(Of String) Dim ItemsToDelete As List(Of String) = New List(Of String) Dim FileAlreadyExist As List(Of String) = New List(Of String) Dim ErrorList As List(Of String) = New List(Of String) Dim IgnoreFilesWithExtensions As String = String.Empty - If My.Computer.FileSystem.FileExists("ignore.txt") Then IgnoreFilesWithExtensions = My.Computer.FileSystem.ReadAllText("ignore.txt") + If IO.File.Exists("ignore.txt") Then IgnoreFilesWithExtensions = My.Computer.FileSystem.ReadAllText("ignore.txt") If IO.Directory.Exists(InputTxt.Text) Then For Each File In IO.Directory.GetFiles(InputTxt.Text) - If (IO.Path.GetExtension(File) = ".wav" Or IO.Path.GetExtension(File) = ".flac" Or IO.Path.GetExtension(File) = ".opus" And EncOpusenc.Checked) Or EncFfmpeg.Checked Then + If (IO.Path.GetExtension(File) = ".wav" Or IO.Path.GetExtension(File) = ".flac" Or IO.Path.GetExtension(File) = ".opus" And EncOpusenc.Checked) Or EncFfmpeg1.Checked Or EncFFmpeg2.Checked Then ItemsToProcess.Add(File) ElseIf IO.Path.GetExtension(File) = ".mp3" Or IO.Path.GetExtension(File) = ".m4a" And EncOpusenc.Checked Then If Not ffmpeg_version = String.Empty Then @@ -66,7 +66,7 @@ End If Else If Not String.IsNullOrEmpty(OutputTxt.Text) Then - If Not My.Computer.FileSystem.FileExists(OutputTxt.Text + "\" + My.Computer.FileSystem.GetName(File)) Then + If Not IO.File.Exists(OutputTxt.Text + "\" + My.Computer.FileSystem.GetName(File)) Then If Not IgnoreFilesWithExtensions.Contains(IO.Path.GetExtension(File)) Then My.Computer.FileSystem.CopyFile(File, OutputTxt.Text + "\" + My.Computer.FileSystem.GetName(File)) End If End If @@ -85,9 +85,11 @@ Dim args As Array = {ItemsToProcess(Counter), GetOutputPath(OutputTxt.Text, ItemsToProcess(Counter)), My.Settings.Bitrate} If Not IO.File.Exists(args(1)) Then If EncOpusenc.Checked Then - tasks.Add(Function() Run_opus(args, "opusenc")) + tasks.Add(Function() Run_opus(args, "opusenc", "opusenc")) + ElseIf EncFfmpeg1.Checked Then + tasks.Add(Function() Run_opus(args, "ffmpeg1", "ffmpeg")) Else - tasks.Add(Function() Run_opus(args, "ffmpeg")) + tasks.Add(Function() Run_opus(args, "ffmpeg2", "ffmpeg")) End If Else FileAlreadyExist.Add(args(1)) @@ -99,9 +101,11 @@ Dim args As Array = {ItemsToProcess(Counter), GetOutputPath(OutputTxt.Text, ItemsToProcess(Counter)), My.Settings.Bitrate} If Not IO.File.Exists(args(1)) Then If EncOpusenc.Checked Then - Run_opus(args, "opusenc") - Else - Run_opus(args, "ffmpeg") + Run_opus(args, "opusenc", "opusenc") + ElseIf EncFfmpeg1.Checked Then + Run_opus(args, "ffmpeg1", "ffmpeg") + ElseIf EncFFmpeg2.Checked Then + Run_opus(args, "ffmpeg2", "ffmpeg") End If Else FileAlreadyExist.Add(args(1)) @@ -139,20 +143,21 @@ End If MsgBox(MessageToShow) End Sub - Private Function Run_opus(args As Array, encoder As String) + Private Function Run_opus(args As Array, encoder As String, encoderExe As String) Dim Input_File As String = args(0) Dim Output_File As String = args(1) Dim Bitrate As String = args(2) Dim opusProcessInfo As New ProcessStartInfo Dim opusProcess As Process - opusProcessInfo.FileName = encoder + ".exe" - If encoder = "opusenc" Then - opusProcessInfo.Arguments = "--music --bitrate " & Bitrate & " """ + Input_File + """ """ + Output_File + """" - Else - If Not String.IsNullOrEmpty(Output_File) Then + opusProcessInfo.FileName = encoderExe + ".exe" + Select Case encoder + Case "opusenc" + opusProcessInfo.Arguments = "--music --bitrate " & Bitrate & " """ + Input_File + """ """ + Output_File + """" + Case "ffmpeg1" opusProcessInfo.Arguments = "-i """ + Input_File + """ -c:a libopus -application audio -b:a " & Bitrate & "K """ + Output_File + """" - End If - End If + Case "ffmpeg2" + opusProcessInfo.Arguments = "-i """ + Input_File + """ -c:a opus -strict -2 -b:a " & Bitrate & "K """ + Output_File + """" + End Select opusProcessInfo.WorkingDirectory = IO.Path.GetDirectoryName(Input_File) opusProcessInfo.CreateNoWindow = True opusProcessInfo.RedirectStandardOutput = False @@ -178,9 +183,10 @@ Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load BitrateNumberBox.Value = My.Settings.Bitrate enableMultithreading.Checked = My.Settings.Multithreading - EncFfmpeg.Checked = My.Settings.EncFfmpeg + EncFfmpeg1.Checked = My.Settings.EncFfmpeg + EncFFmpeg2.Checked = My.Settings.EncFfmpeg2 EncOpusenc.Checked = My.Settings.EncOpusenc - If Not EncFfmpeg.Checked And Not EncOpusenc.Checked Then EncOpusenc.Checked = True + If Not EncFfmpeg1.Checked And Not EncFFmpeg2.Checked And Not EncOpusenc.Checked Then EncOpusenc.Checked = True IO.Directory.SetCurrentDirectory(IO.Path.GetDirectoryName(Process.GetCurrentProcess.MainModule.FileName)) GetOpusencVersion() GetFFmpegVersion() @@ -221,16 +227,17 @@ ffmpegProcess = Process.Start(ffmpegProcessInfo) ffmpegProcess.WaitForExit() ffmpeg_version = ffmpegProcess.StandardError.ReadLine() - ffmpegVersionLabel.Text = "ffmpeg version: " + ffmpeg_version + ffmpegVersionLabel.Text = ffmpeg_version Catch ex As Exception ffmpegVersionLabel.Text = "ffmpegenc.exe was not found." - EncFfmpeg.Enabled = False + EncFfmpeg1.Enabled = False + EncFFmpeg2.Enabled = False EncOpusenc.Checked = True End Try End Sub - Private Function OpusEncExists() As Boolean - If My.Computer.FileSystem.FileExists("opusenc.exe") Then + Private Function OpusEncExists() As Boolean 'Currently not used + If IO.File.Exists("opusenc.exe") Then Return True Else Return False @@ -259,10 +266,12 @@ Private Sub EncOpusenc_CheckedChanged(sender As Object, e As EventArgs) Handles EncOpusenc.CheckedChanged My.Settings.EncOpusenc = EncOpusenc.Checked + My.Settings.Save() End Sub - Private Sub EncFfmpeg_CheckedChanged(sender As Object, e As EventArgs) Handles EncFfmpeg.CheckedChanged - My.Settings.EncFfmpeg = EncFfmpeg.Checked + Private Sub EncFfmpeg_CheckedChanged(sender As Object, e As EventArgs) Handles EncFfmpeg1.CheckedChanged + My.Settings.EncFfmpeg = EncFfmpeg1.Checked + My.Settings.Save() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles InputFileBtn.Click @@ -287,4 +296,9 @@ Clipboard.SetText(opusenc_version) End If End Sub + + Private Sub EncFFmpeg2_CheckedChanged(sender As Object, e As EventArgs) Handles EncFFmpeg2.CheckedChanged + My.Settings.EncFfmpeg2 = EncFFmpeg2.Checked + My.Settings.Save() + End Sub End Class diff --git a/opus_gui/My Project/AssemblyInfo.vb b/opus_gui/My Project/AssemblyInfo.vb index 4fb80fb..994beb1 100644 --- a/opus_gui/My Project/AssemblyInfo.vb +++ b/opus_gui/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' by using the '*' as shown below: ' - - + + diff --git a/opus_gui/My Project/Settings.Designer.vb b/opus_gui/My Project/Settings.Designer.vb index bc38dc3..8ae5df7 100644 --- a/opus_gui/My Project/Settings.Designer.vb +++ b/opus_gui/My Project/Settings.Designer.vb @@ -101,6 +101,18 @@ Namespace My Me("EncFfmpeg") = value End Set End Property + + _ + Public Property EncFfmpeg2() As Boolean + Get + Return CType(Me("EncFfmpeg2"),Boolean) + End Get + Set + Me("EncFfmpeg2") = value + End Set + End Property End Class End Namespace diff --git a/opus_gui/My Project/Settings.settings b/opus_gui/My Project/Settings.settings index 710015d..e9632f4 100644 --- a/opus_gui/My Project/Settings.settings +++ b/opus_gui/My Project/Settings.settings @@ -14,5 +14,8 @@ False + + False + \ No newline at end of file