Split Video Automatically Based on Criteria

What type of scripts do you need?

Moderator: byronnash

Post Reply
User avatar
lucrativestudios
Posts: 3
Joined: April 19th, 2010, 2:28 pm
Location: Toronto, ON
Contact:

Hey guys,

Just wondering if a script exists that would essentially analyze each frame, and split video based on certain criteria.

Here are a few examples:
- Splitting when the last x frames are identical to the current
- Splitting when the screen is entirely made of black pixels (0,0,0)

I've looked at the 'Magnum: Edit Detector' code, and it seems like this is definitely possible. Just hoping that something like this might exist already.

Thanks!
Adam Bloemink
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

Hey Adam,

Very easy to adapt Magnum to do that. Magnum uses sampleImage() to get an average color for the frame and then compares to the following frame and if it is beyond the threshold different then it creates a cut so you can change that code to look and store 3 frames and compare. The black frame is even easier because you can just say that if sampleImage() returns black then it should be a cut.

-Lloyd
User avatar
lucrativestudios
Posts: 3
Joined: April 19th, 2010, 2:28 pm
Location: Toronto, ON
Contact:

Thanks Lloyd,

I've looked at the code, and with my limited background in scripting, I don't know the proper syntax to make this modification.

Would it be too much to ask for you to tell me how to adjust the following code in order to trigger a split on black frame? (I figure this is the part of the Magnum script which would have to be changed)

myExpEffect.property("Slider").expression = "p=[width/2,height/2];\n " +
"frames=timeToFrames(t = time + thisComp.displayStartTime, fps = 1.0 / thisComp.frameDuration, isDuration = false); \n" +
"frameBefore = framesToTime(frames-1, fps = 1.0 / thisComp.frameDuration); \n" +
"s=sampleImage(p, radius = [width,height], postEffect = true, t = time); \n"+
"sb=sampleImage(p, radius = [width,height], postEffect = true, t = frameBefore); \n"+
"thres=effect(\"Slider Control\")(\"Slider\");\n" +
"diff=(sb[3]*100) - (s[3]*100); \n"+
"c=0; "+
"if (diff > thres) { c= 1} "+
"c";


Thanks!
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

It's a much simple expression just to detect a black frame:

Code: Select all

myExpEffect.property("Slider").expression = "p=[width/2,height/2];\n " +
"s=sampleImage(p, radius = [width,height], postEffect = true, t = time); \n"+
"c=0; "+
"if ((s[0]+s[1]+s[2]) == 0) { c= 1} "+
"c";
-Lloyd
User avatar
lucrativestudios
Posts: 3
Joined: April 19th, 2010, 2:28 pm
Location: Toronto, ON
Contact:

Works great. Thanks!

Ran into some problems though with my workflow, and it would be better if it didn't split unless there are >50 consecutive black frames.

I've modified the code according to how I figured it should look. (I have very little Java knowledge). However, it's still returning an error. Do I have to declare my counting variable?

Code: Select all

		myExpEffect.property("Slider").expression = "p=[width/2,height/2];\n " +
			"s=sampleImage(p, radius = [width,height], postEffect = true, t = time); \n"+
			"c=0; "+
			"if ((s[0]+s[1]+s[2]) == 0) {blkCount=blkCount + 1}"+
			"if (blkCount > 50) {"+
				"c= 1;"+
				"blkCount= 0;"+
			"}"
			"c";

The error is "Class 'global' has no property or method named 'blkCount'" Expression disabled.
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

Expressions are evaluated on a per-frame basis so there is no easy way for it to know the result of the previous frame. You would need to keep the black frame count in the script which requires a bit more involved code. If you want me to do this for you please contact me directly. You can get my email by going to the About section of aescripts.com

-Lloyd
nfrancisj
Posts: 2
Joined: January 18th, 2011, 6:05 am

is there a way... to find the location(X,Y) of a single pixel (thats red) thats on a complete black background?
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

Yes, but you would need to scan the frame pixel by pixel which would take forever using sampleImage(). I think this is a better job for a pixel bender plugin which is designed to do this kind of stuff.
Post Reply