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 Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 20th March 2004, 01:43   #1  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,268
stickboy's AviSynth plug-ins

Okay, I've made some really rudimentary AviSynth plug-ins. I've mentioned a couple of them in passing in some other threads, but I haven't said much about them.


SelectByString

A function that's similar to the built-in Select function but that operates on strings. (If you're familiar with other programming languages, it can provide functionality similar to a switch statement or to an associative array.)

Examples:
Code:
SelectByString("jubjub", 
\              "tove", 0, 
\              "borogove", 1,
\              "jubjub", 2,
\              "jabberwock", 3)
would return 2.

Obviously, it's more useful if the search string is a variable:
Code:
function ColorNameToRGB(string colorName)
{
    return SelectByString(colorName,
    \                     "white", $FFFFFF,
    \                     "black", $000000,
    \                     "red",   $FF0000,
    \                     "green", $00FF00,
    \                     "blue",  $0000FF)
}
A SelectByStringEval function also is included, which is shorthand for Eval(SelectByString(...))

And, of course, these functions can be useful for making wrapper functions with presets.


Min/Max

Basic Min/Max functions that can take a variable number of arguments. Arguments can be integers or floats and even can be mixed, if so desired. Not much to say here.


Threshold/Core [YUY2, RGB24, RGB32]

Basic (and unoptimized) threshold and coring functions. Threshold maps all pixels darker than a specified threshold value to pure black and the rest to pure white.

Core is similar; it maps all pixels darker than a specified threshold value to pure black and leaves the rest untouched.


Shuffle

Randomly shuffles the frames in a clip. Yeah, it's useless, but it can be used to make some mildly interesting effects. (See the included script of examples.)


DeleteEvery/DeleteFrames

Functions that facilitate deletion of multiple frames. DeleteEvery complements SelectEvery; SelectEvery(4, 0, 1, 2) is equivalent to DeleteEvery(4, 3). Again, not too useful, but I remember there have been some cases where people have wanted to delete, say, 1 frame of every 1000, which is impractical for SelectEvery.

DeleteFrames--not surprisingly--is a version of the built-in DeleteFrame function that can handle multiple frames. Calling DeleteFrame multiple times is:
  • tedious
  • inefficient
  • error-prone, since the order of DeleteFrame calls matters


Source code to everything is included under a BSD-style license.

Last edited by Guest; 10th October 2007 at 02:24. Reason: rule 4
stickboy is offline   Reply With Quote
Old 20th March 2004, 16:46   #2  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
bravo!!

deleteevery is just the thing for PAL telecine with duped frames (r4 fight club)

[edit]

and shuffle could be made a _little bit_ more useful if you could select random chunks of several frames rather than just single frames.

i did something like that with a script when i was helping a friend make a grindcore video. lots of gore footage selected randomly in 5 frame chunks (that coincided with the double-kick). huge time-saver to do it that way rather than make a million cuts in premiere, i can tell you :|
__________________
sucking the life out of your videos since 2004

Last edited by Mug Funky; 20th March 2004 at 16:48.
Mug Funky is offline   Reply With Quote
Old 20th March 2004, 17:22   #3  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,605
[quote] PAL telecine with duped frames[/qoute]

Please tell me more!

Sounds interesting.
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 20th March 2004, 18:21   #4  |  Link
DDogg
Retired, but still around
 
DDogg's Avatar
 
Join Date: Oct 2001
Location: Lone Star
Posts: 3,058
Just a thought, but if each of the advanced script writers would post a similar guide to their work in this thread, then eventually, it could be edited, renamed and potentially made sticky. We do need a way to consolidate all this great work you guys are doing and this may be a simple way to do it.
DDogg is offline   Reply With Quote
Old 20th March 2004, 21:39   #5  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,268
Quote:
Originally posted by Mug Funky
and shuffle could be made a _little bit_ more useful if you could select random chunks of several frames rather than just single frames.
I'm not quite sure what you mean. Could you provide an example? (i.e., if you have frames 0 1 2 3 4 5 ..., then how do you want them rearranged?) There's a "groupSize" parameter to Shuffle, but I'm not sure if that does what you want.
stickboy is offline   Reply With Quote
Old 21st March 2004, 01:40   #6  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,268
New plug-in: ApplyEvery

