fixing issues with audio output filename

This commit is contained in:
Frank Skare
2020-12-15 09:26:21 +01:00
parent 7c07e9a574
commit ac2235e340
8 changed files with 133 additions and 47 deletions
+1 -1
View File
@@ -733,7 +733,7 @@ Public Class NullEncoder
If Not p.VideoEncoder.Muxer.IsSupported(sourceFile.Ext) Then
Select Case sourceFile.Ext
Case "mkv"
mkvDemuxer.Demux(sourceFile, Nothing, Nothing, Nothing, p, False, True, True)
mkvDemuxer.Demux(sourceFile, Nothing, Nothing, Nothing, p, False, True, True, "Demux Video MKV", True)
End Select
End If
End Sub
-1
View File
@@ -366,7 +366,6 @@ Friend Class JobsForm
End If
Documentation.ShowTip(Tip)
g.StopAfterCurrentJob = False
Close()
If g.IsJobProcessing Then
+1 -1
View File
@@ -2855,7 +2855,7 @@ Public Class MainForm
End If
End If
For Each ap In g.GetAudioProfiles
For Each ap In AudioProfile.GetProfiles
If ap.File = p.TargetFile Then
If ProcessTip("The audio source and target filepath is identical.") Then
g.Highlight(True, tbTargetFile)
+20 -8
View File
@@ -13,7 +13,7 @@ Public Class Audio
End If
If ap.File <> p.SourceFile Then
Log.Write("Media Info Audio Source " & ap.GetTrackID, MediaInfo.GetSummary(ap.File))
Log.Write("Media Info Audio Source " & (ap.GetTrackIndex + 1), MediaInfo.GetSummary(ap.File))
End If
If TypeOf ap Is GUIAudioProfile Then
@@ -46,7 +46,7 @@ Public Class Audio
Select Case ap.File.ExtFull
Case ".mkv", ".webm"
mkvDemuxer.Demux(ap.File, {ap.Stream}, Nothing, ap, p, False, False, True)
mkvDemuxer.Demux(ap.File, {ap.Stream}, Nothing, ap, p, False, False, True, "Demux MKV", True)
Case ".mp4"
MP4BoxDemuxer.DemuxAudio(ap.File, ap.Stream, ap, p, True)
Case Else
@@ -303,7 +303,7 @@ Public Class Audio
args += " -simple -progressnumbers"
Using proc As New Proc
proc.Header = "Convert " + ap.File.Ext.ToUpper + " to " + outPath.Ext.ToUpper + " " & ap.GetTrackID
proc.Header = "Convert " + ap.File.Ext.ToUpper + " to " + outPath.Ext.ToUpper + " " & ap.GetTrackIndex
proc.Package = Package.eac3to
proc.Arguments = args
proc.TrimChars = {"-"c, " "c}
@@ -332,7 +332,13 @@ Public Class Audio
gap.Params.Normalize = False
End If
Dim outPath = (p.TempDir + ap.File.Base + "." + ap.ConvertExt).LongPathPrefix
Dim base = ap.File.Base
If Not base.Contains(ap.GetTrackID) Then
base += ap.GetTrackID
End If
Dim outPath = (p.TempDir + base + "." + ap.ConvertExt).LongPathPrefix
If ap.File = outPath Then
outPath += "." + ap.ConvertExt
@@ -365,7 +371,7 @@ Public Class Audio
args += " " + outPath.Escape
Using proc As New Proc
proc.Header = "Convert " + ap.File.Ext.ToUpper + " to " + outPath.Ext.ToUpper + " " & ap.GetTrackID
proc.Header = "Convert " + ap.File.Ext.ToUpper + " to " + outPath.Ext.ToUpper + " " & ap.GetTrackIndex
proc.SkipStrings = {"frame=", "size="}
proc.Encoding = Encoding.UTF8
proc.Package = Package.ffmpeg
@@ -602,7 +608,13 @@ Public Class Audio
Throw New AbortException
End If
Dim aviPath = p.TempDir + ap.File.Base + "_cut_mm.avi"
Dim base = ap.File.Base
If Not base.Contains(ap.GetTrackID) Then
base += ap.GetTrackID
End If
Dim aviPath = p.TempDir + base + "_cut_.avi"
Dim d = (p.CutFrameCount / p.CutFrameRate).ToString("f9", CultureInfo.InvariantCulture)
Dim r = p.CutFrameRate.ToString("f9", CultureInfo.InvariantCulture)
Dim args = $"-f lavfi -i color=c=black:s=16x16:d={d}:r={r} -y -hide_banner -c:v copy " + aviPath.Escape
@@ -623,7 +635,7 @@ Public Class Audio
Log.WriteLine(MediaInfo.GetSummary(aviPath))
End If
Dim mkvPath = p.TempDir + ap.File.Base + "_cut_.mkv"
Dim mkvPath = p.TempDir + base + "_cut_.mkv"
Dim args2 = "-o " + mkvPath.Escape + " " + aviPath.Escape + " " + ap.File.Escape
args2 += " --split parts-frames:" + p.Ranges.Select(Function(v) v.Start & "-" & (v.End + 1)).Join(",+")
@@ -646,7 +658,7 @@ Public Class Audio
Dim streams = MediaInfo.GetAudioStreams(mkvPath)
If streams.Count > 0 Then
mkvDemuxer.Demux(mkvPath, {streams(0)}, Nothing, ap, p, False, False, True)
mkvDemuxer.Demux(mkvPath, {streams(0)}, Nothing, ap, p, False, False, True, "Demux cutted MKV", False)
Else
fail = True
End If
+32 -14
View File
@@ -268,21 +268,27 @@ Public MustInherit Class AudioProfile
Overridable Function HandlesDelay() As Boolean
End Function
Function GetTrackID() As Integer
If Me Is p.Audio0 Then Return 1
If Me Is p.Audio1 Then Return 2
Function GetTrackIndex() As Integer
If Me Is p.Audio0 Then Return 0
If Me Is p.Audio1 Then Return 1
For x = 0 To p.AudioTracks.Count - 1
If Me Is p.AudioTracks(x) Then
Return x + 3
Return x + 2
End If
Next
End Function
Function GetTrackID() As String
Return "_" & (CRC32.GetChecksum(p.TargetFile) + GetTrackIndex())
End Function
Function GetOutputFile() As String
Dim base As String
If p.TempDir.EndsWithEx("_temp\") AndAlso File.Base.StartsWithEx(p.SourceFile.Base) Then
If HasStream Then
base = Audio.GetBaseNameForStream(File, Stream)
ElseIf p.TempDir.EndsWithEx("_temp\") AndAlso File.Base.StartsWithEx(p.SourceFile.Base) Then
base = File.Base.Substring(p.SourceFile.Base.Length).Trim
Else
base = File.Base
@@ -292,6 +298,10 @@ Public MustInherit Class AudioProfile
base = "temp"
End If
If Not base.Contains(GetTrackID) Then
base += GetTrackID()
End If
If Delay <> 0 Then
If HandlesDelay() Then
If base.Contains("ms") Then
@@ -308,17 +318,25 @@ Public MustInherit Class AudioProfile
End If
End If
Dim tracks = g.GetAudioProfiles.Where(Function(track) track.File <> "")
Dim trackID = If(tracks.Count > 1, "_a" & GetTrackID(), "")
Dim outfile = p.TempDir + base + trackID & "." + OutputFileType.ToLower
Dim outfile = p.TempDir + base + "." + OutputFileType.ToLower
If outfile.FileExists Then
Return p.TempDir + base + trackID & "_new." + OutputFileType.ToLower
If File = outfile Then
outfile = outfile.Base + "_new." + OutputFileType.ToLower
End If
Return outfile
End Function
Shared Function GetProfiles() As List(Of AudioProfile)
Dim ret As New List(Of AudioProfile)
ret.Add(p.Audio0)
ret.Add(p.Audio1)
ret.AddRange(p.AudioTracks)
Return ret
End Function
Function ExpandMacros(value As String) As String
Return ExpandMacros(value, True)
End Function
@@ -727,7 +745,7 @@ Public Class GUIAudioProfile
Dim cl = GetCommandLine(True)
Using proc As New Proc
proc.Header = "Audio Encoding " & GetTrackID()
proc.Header = "Audio Encoding " & GetTrackIndex()
If cl.Contains("|") Then
proc.File = "cmd.exe"
@@ -807,7 +825,7 @@ Public Class GUIAudioProfile
args += " -f null NUL"
Using proc As New Proc
proc.Header = "Find Gain " & GetTrackID()
proc.Header = "Find Gain " & GetTrackIndex()
proc.SkipStrings = {"frame=", "size="}
proc.Encoding = Encoding.UTF8
proc.Package = Package.ffmpeg
@@ -1247,7 +1265,7 @@ Public Class GUIAudioProfile
End If
End If
If Params.ChannelsMode <> ChannelsMode.Original Then
If Params.ChannelsMode <> ChannelsMode.Original OrElse Params.Codec = AudioCodec.Opus Then
sb.Append(" -ac " & Channels)
End If
@@ -1360,7 +1378,7 @@ Public Class GUIAudioProfile
Return GuiAudioEncoder.ffmpeg
End Function
Function GetCommandLine(includePaths As Boolean) As String
Function GetCommandLine(includePaths As Boolean, Optional useCrcSuffix As Boolean = False) As String
Select Case GetEncoder()
Case GuiAudioEncoder.eac3to
Return GetEac3toCommandLine(includePaths)
+14 -4
View File
@@ -729,7 +729,7 @@ Public Class mkvDemuxer
End If
End If
Demux(proj.SourceFile, audioStreams, subtitles, Nothing, proj, True, VideoDemuxed, OverrideExisting)
Demux(proj.SourceFile, audioStreams, subtitles, Nothing, proj, True, VideoDemuxed, OverrideExisting, "Demux MKV", True)
If demuxChapters AndAlso stdout.Contains("Chapters: ") Then
Using proc As New Proc
@@ -812,7 +812,9 @@ Public Class mkvDemuxer
proj As Project,
onlyEnabled As Boolean,
videoDemuxing As Boolean,
overrideExisting As Boolean)
overrideExisting As Boolean,
title As String,
useStreamName As Boolean)
If audioStreams Is Nothing Then
audioStreams = New List(Of AudioStream)
@@ -879,7 +881,15 @@ Public Class mkvDemuxer
ext = "aac"
End If
Dim outPath = proj.TempDir + Audio.GetBaseNameForStream(sourcefile, stream) + "." + ext
Dim base As String
If useStreamName Then
base = Audio.GetBaseNameForStream(sourcefile, stream)
Else
base = sourcefile.Base
End If
Dim outPath = proj.TempDir + base + "." + ext
audioOutPaths.Add(outPath, stream)
outPaths.Add(outPath)
args += " " & stream.StreamOrder & ":" + outPath.Escape
@@ -899,7 +909,7 @@ Public Class mkvDemuxer
Using proc As New Proc
proc.Project = proj
proc.Header = "Demux MKV"
proc.Header = title
proc.SkipString = "Progress: "
proc.Encoding = Encoding.UTF8
proc.Package = Package.mkvextract
+38
View File
@@ -1487,3 +1487,41 @@ Public Class PowerRequest
Public SimpleReasonString As String
End Structure
End Class
Public Class CRC32
Shared Table As UInteger() = New UInteger(255) {}
Shared Sub New()
Dim poly = &HEDB88320UI
Dim temp As UInteger
For i = 0 To Table.Length - 1
temp = CUInt(i)
For j = 8 To 1 Step -1
If (temp And 1) = 1 Then
temp = (temp >> 1) Xor poly
Else
temp >>= 1
End If
Next
Table(i) = temp
Next
End Sub
Shared Function GetChecksum(bytes As Byte()) As UInteger
Dim crc = &HFFFFFFFFUI
For i = 0 To bytes.Length - 1
Dim index = CByte((crc And &HFF) Xor bytes(i))
crc = (crc >> 8) Xor Table(index)
Next
Return Not crc
End Function
Shared Function GetChecksum(str As String) As UInteger
Return GetChecksum(Encoding.Unicode.GetBytes(str))
End Function
End Class
+27 -18
View File
@@ -3,7 +3,6 @@ Imports System.Collections.ObjectModel
Imports System.Drawing.Imaging
Imports System.Globalization
Imports System.Management.Automation
Imports System.Reflection
Imports System.Runtime.ExceptionServices
Imports System.Runtime.InteropServices
Imports System.Security.Principal
@@ -23,13 +22,13 @@ Public Class GlobalClass
Property IsAdmin As Boolean = New WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)
Property IsJobProcessing As Boolean
Property MainForm As MainForm
Property MAX_PATH As Integer = 260
Property MenuSpace As String
Property MinimizedWindows As Boolean
Property ProcForm As ProcessingForm
Property ProjectPath As String
Property SavedProject As New Project
Property StopAfterCurrentJob As Boolean
Property MAX_PATH As Integer = 260
Event JobMuxed()
Event JobProcessed()
@@ -173,6 +172,11 @@ Public Class GlobalClass
End Function
Sub ProcessJobs()
g.StopAfterCurrentJob = False
ProcessJobsRecursive()
End Sub
Sub ProcessJobsRecursive()
Dim jobs = JobManager.ActiveJobs
If jobs.Count = 0 Then
@@ -208,7 +212,7 @@ Public Class GlobalClass
g.MainForm.SetSavedProject()
g.MainForm.Close()
Else
ProcessJobs()
ProcessJobsRecursive()
End If
End If
Catch ex As AbortException
@@ -895,16 +899,6 @@ Public Class GlobalClass
Return path.Base.StartsWith(p.SourceFile.Base) OrElse path.StartsWithEx(p.TempDir)
End Function
Function GetAudioProfiles() As List(Of AudioProfile)
Dim ret As New List(Of AudioProfile)
ret.Add(p.Audio0)
ret.Add(p.Audio1)
ret.AddRange(p.AudioTracks)
Return ret
End Function
Function GetFilesInTempDirAndParent() As List(Of String)
Dim ret As New List(Of String)
Dim dirs As New HashSet(Of String)
@@ -1360,11 +1354,26 @@ Public Class GlobalClass
End Sub
Function ConvertPath(value As String) As String
If value = "" Then Return ""
If value.Length > 30 AndAlso value.Contains("|") Then value = value.RightLast("|")
If value.Contains("Constant Quality") Then value = value.Replace("Constant Quality", "CQ")
If value.Contains(" | ") Then value = value.Replace(" | ", " - ")
If value.Contains(" ") Then value = value.Replace(" ", " ")
If value = "" Then
Return ""
End If
If value.Length > 30 AndAlso value.Contains("|") Then
value = value.RightLast("|")
End If
If value.Contains("Constant Quality") Then
value = value.Replace("Constant Quality", "CQ")
End If
If value.Contains(" | ") Then
value = value.Replace(" | ", " - ")
End If
If value.Contains(" ") Then
value = value.Replace(" ", " ")
End If
Return value.Trim
End Function