diff --git a/Changelog.md b/Changelog.md index d6ae0898..d633ab56 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ - Main dialog shows actual width and height. (stax76) - Advanced Info feature of Code Editor has new VapourSynth ClipInfo option. (stax76) - Fix items can't be removed from or rearranged in lists (Dendraspis, [#433](/../../issues/433)) +- Fix randomly appearing IOException when using x265 with chunks (Dendraspis, [#431](/../../issues/431)) 2.1.7.0 Stable (2021-01-07) diff --git a/Encoding/x265Enc.vb b/Encoding/x265Enc.vb index c8b085b3..fab2e77c 100644 --- a/Encoding/x265Enc.vb +++ b/Encoding/x265Enc.vb @@ -53,6 +53,27 @@ Public Class x265Enc AfterEncoding() End Sub + Overloads Sub Encode(passName As String, commandLine As String, priority As ProcessPriorityClass, Optional isFirstChunk As Boolean = True) + p.Script.Synchronize(False, True, False, Nothing, isFirstChunk) + + Using proc As New Proc + proc.Package = Package.x265 + proc.Header = passName + proc.Encoding = Encoding.UTF8 + proc.Priority = priority + proc.SkipString = "%] " + + If commandLine.Contains("|") Then + proc.File = "cmd.exe" + proc.Arguments = "/S /C """ + commandLine + """" + Else + proc.CommandLine = commandLine + End If + + proc.Start() + End Using + End Sub + Overrides Function GetFixedBitrate() As Integer Return CInt(Params.Bitrate.Value) End Function @@ -85,50 +106,29 @@ Public Class x265Enc If Params.Mode.Value = x265RateMode.TwoPass Then ret.Add(Sub() Encode("Video encoding pass 1" + name.Replace("_chunk", " chunk "), - GetArgs(1, startFrame, endFrame, name, p.Script), s.ProcessPriority) + GetArgs(1, startFrame, endFrame, name, p.Script), s.ProcessPriority, isFirst) Encode("Video encoding pass 2" + name.Replace("_chunk", " chunk "), - GetArgs(2, startFrame, endFrame, name, p.Script), s.ProcessPriority) + GetArgs(2, startFrame, endFrame, name, p.Script), s.ProcessPriority, isFirst) End Sub) ElseIf Params.Mode.Value = x265RateMode.ThreePass Then ret.Add(Sub() 'Specific order 1 > 3 > 2 is correct! Encode("Video encoding first pass" + name.Replace("_chunk", " chunk "), - GetArgs(1, startFrame, endFrame, name, p.Script), s.ProcessPriority) + GetArgs(1, startFrame, endFrame, name, p.Script), s.ProcessPriority, isFirst) Encode("Video encoding Nth pass" + name.Replace("_chunk", " chunk "), - GetArgs(3, startFrame, endFrame, name, p.Script), s.ProcessPriority) + GetArgs(3, startFrame, endFrame, name, p.Script), s.ProcessPriority, isFirst) Encode("Video encoding last pass" + name.Replace("_chunk", " chunk "), - GetArgs(2, startFrame, endFrame, name, p.Script), s.ProcessPriority) + GetArgs(2, startFrame, endFrame, name, p.Script), s.ProcessPriority, isFirst) End Sub) Else ret.Add(Sub() Encode("Video encoding" + name.Replace("_chunk", " chunk "), - GetArgs(1, startFrame, endFrame, name, p.Script), s.ProcessPriority)) + GetArgs(1, startFrame, endFrame, name, p.Script), s.ProcessPriority, isFirst)) End If Next Return ret End Function - Overloads Sub Encode(passName As String, commandLine As String, priority As ProcessPriorityClass) - p.Script.Synchronize() - - Using proc As New Proc - proc.Package = Package.x265 - proc.Header = passName - proc.Encoding = Encoding.UTF8 - proc.Priority = priority - proc.SkipString = "%] " - - If commandLine.Contains("|") Then - proc.File = "cmd.exe" - proc.Arguments = "/S /C """ + commandLine + """" - Else - proc.CommandLine = commandLine - End If - - proc.Start() - End Using - End Sub - Overrides Sub RunCompCheck() If Not g.VerifyRequirements OrElse Not g.IsValidSource Then Exit Sub diff --git a/General/VideoScript.vb b/General/VideoScript.vb index 02f0572a..66e84bce 100644 --- a/General/VideoScript.vb +++ b/General/VideoScript.vb @@ -187,7 +187,8 @@ Public Class VideoScript Optional convertToRGB As Boolean = False, Optional comparePath As Boolean = True, Optional flipVertical As Boolean = False, - Optional avsEncoding As Encoding = Nothing) + Optional avsEncoding As Encoding = Nothing, + Optional writeScript As Boolean = True) If Path = "" Then Exit Sub @@ -255,10 +256,12 @@ clipname.set_output() (comparePath AndAlso Path <> LastPath) OrElse changedAvsEncoding Then If Path.Dir.DirExists Then - If Engine = ScriptEngine.VapourSynth Then - ModifyScript(code, Engine).WriteFileUTF8(Path) - Else - ModifyScript(code, Engine).WriteFile(Path, TextEncoding.EncodingOfProcess) + If writeScript Then + If Engine = ScriptEngine.VapourSynth Then + ModifyScript(code, Engine).WriteFileUTF8(Path) + Else + ModifyScript(code, Engine).WriteFile(Path, TextEncoding.EncodingOfProcess) + End If End If If Not Package.AviSynth.VerifyOK OrElse