Ad-Detective... Split and save video file at markers automatically

jmc

Well-known member
I have no idea if this would be easy or impossible.

It seems to detect the breaks in the video file. I would love it if it could also
automatically split the file at those points and save each segment off as a separate file.

I do not want anything deleted. I want everything saved but separately.

Thanks,
jmc
 
Last edited:

Dan203

Senior Developer
Staff member
We've talked about adding this before. Because of the way our output works it's a little difficult to do because each muxer would either need to be changed to be aware of the splitting or we'd have to create a new output graph for each segment, neither of which is really easy. This is actually something that could be done pretty easily using a script and the COM interface though. Right now with no changes from us.
 

jmc

Well-known member
We've talked about adding this before. Because of the way our output works it's a little difficult to do because each muxer would either need to be changed to be aware of the splitting or we'd have to create a new output graph for each segment, neither of which is really easy. This is actually something that could be done pretty easily using a script and the COM interface though. Right now with no changes from us.
"script and the COM interface"...Ouch.

Thank you tho,
jmc
 

tobyW

Member
Attached: a script that saves scenes as separate files

Scary, yes! But, this capability is one of the great strengths of VideoRedo.:)

The COM interface, with an example, is documented in VRD's Help->Contents->Contents->Reference->COMinterface.

That documentation does have a few misguidances, and anyway writing a VBScript is strewn with pitfalls for a novice like me.

So, curiosity leads me to summon my courage and tackle your request, as a learning exercise.

Luckily your request is simple to implement. Basically there are 2 steps:-
- Step 1. Run VRD and do your ad-scan, to arrive at a list of "scenes", then save the project file.
- Step 2. Run a script that uses the COM interface to read the list of scenes and then loads each scene singly
into VRD and writes it to a separate file.

I attach a script "AdSplit.vbs" that I've cooked up. At the top of the file I've put some notes on how to use it.

This script seems to work OK for me, but feel free to improve it if you like!

TobyW
 

Attachments

jmc

Well-known member
I downloaded the AdSplit.zip.
Will see if I get in an experimental mood.

thanks,
jmc
 

nitro918

New member
I am reviewing the code provided for version 5 and attempting to update it to version 6. I can't seem to connect/update the method from v5: GetCutSceneListData in the v6, which is located at line 66 in the code attached/below modified from the original in 2015.

I've tried the method in v6 believing it to be the equivalent of V5: SceneMarksGetSceneMarkTime



The number of scenes detected in my test video file do calculate correctly from the project file under the previous lines of code:

numScenes = vrd.SceneMarksGetCount( )
Wscript.echo("Number of scenes: " & numScenes)





' Before running this script, run VRD and do the ad-scan. This script assumes you
' do your ad-removal in Cut mode, so on completion please click "Invert All Cuts",
' then the Cut list will actually be a list of Scenes. Save this as a project file.
'
' Run this script from command line, with full path of project filename as a parameter.
' Optionally, add a profile name and output file extension as 2nd and 3rd parameters.
' Examples:-
' AdSplit "H:\EDITING\Gardens.Vprj"
' AdSplit "H:\EDITING\Gardens.Vprj" "my H264 Profile" ".mp4"

' Script starts here. Make sure at least one parameter was supplied
if WScript.Arguments.Count < 1 then
Wscript.echo( "Syntax: AdSplit.vbs ""C:\My Movies\Antz.Vprj""" _
& " [""my H264 profile"" "".mp4""]" )
Wscript.Quit 3
end if

' Get the project file name
projectFile = Wscript.Arguments(0)

' Get the extra parameters if supplied, or default to mpeg-2 program stream
outputProfile = "MPEG-2 Program Stream"
outputExtension = ".mpg"
if WScript.Arguments.Count > 2 then
outputProfile = Wscript.Arguments(1)
outputExtension = Wscript.Arguments(2)
end if

' Get project file's parent folder. We will save outputs there, based on same filename.
Set objFS = CreateObject("Scripting.FileSystemObject")

projectPath = objFS.GetAbsolutePathName(projectFile) ' full path including drive
filename = objFS.GetFileName(projectFile) ' filename with its extension
basename = objFS.GetBaseName(projectFile) ' filename minus its extension
folderpath = Left(projectPath, Len(projectPath)-Len(filename))
basepath = folderpath & basename & "_"

if not objFS.FileExists(projectPath) then
Wscript.echo("ERROR - File not found: " & projectPath)
Wscript.Quit 3
end if

' We will be using the old pre-VRD5 COM interface, which is the one still listed
' in VRD5's help. That's OK, because VRD5 still supports the old interface if we
' launch the VRD COM object with the following version of the command.
set vrd = WScript.CreateObject( "VideoReDo6.Application" )

' In VRD, open the project file that contained the ad-scan's scene markers
Vrd.EditSetMode(0)
openflag = vrd.FileOpen ( projectpath, false)

if openflag = false then
Wscript.echo( "ERROR Unable to open project file: " + projectPath )
Wscript.Quit 3
end if

' Find out how many scenes there are
numScenes = vrd.SceneMarksGetCount( )
Wscript.echo("Number of scenes: " & numScenes)


' Gather the list of scenes. Let's allow for up to 1000 of them.
dim startMsec(1000)
dim endMsec(1000)
for scene = 1 to numScenes
startMsec(scene) = vrd.GetCutSceneListData(scene, 0)
endMsec(scene) = vrd.GetCutSceneListData(scene, 1)
next

' Construct output file names, and check they don't already exist
dim outputFile(1000)
for scene = 1 to numScenes
suffix = Right(String(2, "0") & scene, 2)
name = basepath & suffix & outputExtension
outputFile(scene) = name
if objFS.FileExists(name) then
Wscript.echo("ERROR: Found old output file called " & name)
Wscript.quit 3
end if
next

' Change to Scene mode, as we want to add a scene rather than add a cut
vrd.EditSetMode(1)

if not vbYes = MsgBox ( "There are " & numScenes & " scenes. These will be saved as" _
& chr(13) & chr(13) & """" & outputFile(1) & """ etc." _
& chr(13) & chr(13) & "using profile: ''" & outputProfile & """" _
& chr(13) & chr(13) & "OK to continue?", _
vbYesNo, "AdSplit" ) then
vrd.Close()
Wscript.quit 0
end if

' For each scene in the original list...
for scene = 1 to numScenes
' Place that single scene in the scene list
vrd.SceneMarkClearAll( )
startMs = startMsec(scene)
endMs = endMsec(scene)
if not vrd.SceneMarksGetSceneMarkTime( startMs, endMs ) then
Wscript.echo("ERROR selecting scene " & scene & ": " & startMs & "mS to " & endMs & "mS")
Wscript.quit 3
end if

' Then launch the file-save process, and poll until it finishes
'Wscript.echo( "Saving with profile " & outputProfile & " to " & outputFile(scene) )
call vrd.FileSaveProfile(outputFile(scene), outputProfile)
While( vrd.IsOutputInProgress() )
Wscript.Sleep 1000
Wend
next ' ...end of the "for scene" loop

Wscript.echo("Finished splitting into " & numScenes & " files in " & folderpath)
vrd.Close()
Wscript.quit 0
 

Attachments

Top Bottom