Skip to content

Commit

Permalink
Added ffmpeg native opus encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
moisespr123 committed Apr 1, 2019
1 parent ea7dd24 commit 209d35e
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 45 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/).

Expand Down
3 changes: 3 additions & 0 deletions opus_gui/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<setting name="EncFfmpeg" serializeAs="String">
<value>False</value>
</setting>
<setting name="EncFfmpeg2" serializeAs="String">
<value>False</value>
</setting>
</opus_gui.My.MySettings>
</userSettings>
</configuration>
44 changes: 29 additions & 15 deletions opus_gui/Form1.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 39 additions & 25 deletions opus_gui/Form1.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions opus_gui/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("1.9.0.0")>
<Assembly: AssemblyFileVersion("1.9.0.0")>
<Assembly: AssemblyVersion("1.10.0.0")>
<Assembly: AssemblyFileVersion("1.10.0.0")>
12 changes: 12 additions & 0 deletions opus_gui/My Project/Settings.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions opus_gui/My Project/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
<Setting Name="EncFfmpeg" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="EncFfmpeg2" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 209d35e

Please sign in to comment.