ApplyEvery

A generalized function that can apply a specified function at regular intervals in a clip. DeleteEvery can be viewed as a specialized version; DeleteEvery(100, 0) is conceptually equivalent to ApplyEvery(100, "DeleteFrame(0)"). (In practice, DeleteEvery is much more efficient, so if you're only deleting frames, use that. Plus, DeleteEvery modifies the frame-rate appropriately.)

This is basically a straight conversion of my JDL_ApplyEvery user-defined function to an AviSynth plug-in.

I tried the following script with my user-defined version:
Code:
BlankClip(length=2100, pixel_type="yuy2")
ShowFrameNumber()
JDL_ApplyEvery(4, "Reverse()")
On my system, the user-defined version can iterate about 525 times (2100 / 4) without crashing; increasing the source clip's frame count by one causes VirtualDub+AviSynth to crash silently.

If I substitute in the plug-in version, I can increase the clip length to over 80000. (That's 20000+ iterations, a ~40-fold increase.) A script with that many iterations is slow to load, however.

This is an experimental, quick-and-dirty build; source currently isn't included but will be forthcoming eventually, after I ponder some possible improvements.

Last edited by stickboy; 31st March 2004 at 23:25.
stickboy is offline   Reply With Quote
Old 21st March 2004, 03:17   #7  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
ApplyEvery!!!

Now, this is great! ... but a year too late

By that time, I had a clip with a logo consisting of the word "pop" in small letters, that was slowly travelling its way around a big imaginary circle.
I ended up in breaking the circumfang in 10 or 12 pieces, made a "delogo" function for each of these fractions, and then fiddled something together with the "select" function and conditional filtering acc. to framecount.

That would've been a job for ApplyEvery ...

Thanks for "centralizing" your functions, stickboy.

- Didée
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 22nd March 2004, 05:56   #8  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
@scharfis_brain - it's nothing spectacular... just a matter of duping 1 in 25 frames and not touching the audio. sadly i've only seen it used once.

i've noticed sped-up audio discs often transcode the audio from the NTSC version! this completely breaks any transparency the audio once had. (if you can get hold of r4 "being john malkovich" you'll hear the opening applause is riddled with pre-echo and stereo collapse)
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 1st April 2004, 03:37   #9  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,268
New ApplyEvery version up.

I merged my ApplyEvery and DeleteEvery plug-ins and added a new function: InterleaveEvery.

InterleaveEvery is yet another almost useless function, but I felt that it was needed for completeness.

InterleaveEvery can undo the work of SelectEvery + DeleteEvery. If you use SelectEvery and DeleteEvery to pull some frames out, InterleaveEvery can put them back in:
Code:
src = AVISource( ... )

# pull out some frames
subClip = src.SelectEvery(5, 0, 1)
src = src.DeleteEvery(5, 0, 1)

# inject the frames back in
src.InterleaveEvery(subClip, 5, 0, 1)
(The above example is basically a convoluted no-op.)

But, if you wanted to, say, invert the first two frames of every group of five, InterleaveEvery makes it easy to do that. (Not that anyone would want to do that, of course...)

Or maybe it could be used to insert subliminal messages. Or something.

Last edited by stickboy; 1st April 2004 at 03:59.
stickboy is offline   Reply With Quote
Old 24th December 2004, 23:19   #10  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,268
RemapFrames

I neglected to announce this here before, but I made another plug-in: RemapFrames.

RemapFrames provides general control over manipulation of frame indices in a clip.

It doesn't affect the audio track. I still haven't figured out a good way to deal with audio, but it's intended to be an alternative to long chains of FreezeFrame and DeleteFrame calls, which touch up individual frames and which also don't affect the audio.

Anyhow, today I hacked in a new function to RemapFrames: ReplaceFramesSimple.

On a number of occasions I've done things like:
Code:
c = src.Telecide(...).Decimate(...)

# Oops.  Some frames are still combed, and I don't want to
# post-process the entire clip.
ApplyRange(100, 110, "SomeDeinterlacer")
ApplyRange(200, 200, "SomeDeinterlacer")
ApplyRange(250, 250, "SomeDeinterlacer")
ApplyRange(300, 310, "SomeDeinterlacer")
With ReplaceFramesSimple, this can be done more efficiently and more cleanly:
Code:
c = src.Telecide(...).Decimate(...)
deinterlaced = c.SomeDeinterlacer()

ReplaceFramesSimple(c, deinterlaced,
\                   mappings="[100 110] 200 250 [300 310]")
The syntax probably could use a little bit more work, and the right now documentation has a lot to be desired. Oh well.
stickboy is offline   Reply With Quote
Old 13th January 2007, 22:55   #11  |  Link
chipzoller
Mr. Woof
 
chipzoller's Avatar
 
Join Date: Jan 2002
Location: USA
Posts: 784
stickboy, I'd like to use applyrange to isolate 2 sections in my clip, but I also need to IVTC the clip (VHS capture). Your warning in the script says I shouldn't use applyrange along with anything that alters frame count, so then what should I use? Trim isn't very reliable from what I've read although I'm no expert.

How should I proceed? Can I just find the decimated frame range and use those numbers, calling jdl_applyrange after IVTC?

Last edited by chipzoller; 13th January 2007 at 23:52.
chipzoller is offline   Reply With Quote
Old 14th January 2007, 11:38   #12  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,268
I don't understand what you want to do. What do you want to use JDL_ApplyRange (or the internal ApplyRange) for? What are you doing that with it that will affect the frame count?

The filter you apply with JDL_ApplyRange shouldn't affect the frame count. You can do whatever you want to the clip before or after calling JDL_ApplyRange, though.

That said, it's probably a better idea to do IVTC early on so you don't waste time filtering frames that will be removed, and then figure out the appropriate frame numbers to give to ApplyRange/JDL_ApplyRange/whatever in the IVTC'd clip.

BTW, why isn't Trim reliable? If you're referring to my Caveats about using Trim in functions thread, then you've misunderstood.
stickboy is offline   Reply With Quote
Old 14th January 2007, 11:59   #13  |  Link
guada2
Registered User
 
Join Date: Jun 2005
Location: Lyon
Posts: 194
good job man.
guada2 is offline   Reply With Quote
Old 14th January 2007, 14:39   #14  |  Link
chipzoller
Mr. Woof
 
chipzoller's Avatar
 
Join Date: Jan 2002
Location: USA
Posts: 784
I have a capture that the intro and credits are animated and the middle is live action. I want to use applyrange to filter the intro. and credits separately from the live action section, but at the same time, the capture needs to be IVTCd. This thread may better explain.
chipzoller is offline   Reply With Quote
Old 14th January 2007, 20:30   #15  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,268
Yeah, just IVTC first and use ApplyRange afterward.

Or actually, in this case, just using Trim directly is probably more straightforward:
Code:
intro = Trim(0, 1000).IVTC().OtherFilters()
rest = Trim(1001, 0).IVTC()

intro + rest
stickboy is offline   Reply With Quote
Old 10th October 2007, 00:54   #16  |  Link
blausand
Registered User
 
blausand's Avatar
 
Join Date: Mar 2007
Posts: 15
Good Morning, Stickboy!

I've been happy for about three days now, that i have found a solution for re-arranging frames algorithmically - with your RemapFrames function.
Unfortunately, the function does not eat the three parameters, as the following script earns a "Invalid arguments to function RemapFrames":
Code:
dur=1200
src2 = aviSource("an .AVI")
target = BlankClip(src2)
target.lengthenClip(dur).ShowFrameNumber()
#return src2 will work!
#RemapFrames(target, filename = "D:\Code\Avisynth\gfa.Frames.vsc", src2) #as well as
RemapFrames(src2, filename = "D:\Code\Avisynth\gfa.Frames.vsc", target)
# yield the error "Invalid Arguments"
Apart from this Problem i'm having:
I need to extend these functions you wrote, if you could give me some advise:
  1. Time-stretched portions of the Remap should be blended somehow. Maybe by calling another function for each frame with the two srcFrames and opacity-"weights" for blending?
  2. A function like RemixClips should allow for selecting which clip, that is to be remapped. Example:
    Code:
    [srcRange] clipNameWithoutQuotMarks [destRange]
    [0 15] src2fx0 [0 15]
    [16 31] src2fx1 [63 32]
    [32 48] src2fx2 [0 15]
    [49 63] src2fx3 [63 0]
Anyway, great work in that stuff! Hope to meet you in the code one day!
blausand
Attached Images
 
blausand is offline   Reply With Quote
Old 10th October 2007, 22:37   #17  |  Link
blausand
Registered User
 
blausand's Avatar
 
Join Date: Mar 2007
Posts: 15
Bug in LengthenClip() regarding c.framecount?

Quote:
Originally Posted by stickboy View Post
(Not that anyone would want to do that, of course...)
Don't say that! It seems that your work is quite valueable to a small community (me, in fact?) of video artists.
Regarding the malfunction mentioned above:
It seems that RemapFrames does not insert last
automatically when the first argument is omitted. To double-check, i use 'optional parameter notation' allover now.
The error changed to "Value out of bounds" when i used "pure argument notation" and that turned out to be an error within LengthenClip(). LengthenClip() does not correct the clip property "framecount", as the following screenshot wants to make me believe:
Attached Images
 

Last edited by blausand; 10th October 2007 at 22:40.
blausand is offline   Reply With Quote
Old 10th October 2007, 23:34   #18  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,268
Quote:
Originally Posted by blausand View Post
Good Morning, Stickboy!
Unfortunately, the function does not eat the three parameters, as the following script earns a "Invalid arguments to function RemapFrames":
Hm, RemapFrames has four parameters...

Quote:
Code:
RemapFrames(src2, filename = "D:\Code\Avisynth\gfa.Frames.vsc", target)
# yield the error "Invalid Arguments"
But that's because you tried to pass "target" for the "mappings" string. Try:
Code:
RemapFrames(src2, filename="D:\Code\Avisynth\gfa.Frames.vsc", sourceClip=target)
When used this way, it should use the "implicit last" clip if the first argument is omitted. Let me know if that works or not.
Quote:
LengthenClip() does not correct the clip property "framecount"
Hm, looking at its source code, it should. It does set vi.num_frames in its constructor. I'll double-check when I get to a computer that has AviSynth installed. Can you post the current version of your script? In the original version of the script you posted, none of the clips you passed in (src2 nor target) were lengthened to 1200 frames; only 'last' was.

Last edited by stickboy; 10th October 2007 at 23:41.
stickboy is offline   Reply With Quote
Old 11th October 2007, 17:09   #19  |  Link
blausand
Registered User
 
blausand's Avatar
 
Join Date: Mar 2007
Posts: 15
clip.function() does not alter clip...

at least [me] thought, the object.function semantic operates destructive per default.
It took me some effort to understand this:
Code:
target.LengthenClip(new_duration)
target = target.LengthenClip(new_duration)
While the first line does not alter target,
i have to make an explicit assignment, as in the second line.
If you look at my second ScreenShot, you'll see a proof of inconsistency, though.
Anyway, i think that this behaviour should be emphasized in any introductory or tutorial text;

I'd personally prefer to work with last, making one operation per line, but working with several clips and using last complicates commenting in and out single lines of code. How can i finish every clip-editing block with an assignment line? The following ends with "Not a Clip" error:
E.g.:
Code:
LoadPlugin("C:\Programme\MEDIA\AviSynth 2.5\PlugIns\ApplyEvery.dll") 
# (necessary because Avisynth didn't register my custom installation path correctly ;( #

#### CLIP1 ####
aviSource("src0.AVI", pixel_type = "RGB32") 
BilinearResize(320,240)
Mask(Levels(last, 126,1.0,128, 0, 255))
ShowFrameNumber()
LengthenClip(1200)
CLIP1 = last
Stickboy, Sorry for the inconvenience! Keep the good work up!
blausand

Last edited by blausand; 11th October 2007 at 17:32.
blausand is offline   Reply With Quote
Old 11th October 2007, 17:40   #20  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,175
You have to use CLIP1 or return CLIP1 as the last line of your script; avisynth doesn't like assignments as the last line for some reason, even when there is a logical last.

And yeah, avisynth is designed so that a source clip is never modified, although it may be lost (and internally, a source may be modified/overwritten if it's never reused in script).
__________________
There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order. ~ Ed Howdershelt
foxyshadis 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 00:21.


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