Log in

View Full Version : rotate


Truman
12th November 2002, 17:33
Is there a way to use Vdub's internal filters? I need a rotate filter :scared:
poptones?

Dreassica
12th November 2002, 17:41
doesnt Wilbert vdub filter import plugin support that one?

Wilbert
12th November 2002, 18:01
No, only most of Vdub's external filters. Sorry ...

Xenoproctologist
14th November 2002, 01:40
I converted this to an external filter for a project I was working on a while ago. `Lemme scrounge around a bit and see if I can find it again.

Xenoproctologist
14th November 2002, 02:39
Ah, here we go. One externalized version of vdub's rotate filter. Dump rotate.vdf in your virtualdub plugin directory, edit virtualdub_plugin_directory in vd_rotate.avs, and then import it into your script.


Attachment pending moderator approval...

Richard Berg
14th November 2002, 08:27
This should be a candidate for addition to the core, IMO.

Wilbert
14th November 2002, 10:23
Cool! I will try it and add it to vdub_filters.avs.

Truman
14th November 2002, 13:53
Originally posted by Richard Berg
This should be a candidate for addition to the core, IMO.

Yes, and hopefully the zoom filter too.

Thanks a lot Xenoproctologist.

Truman
14th November 2002, 15:19
:D It works. Exactly what I want to do.

import("e:\Avisynth\Vdub_plugins\vdub_filters_v16+\vdub_filters+.avs")
v=directshowsource("d:\test.mpg",25).ConvertToRGB32
intro=trim(v,0,249)
main=trim(v,250,0)
z=VD_Zoom(intro,352, 288, 176, 144, 10, 100, 0, 249, 255, 0,0, "p_bicubic")
a=animate(z,0,249,"vd_rotate",33554519,2,$ff0000,0,0,2,$ff0000,0)
unalignedsplice(a,main)

Thanks again.

Marc FD
14th November 2002, 16:56
i've some ideas about basic YV12 rotate.

for zoom, simply use crop+*resize

Truman
14th November 2002, 19:10
Originally posted by Marc FD
for zoom, simply use crop+*resize
Well, zoomin work with animate+crop+resize, but zoomout does not work this way. I would need a combination of resize and addborders, that is not possible with the animate filter. Hope, I am wrong and you can show me an example.:)

scmccarthy
14th November 2002, 19:58
I don't know anything about this BUT :D

Keep a pointer to the original fullsize frame like this:

original=avisource("my.avi")
new=Crop(original,l,t,w,h)
Resize(new,w,h),etc.

Something like that. Either that or put resize before crop for ZoomOut.

Xenoproctologist
15th November 2002, 03:59
You can't do Zoom with animate() because animate() refuses to output a clip where the frame changes sizes--something which would have to happen unless there's some way to chain filters within animate() which I don't know of.

The only thing holding one back from doing Zoom as a purely scripted function is the inability to get the current frame number from the environment. Is there an undocumented function to get it, or is this just an oversight?

Of course, it'd be simple to program as a plugin...just invoke() the correct combination of crop(), *resize(), and addborders(). The only thing that really prevents me from doing it myself is that I've never used vd_resize, and thus don't know its exact behavior. Maybe I'll try puzzling it out and throwing it together.


Hmm...as a side note, crop's default behavior should probably be to invoke addborders() when the cropping window goes outside the frame, rather than throwing an access violation.

[EDIT]
Waitaminute...nevermind on the "can't use animate()".

How the hell did I miss the src_* parameters on the resize functions for so long?

Wilbert
15th November 2002, 10:30
Well, zoomin work with animate+crop+resize, but zoomout does not work this way. I would need a combination of resize and addborders, that is not possible with the animate filter. Hope, I am wrong and you can show me an example.

You can use a black clip as blackground (with overlay) when doing this. Look up the screensaver thread for examples of zooming out.

@ Xenoproctologist,

Did you make this filter? (btw, 93207 = about two degrees)

Xenoproctologist
15th November 2002, 11:08
Originally posted by Wilbert
@ Xenoproctologist,

Did you make this filter? (btw, 93207 = about two degrees)

Everything that actually does anything was cribbed directly from VirtualDub. I just appended the right dll exports and fudged things so that it would compile as a dll.

Not too impressive, in all truth, but I think I did well, considering that I didn't know C(++) or anything beyond the most basic procedural programming at all when I did it (7 or 8 months ago, I think it was).


It's entirely possible that 93207 is 2 degrees; I had to guess the units from an old avisynth script of mine and I could have misrememberd what I was aiming for. If you want the final word on this, create a VirtualDub job which rotates the video 1 degree and open the .jobs file.


By-the-by, if anyone notices anything that I forgot to do to make this GPL compliant, `lemme know. For that matter, I should probably diff my local copy of the vdub source against the originals to make sure I didn't fudge anything else when making this; it's been so long that I've completely forgotten.

