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 15th May 2003, 22:21   #1  |  Link
t_2
Registered User
 
Join Date: Apr 2003
Location: USA
Posts: 91
BoxBlur.vdf & MotionBlurBlend.avs

Is there interest in porting VirtualDub's box blur filter, so it can be used in AviSynth? It seems to me to be an exellent filter AND I have a more selfish reason as well - a User Defined Function that I am working on.

I will paste it below. I've got it working and can email input and output frames if there is interest.

I'm new to this so there may be issues with resolution. It needs some tests and some error messages, but haven't figured that out yet. Nevertheless, it seems to work very well. Any suggestions most welcome, better yet if someone rewrites it.

t_2

P.S. MotionBlurBlend got a little messed up when I pasted it below, so I can email it along with the frames, it that is easier.


#######################################################################
# MotionBlurBlend
# User-Defined Function
# for use with AviSynth
#
# When a video camera records (at normal shutter speeds, i.e.,1/50
# sec.) a subject/object moving quickly in front of a screen for
# chroma keying, the object and screen can blend together in the
# motion areas. After the object is superimposed on the new
# background, the screen color can show up in the higher motion
# areas. This can have a magical effect but maybe that's not what you # need. When the shutter is set to, say, 1/600 sec., the object and
# screen can be easily separated, but the motion will display a
# strobe-like effect rather than being fluid. The sharp edges of the
# object, which allow for good separation when chroma keying have the
# unwanted effect of disturbing our perception of the fluidity of
# motion.
#
# This user-defined function is for use on interlaced video of moving
# objects shot at high shutter speeds against a screen (for purposes
# of chroma keying). MotionBlurBlend works by rendering the moving
# object somewhat transparent vis-a-vis the new background
# (i.e., blending the object with the new background) and by bluring # the objects sharp edges.
#
# Presently MotionBlurBlend makes several calls to
# SmartDeinterlacer.vdf and until VirtualDub's box blur is ported to
# AviSynth, it makes two calls to VirtualDubs frameserver!! It runs
# at 4-5 sec/frame on a 1 GHz PC, but seems to yield good results.
#
# The imput is RGBA fields which have been expanded to full frames,
# i.e., 720x576 at 50fps for PAL. The alpha chanel of areas where the
# screen appears is presumed to be set to zero (0 = transparent, 255
# = opaque). If you didn't preprocess, use ColorKeyMask to key out
#
# the screen. I prefer to do this in Winimage's FX7 which gives me
# much more control of the process and better results. The output is
# progressive video 720x576 at 25 fps for PAL.
#
# (Naturally, when you film at high shutter speeds you must open up
# the iris (i.e., decrease the f-stop) to let in more light and/or
# use brighter lamps.)
#
#
# <theo@szent-norbert.sulinet.hu>
######################################################################





######################################################################
# DEFINITION




#This is how I hope the Function will eventually look:
#function MotionBlurBlend(clip v,clip b, int blend, int blur, int matteblur)
#Where v is the object video and b the new background video
#Below is what we have now.


