Log in

View Full Version : My PIP Script...


Surrealist
11th January 2008, 18:46
So... I came across the infamous(or maybe famous) Brady Bunch script, but I wanted to be able to specify where, when, and for how long certain clips were played in a PIP box. I also wanted to easily add multiple PIP boxes spread throughout a base clip.

After tinkering(and already being an experienced programmer), I think I figured out the script language and modified the Brady Bunch script to be an easy way to create the PIP effect with the least amount of hassle.

You need to make sure all clips are in the same framerate... I found that out the hard way.

To add more than one PIP clip in a single video, just load the clip and resize it... and then copy the line at the bottom with your new clip name and start position.

So... I hope someone finds this script useful, or educational. :)

And I just realized... to use this script you need a file named "blank.png" which is just a white picture. I think that the "blank.png" could be modified to give rise to various PIP shapes instead of the normal square one, but am actually totally unaware of its true function in this script... I couldn't figure out how to get rid of it...

Also, "video" and "clip1" are assumed to be the same size videos... obviously if your "clip1" is already small enough then you don't need the resize.

Here it is:

#Master video
global video = avifilesource("01.avi").ConvertToRGB32()

#PIP clips
clip1 = avifilesource("02.avi").ConvertTorgb32()

#Reduce the size of all PIP clips
clip1 = clip1.bicubicresize(width(clip1) / 4,height(clip1) / 4)

#################################################################

# calculate coordinates for PIP clips
xpos = Width(video)-Width(clip1)-20
ypos = Height(video)-Height(clip1)-20

#################################################################

#Framerate, seconds, and total length of master video
FR = video.framerate()
global Total=video.Framecount()

#Intialize mask video clip
global lblank = ImageSource("blank.png", 0, 1, FR,pixel_type = "rgb32").BilinearResize(width(video),height(video)).Loop().ConvertToRGB32()

#################################################################

# This makes moving layers possible:
Function Layer1(clip lblank, clip lvideo1, int x, int y, int w, int h)
{(lblank).Layer(lvideo1,"add",255,x,y)}

# Simplifies doing PIP clips... less code and hassle!
Function placePIP(clip PIP, int start, int x, int y)
{
video1=Animate(0,1, "Layer1" ,lblank,PIP,x,y,width(PIP),height(PIP),lblank,PIP,x,y,width(PIP),height(PIP))

videoa=video.Trim(0,int(start))
videob=video.Trim(int(start)+1,int(start + (PIP.Framecount()))).Layer(video1)
videoc=video.Trim(int(start + (PIP.framecount()))+1,Total)
video1=videoa+videob+videoc

return video1
}

#################################################################

#Add PIP for clip1
video = placePIP(clip1,110,xpos,ypos)

video

talen9
11th January 2008, 19:28
Maybe you could replace "ImageSource("blank.png", ...)" with a call to BlankClip(width(video),height(video)) (or something similar, I didn't try it just yet) ?

Surrealist
12th January 2008, 03:23
Maybe you could replace "ImageSource("blank.png", ...)" with a call to BlankClip(width(video),height(video)) (or something similar, I didn't try it just yet) ?
Hmm... that's what I was thinking...

But, I'm going to have to look into that function and see if I can get it to fit.

EDIT:
Okay, got it... you can replace that "blank.png" line with:
global lblank = blankclip(length=int(FR), width=width(video), height=height(video), fps=FR).Loop()

That would make it so you do not need the "blank.png" file at all... I don't know why the "Brady Bunch" guy didn't think of this. Hm....

sh0dan
13th January 2008, 00:04
Use Overlay instead of layer, it will work on all colorspaces, and you can use conditional vairables instead of animate.

Surrealist
13th January 2008, 03:45
Use Overlay instead of layer, it will work on all colorspaces, and you can use conditional vairables instead of animate.

Ahhh!

I know a bunch about other languages, but I still have to grasp exactly how this "language" is set up.

I don't know how I would use overlay instead of layer, and I don't know how I would replace "animate."

I just basically hacked apart the "Brady Bunch" script, and made it something else. I have no idea what certain things actually *do*.

cweb
28th January 2008, 19:49
Here's a little pip function I just wrote for fun.. x and y are the position where you want clip pipb to appear. pipb needs to be resized, reduced in size.. eg bicubicresize(360,270)

function PIPCLIP(clip c, clip pipb, int "_x", int "_y")
{
_x = default(_x, 342)
_y = default(_y, 280)
c=c.overlay(pipb, x=_x,y=_y,mode="blend",opacity=1)
return c
}

Surrealist
28th January 2008, 19:56
Here's a little pip function I just wrote for fun.. x and y are the position where you want clip pipb to appear. pipb needs to be resized, reduced in size.. eg bicubicresize(360,270)

function PIPCLIP(clip c, clip pipb, int "_x", int "_y")
{
_x = default(_x, 342)
_y = default(_y, 280)
c=c.overlay(pipb, x=_x,y=_y,mode="blend",opacity=1)
return c
}
Yeah... I was looking for a function where I could insert multiple PIP windows in specific frame locations for a specific amount of time.

Basically, what I'd use it for is in video responses on YouTube. I'd cut out multiple sections of their video, and place a few PIP clips that I'd respond to in my video.

So I had to find a way to be able to use just one line to put a PIP clip wherever I wanted in the master clip.