matrix
15th November 2002, 15:58
Hi all.
Is it possible at all to use this function (vd_rotate) on a clip, with another clip as background? ...with layer mabe?
Did some unsuccesful attempts.

Thanks.

Xenoproctologist
15th November 2002, 16:15
Originally posted by matrix
Is it possible at all to use this function (vd_rotate) on a clip, with another clip as background? ...with layer mabe?
Hmm...

This is untested and may need tweaking, but off the top of my head...
rotateclip = whatever.converttorgb32()
backgroundclip = somethingelse.convertorgb32()

maskclip = blankclip(rotateclip, color=$ffffff)

rotateclip = vd_rotate(rotateclip,93207)
maskclip = vd_rotate(maskclip,93207)

rotateclip = mask(rotateclip,maskclip)

layer(backgroundclip, rotateclip, "add")

matrix
15th November 2002, 17:38
I think it needs some animation for the actual rotation. I can rotate it any angle, but not give it the motion.

Edit

Ok, this way works, but...

rotateclip = AviSource("C:\Movie\t7.avi").BilinearResize(180,180).converttorgb32
backgroundclip = AviSource("C:\Movie\t6.avi").BilinearResize(480,480).converttorgb32
import("C:\Movie\VirtualDub-1_4_10\plugins\vd_rotate.avs")
maskclip = blankclip(rotateclip, color=$ffffff)

rotateclip = animate(rotateclip,0,150,"vd_rotate",33554519,2,0,0,0,2,0,0)
maskclip = animate(rotateclip,0,150,"vd_rotate",33554519,2,0,0,0,2,0,0)

rotateclip = mask(rotateclip,maskclip)

layer(backgroundclip,rotateclip, "add", 255, 150, 150)

the rotateclip is transparent, and the maskclip should be bigger.(cuts the corners of the clip)

Any ideas how to fix it?

Xenoproctologist
16th November 2002, 02:50
Originally posted by matrix
the rotateclip is transparent, and the maskclip should be bigger.(cuts the corners of the clip)

