Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 12th July 2007, 21:01   #1  |  Link
Gatiori
Registered User
 
Join Date: Jun 2007
Posts: 3
ShakerAVS. My new filter. Help.

Hi.
I make a new filter. Basicly shake the image by changing amout of radius displacement and frequency of frames.

This is an exemple: http://www.youtube.com/watch?v=WzLJbD20jJQ

This is the code: http://rapidshare.com/files/42560547/shaker.cpp.html

I use BitBlt function, but I have a problem with YV12 colour space, and I wanna make a sub-pixel displacement.

Help me please.

How work a sub pixel displacement?
Gatiori is offline   Reply With Quote
Old 13th July 2007, 00:19   #2  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,550
Use the resizer cores. Something like Spline36Resize(width,height,random1,random2,width,height) (mapped to the C interface), or you could do it entirely in script:

Code:
function ShakeItUp(clip c, int "radius") {
  radius=default(radius,10)
  c
  scriptclip(""" Spline36Resize(width,height,random1,random2,width,height) """)
  frameevaluate(""" random1 = frand("""+string(radius)+""")
   random2 = frand("""+string(radius)+""") """)
 
function frand(float "mx", bool "signed") {
  signed=default(signed,true)
  return (Rand(10000)/10000.0)*mx*(signed?sign(rand(2)-.5):1)
}
}
Oops, didn't mean to steal your thunder. >.>

Last edited by foxyshadis; 13th July 2007 at 00:23.
foxyshadis is offline   Reply With Quote
Old 13th July 2007, 02:22   #3  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Of course building a new resizer every frame is going to be slow. You want to build a small farm of resizers, each one doing a particular movement and then select each based on the desired movement for that frame number. Also watch out using random number with frames. One of the rules of the avisynth game is that every time a frame is rerendered it must be identical to every other time it is rendered. A good way to do this is generate and remember framecount random numbers in the constructor and for each GetFrame always use random number N for frame N.


Also whats with this at the global scope. If you have multiple instance of this filter they will interfere with each other.
Code:
  int x,y;
  float x2,y2,xe,ye,xj,yj,xs,ys,xx,yy;
IanB is offline   Reply With Quote
Old 13th July 2007, 09:21   #4  |  Link
tin3tin
Registered User
 
tin3tin's Avatar
 
Join Date: Mar 2005
Posts: 366
@ Gatiori
Very nice and human/handheld-looking shakes.

A fun idear!
__________________
DVD slideshow GUI(Freeware).
tin3tin is offline   Reply With Quote
Old 8th August 2007, 21:00   #5  |  Link
Gatiori
Registered User
 
Join Date: Jun 2007
Posts: 3
Ok Tanks!!!

I wrote again:

Code:
	x=xfloat[index-1];
	y=yfloat[index-1];
	
	AVSValue args[7] = { child, vi.width,vi.height,-(xfloat[index]),yfloat[index],vi.width+0.01,vi.height+.01 }; 
	resized = env->Invoke("Spline16Resize",AVSValue(args,7)).AsClip(); 
	src1 = resized->GetFrame(n, env);
	env->BitBlt(dstp,dst_pitch,src1p,src1_pitch,kb * (bwd),src1_height);

	if (x!=0) {
		args[3]=xfloat[index]-int(xfloat[index]); args[4]=yfloat[index]-int(yfloat[index]);
		resized2 = env->Invoke("Spline16Resize",AVSValue(args,7)).AsClip(); 
		src2 = resized2->GetFrame(n, env);
		for (w=0; w<abs(x); w++) {
		env->BitBlt(dstp+(((x>0)?x-w:bwd+x+w)*kb)+(((y>0)?y:0)*dst_pitch),dst_pitch,src2p+(((x>0)?w:bwd-w-1)*kb)+((y>0)?0:-y*src2_pitch),src2_pitch,kb ,src2_height-abs(y));
		}
	}
	if (y!=0) {
		args[3]=-(xfloat[index]-int(xfloat[index])); args[4]=-(yfloat[index]-int(yfloat[index]));
		resized3 = env->Invoke("Spline16Resize",AVSValue(args,7)).AsClip(); 
		src3 = resized3->GetFrame(n, env);
		for (h=0; h<abs(y); h++) {
		env->BitBlt(dstp+(((x>0)?x:0)*kb)+( ((y>0)?(y-h):(dst_height+y+h))   *dst_pitch),dst_pitch,src3p+((x>0)?0:-x*kb)+(((y>0)?h:src3_height-h-1) * src3_pitch),src3_pitch,kb*(bwd-abs(x)) ,1);
		}
	}

	return dst;
The process are completely solved by subpixel.
... but this code is very slow.

How to make more fast?
Gatiori is offline   Reply With Quote
Old 8th August 2007, 23:07   #6  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Quote:
Originally Posted by IanB View Post
You want to build a small farm of resizers, each one doing a particular movement and then select each based on the desired movement for that frame number.
As I said prebuild all the resizers in the constructor. Save them in a class scope array. Use these in the GetFrame instead of env->Invoke'ing a new one every frame.

Remember the resizer core does horizontal and vertical resizing as 2 distinct steps, you do likewise to minimise the number of resizers instances needed. Generate X only movement separately from Y only movement resizers and then chain them in the GetFrame. By quantizing your movement vectors cleverly you would be able to do 256 distinct movements with only 16 X only resizers and 16 Y only resizers.

You will need an intermediate dummy class to act as a selector so you can have a constant 'child' member for every resizer.

:Edit: In fact completly separate your filter into a horizontal only shaker and a vertical only shaker. In the create call do "return new HShake(new VShake(child,...), ...)"

Last edited by IanB; 8th August 2007 at 23:18.
IanB is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:35.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.