SceneMarkerSplit.vbs

Harry

New member
hi guys,

as i was already asked several times about the split-at-scene-markers script, i thought i'd post it here.

if there's really heavy demand on that, let me know. i could as well make a small windows application which accesses VRD via COM (<= this feature of VRD is awesome) if someone needs this instead of a script, just let me know.

speaking of it, here it is:

Code:
'SCENEMARKERSPLIT START
Dim objFileSystem, objInputFile
Dim strInputFile, inputData, strData
Dim sceneMarker, sceneMarkerArray
Dim arrSize

set Args = Wscript.Arguments
if ( args.count <> 2 ) then	Usage ""

strInputFile = args(0)
outputFile = args(1)

subChar = instr( outputFile, "#" )
if subChar = 0 then Usage "No substitution character found in the output filename"

subChar = instr( outputFile, "\" )
if subChar = 0 then Usage "Output file doesn't contain a path"

Const OPEN_FILE_FOR_READING = 1

Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objInputFile = objFileSystem.OpenTextFile(strInputFile, OPEN_FILE_FOR_READING)

' read everything in an array
inputData = Split(objInputFile.ReadAll, vbNewline)

' create split array with scene markers in msec format
sceneMarkerArray = Array (Int(0))
arrSize = 0
For each strData In inputData
    If  InStr( 1, strData, "SceneMarker") > 0 Then
    	sceneMarker = Mid( strData, InStr( 1, strdata, ">") + 1)
        arrSize = arrSize + 1
	ReDim Preserve sceneMarkerArray (arrSize)
	sceneMarkerArray( arrSize) = round( sceneMarker / 10000000)
    End If
    If  InStr( 1, strData, "Filename") > 0 Then
    	inputFile = Mid( strData, InStr( 1, strdata, ">") + 1)
    End If
    
Next
'SCENEMARKERSPLIT END

'	Finished processing arguments.
'  Start VideoReDo and open the input file.
Set VideoReDo = WScript.CreateObject( "VideoReDo.Application" )
openFlag = VideoReDo.FileOpen( inputFile )

if openFlag = false then
	FatalErr "Unable to open file/project: " + inputFile
end if

fileDuration = VideoReDo.GetProgramDuration
echo fileDuration
frameRate = VideoReDo.GetFrameRate			' in hundredths of a second.
msecPerFrame = 100 / frameRate

if endTIme > fileDuration then endTime = fileDuration

VideoReDo.SetCutMode( FALSE )		' Run in scene mode.

'SCENEMARKERSPLIT START
'also get last segment
arrSize = arrSize + 1
ReDim Preserve sceneMarkerArray (arrSize)
sceneMarkerArray( arrSize) = Int(fileDuration)
'	Output the segments.
Dim lastPos
For each segmentEnd In sceneMarkerArray
	If segmentEnd = 0 Then
		segmentStart = 0
	Else 
		OutputSegment segmentCount, segmentStart, segmentEnd
		segmentStart = segmentEnd
		segmentCount = segmentCount + 1
	End If
Next
'SCENEMARKERSPLIT END


echo "Processing complete"
VideoReDo.Close
Wscript.Quit 0

sub OutputSegment( count, startTime, EndTime )
	outputFilename = CreateSegmentFilename( outputFile, count )
	echo "Outputting: " & count & " " & startTime & " " & endTime & " To: " & outputFilename
	 VideoReDo.ClearAllSelections			' Clear everything out.
	VideoReDo.SelectScene startTime * 1000, EndTime * 1000   ' Start and end times are in msec, SelectScene wants Msec.
	VideoReDo.SetQuietMode true

	' Open the output file and start processing.
	outputFlag = VideoReDo.FileSaveAsEx( outputFilename, 1 )			' Default to MPEG program stream output.

	if outputFlag = false then  FatalErr "Problem opening output file: " + outputFilename

	' Wait until output done.
	while( VideoReDo.IsOutputInProgress() )
		Wscript.Sleep 2000
	wend

	VideoReDo.ClearAllSelections			' Clear everything out.
end sub

Function CreateSegmentFilename( srcFile, count )
	p = instr(srcFile, "#" )
	if count < 1000 then
		count = "000" & count
		count = right(count, 3 )
	end if

	CreateSegmentFilename = left(srcFile, p-1 ) & count & mid(srcFile, p+1)
end function

function ConvertTimecode( timecode )
	ConvertTimecode = 0
	parts = Split( timecode, ":" )
	for i = 0 to ubound(parts)
		ConvertTimecode = ConvertTimecode * 60 +  parts(i)
	next
end function

sub echo( text  )
	wscript.echo( text )
end sub

sub Usage( text )
	if ( text <> "" ) then echo "Error: " + text
	echo "Usage:" & vbNewLine & vbNewLine & "cscript VRDSplitSceneMarkers.vbs  <project file> <output file>" & vbNewLine & vbNewLine & "    Example: VRDSplitSceneMarkers.vbs c:\videos\myvideo.VPrj c:\videos\output#.mpg" & vbNewLine & vbNewLine &  "Note:" & vbNewLine & vbNewLine & "    input file is taken from the project file" & vbNewLine & "    <output file> must contain a full qualified path and the filename must contain a '#' character for the counter substitution." 
	wscript.quit
end sub

sub FatalErr( text )
	Echo  "Error: " + text
	wscript.quit
end sub

sub SplitFilename( filename )
	outputParts = split( outputFile, "." )
	if  ubound( outputParts ) = 0 then
		baseOutputName = outputFile
		baseOutputExt = ".mpg"
	elseif ubound( outputParts ) = 1 then
		baseOutputName = outputParts(0)
		baseOutputExt = "." + outputParts( 1 )
	else
		baseOutputName = ""
		for i = 0 to ubound( outputParts ) - 1
			if ( baseOutputName <> "" ) then baseOutputName = baseOutputName + "."
			baseOutputName = baseOutputName + outputParts(i)
		next
		baseOutputExt = "." + outputParts( ubound(outputParts) - 1 )
	end if
end sub
just copy the source and put it into a file called VRDSplitSceneMarkers.vbs

usage:

usage: VRDSplitSceneMarkers.vbs <project file> <output file>

example: VRDSplitSceneMarkers.vbs c:\videos\myvideo.VPrj c:\videos\output#.mpg

note: input file is taken from the project file. <output file> must contain a full qualified path and the filename must contain a '#' character for the counter substitution


greetz
Harry
 

Anonymous

New member
Harry, a small Windows application for the operation would be great! Very useful if you could make one!

Regards,
Terry.
 

Harry

New member
thanks for the feedback. it's already done:

* split to multiple files by scene markers
* split cut segments to multiple files

i need to add some more functionality like eg i'm working on an automatic chaptering function, eg place scene markers every n minutes and place n scene markers equally separated over the video.

i think i'll post it by the end of next week.

:D
 

diamondd

New member
Another nice feature would be to have this app accept input from a text file where each line
contained all the parameters VRDSplitSceneMarkers needed for each project
so you could batch in a lot of splits from different projects and have the VRDSplitSceneMarkers
do them all at once.

I have a user that needs to convert 200 karaoke lasers to DVD
and something like that would be useful.

DD
 
Top Bottom