The transparency is because you put ``maskclip = animate(rotateclip[...]''. That should be maskclip.

To fix the clipped corners, just addborders() to the rotateclip and maskclip after you've generated the maskclip.


Fixed script:
rotateclip = AviSource("C:\Movie\t7.avi").BilinearResize(180,180).converttorgb32
backgroundclip = AviSource("C:\Movie\t6.avi").BilinearResize(480,480).converttorgb32
import("C:\Movie\VirtualDub-1_4_10\plugins\vd_rotate.avs")
maskclip = blankclip(rotateclip, color=$ffffff)

rotateclip = rotateclip.addborders(50,50,50,50)
maskclip = maskclip.addborders(50,50,50,50)

rotateclip = animate(rotateclip,0,150,"vd_rotate",33554519,2,0,0,0,2,0,0)
maskclip = animate(maskclip,0,150,"vd_rotate",33554519,2,0,0,0,2,0,0)

rotateclip = mask(rotateclip,maskclip)

layer(backgroundclip,rotateclip, "add", 255, 100, 100)

matrix
16th November 2002, 06:16
You're right. It works now.

Thanks.

Truman
19th November 2002, 02:53
Originally posted by Wilbert
You can use a black clip as blackground (with overlay) when doing this. Look up the screensaver thread for examples of zooming out.

<impressed>What a killer script. Zooming works really great :D , even with a background video. Did you ever consider to post the "res" and "resize" functions (or even the the whole script) to the Avisynth homepage? Thanks a lot.</impressed>

Wilbert
19th November 2002, 16:13
<impressed>What a killer script. Zooming works really great , even with a background video. Did you ever consider to post the "res" and "resize" functions (or even the the whole script) to the Avisynth homepage? Thanks a lot.</impressed>
Yes, I wanted (and still want) to make a short tutorial about this stuff on avisynth.org.

Xesdeeni
20th November 2002, 16:11
I haven't tried, but can you use Animate() with a script function? If not, would it be difficult to implement?

Xesdeeni

Wilbert
20th November 2002, 16:40
I haven't tried, but can you use Animate() with a script function?
You mean your own defined functions? Sure you can use them with Animate.

Xesdeeni
20th November 2002, 17:26
I haven't tried, but can you use Animate() with a script function?You mean your own defined functions? Sure you can use them with Animate.(also http://forum.doom9.org/showthread.php?s=&threadid=38597)

Then wouldn't writing a script function that is used in Animate() and includes cropping (and/or borders) be easier than rotating masks? Am I oversimplifying this?

Xesdeeni

Wilbert
21st November 2002, 10:23
Yes and no. First of all how would you cut the black borders of a rotated rectangle. I don't see how to avoid that.

But you should be able to do it without explicitly applying any masks because ConvertToRGB32 will create a mask. I will look at it this weekend ...

Xesdeeni
21st November 2002, 16:23
I still hope I'm not missing something, but if you start with: _____
| |
|_____|and then rotate it (please ignore graphical text distortion :D ): _
/ \_
/ \
\_ /
\/which is of course taller and wider than the source, and the extra area is filled in with the background color (black?). But then it can be cropped:
____
/ \
\___/
back to the original size. I know there was some mention of zooming too, but for just spinning, isn't this what you would want? My suggestion was just to do the rotation and cropping together in a script function and use that function in the Anamate() call.

Xesdeeni

Xenoproctologist
21st November 2002, 18:51
Actually, Xesdeeni, that's Rotate's default behavior. It's not cropping which requires a bit of script twiddling.

Xesdeeni
21st November 2002, 22:19
Terribly sorry. I must have been confusing it with PhotoShop rotate. I knew I was missing something obvious.

Xesdeeni

Wilbert
23rd November 2002, 16:11
# What do you think about the following script (replace clip2 by your
# favourite short clip)?

global VirtualDub_plugin_directory = "c:\Program Files\virtualdub\plugins"

#######################################################################
# Rotate filter by xxx, (externalized filter of Virtual Dub) #
# orientation: multiples of 0.001 degrees. Positive rotates right; #
# negative rotates left. #
# samplemethod: 0 = point resample #
# 1 = bilinear resample #
# 2 = bicubic resample #
# color = Color to use as background in $RRGGBB hexadecimal notation. #
# expandframe = Expands frame to fit rotated image. #
# #
# (download: xxx) #
#######################################################################

function VD_Rotate(clip clip, float orientation, int "samplemethod", int "color", bool "expandframe")
{
LoadVirtualdubPlugin(virtualdub_plugin_directory+"\rotate.vdf", "_VD_Rotate")
orientation = orientation*8388608/180
return clip._VD_Rotate(orientation, default(samplemethod, 2), default(color, $000000), default(expandframe, false)?1:0)
}


clip2 = AviSource("F:\models.avi", false).ConvertToRGB32
clip1 = BlankClip(length=3000, width=720, height=576, fps=clip2.framerate, color=$000000)
clipa = clip2.BicubicResize(32, (32*clip2.height)/clip2.width)


# fade_in: fades in the clip (during the first n frames) starting with two black frames

function fade_in(clip clip, int "n") {
return clip.Blackness(n+2).Dissolve(clip, n)
}


# res: gives a clip which is resized with size (width, height). (centerX, centerY) is the center of
# the resulting clip on a black background.

function res(clip clip, clip LClip, int width, int height, int centerX, int centerY) {
LClip = BicubicResize(LClip, width, height)
return layer(clip, LClip, "Add", 255, centerX-LClip.width/2, centerY-LClip.height/2)
}


# resize: resizes LClip to a clip with size (width, height). (centerX, centerY) is the center of
# the resulting clip on a black background. LClip starts playing at start_frame (with
# start_frame >= 0 and end_frame >= LClip.framecount).

function resize(clip clip, clip LClip, int start_frame, int start_width, int start_height,
\ int end_frame, int end_width, int end_height, int centerX, int centerY) {
return Animate(start_frame, end_frame, "res", clip, LClip, start_width, start_height, centerX, centerY,
\ clip, LClip, end_width, end_height, centerX, centerY)
}


# rot: rotates LClip angle degrees. (centerX, centerY) is the center of
# the rotating clip on a black background.

function rot(clip clip, clip LClip, int centerX, int centerY, int angle) {
LClip = VD_rotate(LClip, angle, 2, $000000, true).ConvertToRGB24.ConvertToRGB32
return layer(clip, LClip, "Add", 255, centerX-LClip.width/2, centerY-LClip.height/2)
}


# rotate: rotates LClip (start_angle) to a clip (end_angle). Moves it from center (centerX, centerY)
# to (center2X, center2Y). LClip starts playing at start_frame (with
# start_frame >= 0 and end_frame >= LClip.framecount).

function rotate(clip clip, clip LClip, int centerX, int centerY, int start_frame, int start_angle,
\ int end_frame, int end_angle) {
return Animate(start_frame, end_frame, "rot", clip, LClip, centerX, centerY, start_angle,
\ clip, LClip, centerX, centerY, end_angle)
}


# rotate_acc: same as the function rotate, but LClip is accelerated if m>1, decelerated if m<1, gives
# the same as rotate for m=1.

function rotate_acc(clip clip, clip LClip, int centerX, int centerY, int start_frame, int start_angle,
\ int end_frame, int end_angle, float m) {
end_frame2 = round(m*(end_frame+1)-1)
return Animate(start_frame, end_frame, "rotate",
\ clip, LClip, centerX, centerY, start_frame, start_angle, end_frame2, end_angle,
\ clip, LClip, centerX, centerY, start_frame, start_angle, end_frame, end_angle)
}


# examples:

# 45 degrees rotated:
#
# rot(clip1, clipa, 360, 288, 45).Trim(0, clipa.framecount-1)

# 720 degrees rotation:
#
# rotate(clip1, clipa, 360, 288, 0, 0,
# \ clipa.framecount-1, 720).Trim(0, clipa.framecount-1)


# 720 rotation and decelerated by an half:
#
# rotate_acc(clip1, clipa, 360, 288, 0, 0,
# \ clipa.framecount-1, 720, 0.5).Trim(0, clipa.framecount-1)


clip_final = clip2.Trim(0,-1).Loop(200).fade_in(60)

clip_final1 = clip1.resize(clip_final, 0, clipa.width, clipa.height,
\ clip_final.framecount-1, 360, (360*clipa.height)/clipa.width, 360, 288).Trim(0, clip_final.framecount-1)

clip_final2 = clip1.rotate_acc(clip_final1, 360, 288, 0, 0,
\ clip_final1.framecount-1, 720, 0.5).Trim(0, clip_final1.framecount-1)

clip_final2 + clip1.res(clip2, 360, (360*clip2.height)/clip2.width, 360, 288)

Xenoproctologist
23rd November 2002, 23:12
# What do you think about the following script (replace clip2 by your
# favourite short clip)?
Well, it manages to swallow 600+mb of RAM within 120 frames of starting playback...