Skip to content

Commit

Permalink
Run Video Comparison source file indexing as process
Browse files Browse the repository at this point in the history
  • Loading branch information
Dendraspis committed Jun 3, 2024
1 parent 4d28f8c commit d279abf
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ v2.40.0 (not published yet)
- Crop: Move AutoCrop settings from Settings to Project Options
- Crop: Add new "Time Interval" mode for AutoCrop
- Analyzes a frame every x seconds, which makes it more useful throughout short and long videos
- VideoComparison: Run indexing of source files as (visible) task/job ([#1226](/../../issues/1226))
- NVEncC: Add new "--vpp-decomb" parameter
- QSVEncC: Add new "--vpp-decomb" parameter
- SvtAv1EncApp: Add long path support ([#1374](/../../issues/1374))
Expand Down
47 changes: 44 additions & 3 deletions Source/Forms/VideoComparisonForm.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

Imports System.Drawing.Imaging
Imports System.Text
Imports Microsoft.VisualBasic.FileIO
Imports StaxRip.UI

Expand Down Expand Up @@ -119,7 +120,7 @@ Public Class VideoComparisonForm

Sub TabControlOnSelected(sender As Object, e As TabControlEventArgs)
Dim tab = DirectCast(e.TabPage, VideoTab)

laFilePath.Text = tab.SourceFilePath
End Sub

Expand Down Expand Up @@ -412,9 +413,9 @@ Public Class VideoComparisonForm
script.Filters.Add(New VideoFilter("Source", "Source", File.ReadAllText(sourcePath)))
Case VideoComparisonFileType.Video
If sourcePath.EndsWith("mp4") Then
script.Filters.Add(New VideoFilter("LSMASHVideoSource(""" + sourcePath + "" + """, format = ""YUV420P12"")"))
script.Filters.Add(New VideoFilter("Source", "Source", "LSMASHVideoSource(""" + sourcePath + "" + """, format = ""YUV420P12"")"))
Else
script.Filters.Add(New VideoFilter("FFVideoSource(""" + sourcePath + "" + """, colorspace = ""YV12"")"))
script.Filters.Add(New VideoFilter("Source", "Source", "FFVideoSource(""" + sourcePath + "" + """, colorspace = ""YV12"")"))
End If
script.Filters.Add(New VideoFilter("SetMemoryMax(512)"))
Case VideoComparisonFileType.Picture
Expand All @@ -439,6 +440,7 @@ Public Class VideoComparisonForm
Throw New NotSupportedException("VideoComparisonFileType unhandled!")
End Select

Indexing(sourcePath, script)
script.Synchronize(True, True, True)

Server = FrameServerFactory.Create(script.Path)
Expand Down Expand Up @@ -476,6 +478,45 @@ Public Class VideoComparisonForm
Return True
End Function

Sub Indexing(sourcePath As String, script As VideoScript)
If String.IsNullOrWhiteSpace(sourcePath) Then Exit Sub
If Not File.Exists(sourcePath) Then Exit Sub
If script Is Nothing Then Exit Sub

Dim sourceFilter = script.GetFilter("Source")
If sourceFilter Is Nothing Then Exit Sub

Dim codeLower = script.GetFilter("Source").Script.ToLowerInvariant

If codeLower.Contains("ffvideosource(") OrElse codeLower.Contains("ffms2.source") Then
If codeLower.Contains("cachefile") AndAlso p.TempDir <> "" AndAlso New DirectoryInfo(p.TempDir)?.Name?.EndsWithEx("_temp") Then
g.ffmsindex(sourcePath, Path.Combine(p.TempDir, g.GetSourceBase + ".ffindex"))
Else
g.ffmsindex(sourcePath, sourcePath + ".ffindex")
End If
ElseIf codeLower.Contains("lwlibavvideosource(") OrElse codeLower.Contains("lwlibavsource(") Then
If Not File.Exists(sourcePath + ".lwi") AndAlso
Not File.Exists(Path.Combine(p.TempDir, g.GetSourceBase + ".lwi")) AndAlso
File.Exists(script.Path) AndAlso Not FileTypes.VideoText.Contains(sourcePath.Ext) Then
Using proc As New Proc
proc.Header = "Index LWLibav"
proc.Encoding = Encoding.UTF8
proc.SkipString = "Creating lwi"
If script.IsAviSynth Then
proc.File = Package.ffmpeg.Path
proc.Arguments = "-i " + script.Path.Escape + " -hide_banner"
Else
proc.File = Package.vspipe.Path
proc.Arguments = script.Path.Escape + " NUL -i"
End If

proc.AllowedExitCodes = {0, 1}
proc.Start()
End Using
End If
End If
End Sub

Sub Draw()
Renderer.Position = Pos
Renderer.Draw()
Expand Down

0 comments on commit d279abf

Please sign in to comment.