function MotionBlurBlend(clip v,clip b, int blend)
{

#PLUGINS
Import("C:\WINDOWS.000\Asztal\alpha\vdub_filters.avs")
#LoadVirtualDubPlugin("C:\WINDOWS.000\Asztal\alpha\BoxBlur.vdf")

black=BlankClip(length=1112,width=720,height=576,fps=50,color=$000000).ConvertToRGB32.KillAudio.ResetMask
white=BlankClip(length=1112,width=720,height=576,fps=50,color=$ffffff).ConvertToRGB32.KillAudio.ResetMask

# SUPERIMPOSES "v" (STILL 50 fps) ON THE NEW BACKGROUND CLIP. THE RESULT IS FRAMES 1,2,3,
# 4, ETC. AT 50 FPS.

c2v=Layer(b,v)

# SUPERIMPOSES EACH FIELD ON THE FOLLOWING FIELD. THE RESULT IS FRAMES 12,23,34,45,
# 56, ETC. AT 50 FPS.

c1v=Trim(c2v,1,0)
SeparateFields(c1v)
c3v=SelectEven
xv=SeparateFields(c2v)
c4v=SelectOdd(xv)
x2v=Interleave(c3v,c4v)
x3v=Weave(x2v)


# SUPERIMPOSES THE VIDEO "v" (STILL 50 fps) ON A WHITE BACKGROUND CLIP. WE ARE GOING TO
# MAKE A MOTION MAP AND ANY MOTION IN THE NEW BACKGROUND WOULD BE CONFUSED WITH
# MOTION OF THE OBJECT.

c2w=Layer(white,v)

# SUPERIMPOSES EACH FIELD ON THE FOLLOWING FIELD
c1w=Trim(c2w,1,0)

SeparateFields(c1w)
c3w=SelectEven
xw=SeparateFields(c2w)
c4w=SelectOdd(xw)
x2w=Interleave(c3w,c4w)
x3w=Weave(x2w)

# FIRST SMART DEINTERLACE

# THE ONLY WAY IT WORKED WAS TO RUN IT THROUGH BACKWARDS AND THEN REVERSE IT AGAIN AFTER
# THE DEINTERLACE. OTHERWISE WHEN I MADE THE MOTION MAP USING SMART DEINTERLACER? THE
# MOVING OBJECT WASN'T IN THE CENTER OF THE MAP. IT WAS TO ONE SIDE AND THIS MENT THAT
# LATER THE OBJECT WAS ONLY BLURED ON ONE SIDE.

Reverse(x3v)
x4=VD_SmartDeinterlace(mode="frame", channel="luma",show_motion=false,m_threshold=15,sc_threshold=100)
x4b=Reverse(x4)

# NOW WE DO THE SAME THING WITH "v" ON THE WHITE BACKGROUND. NB: show_motion=true
x5=Reverse(x3w)
x5b=VD_SmartDeinterlace(x5,mode="frame", channel="luma",show_motion=true,m_threshold=35,sc_threshold=100)
motion=Reverse(x5b)

# FURTHER WORK ON THE MOTION MASK. FIRST SET THE GREY AREAS (CORRESPONDING TO NO
# MOTION) TO BLACK.

ResetMask(motion)
x6=ColorKeyMask($7f7f7f,5)
x7=Layer(black,x6)

# THEN SET THE MOTION AREAS TO WHITE
x8=ResetMask(x7)
x9=ColorKeyMask(x8,$ffffff,250)
x10=Layer(white,x9)

#BoxBlur(x10,radius=13,power=3)
# UNFORTUNATELY, THE ABOVE FILTER DOESN'T EXIST YET. SO, IN THE MEANTIME WE HAVE TO RETURN
# x10, OPEN THE AVS FILE IN VirtualDub, SET THE BOX BLUR FILTER, AND FRAMESERVE
# "mask13.3.vdr" BACK TO HERE. THIS SMOOTHS OUT THE MASK.

mask133=AVISource("C:\WINDOWS.000\Asztal\alpha\mask13.3.vdr").ConvertToRGB32.ResetMask

#BoxBlur(x4,radius=9,power=1)
# DETTO AS REGARDS FRAMESERVING FROM VirtualDub. THIS BLURES THE ENTIRE "v" ON
# THE NEW BACKGROUND, "b".
b1=AVISource("C:\WINDOWS.000\Asztal\alpha\blur9.1.vdr").ConvertToRGB32.ResetMask

# NOW WE SET ALL THE NON-MOTION AREAS OF THE COMPOSITE TO TRANSPARENT
b2=Mask(b1,mask133)

# AND SUPERIMPOSE THE RESULT ON THE NON BLURED COMPOSITE.
video2=Layer(x4b,b2,level=blend)

# WE ARE STILL AT 50 FPS, SO DOWN TO 25 FPS.
# FIRST WE SQUEEZE THE FRAMES DOWN TO FIELD SIZE
BicubicResize(video2,720,288)
AssumeFieldBased

# INTERLEAVE THE FIELDS
v3=Weave

# AND PERFORM THE FINAL DEINTERLACE
video3=VD_SmartDeinterlace(v3,mode="frame", channel="luma",show_motion=false,m_threshold=15,sc_threshold=100)
return video3
}
######################################################################
# NOW THAT WE HAVE FINISHED DEFINING THE FUNCTION, WE CAN ACTUALLY
# USE IT.

# HERE WE COULD IMPORT MotionBlurBlend, BUT SINCE IT'S ALREADY HERE, # NO NEED TO.
#Import("C:\Program Files\AviSynth 2.5\plugins\MotionBlurBlend.avs")

# HERE WE OPEN THE BACKGROUND VIDEO.
s1=AviSource("c:\png\background.avi")

#THIS IS THE VIDEO TO BE PROCESSED.
s0=AviSource("c:\png\object.avi")

MotionBlurBlend(s0,s1,200)

Last edited by t_2; 16th May 2003 at 10:26.
t_2 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 13:30.


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