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 22nd September 2009, 20:52   #1  |  Link
madhatter300871
Registered User
 
Join Date: Nov 2005
Posts: 255
Help with my first script please

Hi

A question I know you have all heard 1000 times before ! Please can you help me, I'm not fully grasping avisynth scripting.... and know the penny will drop once i've written one or two basic scripts. I'm pretty good with VB so not a novice to programming ..... I hope !

So, I want to check the current frame, see if it is a multiple of 100, if it is then output a frame grab..

I dont want to use selectevery, as this does nothing with all the other frames.

I want to do this :-

myvariable=current_frame
if myvariable/100 = ceil(myvariable/100) then ImageWriter(the current frame)

so while processing the video, every 100th frame will be output to an image.

Problem is I'm being a bit thick and can't get my head around the avisynth scripting. I know how to capture frames and output them to a .bmp. I think what I want is :-

current_frame/100 = ceil (current_frame/100) ? ImageWriter(etc etc.)

Please help !!!!

Many thanks.
madhatter300871 is offline   Reply With Quote
Old 22nd September 2009, 21:22   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
To do something different depending on properties of individual frames (including their frame number), you need to use ConditionalFilter.

images = ImageWriter(...)
ConditionalFilter(images, last, "current_frame%100", "=", "0")

See also this page.
Gavino is offline   Reply With Quote
Old 22nd September 2009, 21:30   #3  |  Link
g-force
Guest
 
Posts: n/a
Quote:
Originally Posted by madhatter300871 View Post
I dont want to use selectevery, as this does nothing with all the other frames.
I don't understand this statement. Can you better expalin why something like "SelectEvery(100,100)" doesn't work for you?

-G
  Reply With Quote
Old 22nd September 2009, 22:01   #4  |  Link
madhatter300871
Registered User
 
Join Date: Nov 2005
Posts: 255
Hi

SelectEvery(100,100) doesnt work because I want to encode some video AND also grab every 100th frame.

Using select every does just that... selects every 100th frame. So I'll only be encoding every 100th frame also.

Am I wrong ??
madhatter300871 is offline   Reply With Quote
Old 22nd September 2009, 22:23   #5  |  Link
madhatter300871
Registered User
 
Join Date: Nov 2005
Posts: 255
Hi again

I'm not grasping the basics am I !!


My script is :-

video=Mpeg2source("D:\MPEGproject\sincity\vts_01_1.d2v")
image=ImageWriter(video, file="d:\mpegproject\caps\cap", start=current_frame, end=current_frame)
ConditionalFilter(video, image, video, "current_frame/100", "<", "ceil(current_frame/100)")

....and I've tried other things very similar, I just cant get it to work.

Is it possible to use select every ASWELL as processing every frame, say in a user function.
madhatter300871 is offline   Reply With Quote
Old 22nd September 2009, 23:28   #6  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
The variable current_frame is only defined inside the run-time environment - see references I gave.
Do it like this:

image=ImageWriter(video, file="d:\mpegproject\caps\cap")

Then the ConditionalFilter will select the appropriate frames to be rendered to the file.

BTW what was wrong with using current_frame%100 = 0 ?
That should be a bit faster.

Last edited by Gavino; 22nd September 2009 at 23:33.
Gavino is offline   Reply With Quote
Old 23rd September 2009, 00:10   #7  |  Link
madhatter300871
Registered User
 
Join Date: Nov 2005
Posts: 255
Gavino, thanks for your help ....

My script is now :-

video=Mpeg2source("D:\MPEGproject\sincity\vts_01_1.d2v")
image=ImageWriter(video.ConvertToRGB(), file="d:\mpegproject\caps\cap", type="jpg")
ConditionalFilter(video, image, video.ConvertToRGB(), "current_frame/1000", "equals", "Ceil(current_frame/1000)")

..I'm begining to understand how this works....slowly....

However, my script now makes a screen grab of every frame ... not just every 1000th frame. Does my conditional filter not say "return image when the current frame / 1000 = rounded up current frame / 1000 ?? Only every 1000th frame / current frame will be a whole number, this is my thinking.
madhatter300871 is offline   Reply With Quote
Old 23rd September 2009, 00:26   #8  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Since current_frame is an integer, so is current_frame/1000 - integer division is used, not floating-point. So your test always returns true!

I told you to use the 'mod' test instead.
(But I should have spotted that your version was not only untidy, but wrong.)
Gavino is offline   Reply With Quote
Old 23rd September 2009, 07:47   #9  |  Link
madhatter300871
Registered User
 
Join Date: Nov 2005
Posts: 255
Gavino, thanks for pointing this out.

I'de like to reiterate the fact that I'm new at this and trying to learn, that's why I have turned to the forum. I know my method might be ugly and I know it might be wrong but again, that's why I have turned to a forum.

I'm looking for help and guidance. I'm looking to have my hand held through my first script or two until I get into the swing of things.

I'm not thick, I can read, I have found the online documentation, I have read through some of this forum and others. I'm sure you agree that it can take a while to plough through documentation, wiki's and forums to find what you want. But again, I find my self wanting some guidance through my first couple of scripts.

I hope you can be patient with me if you decide you will still reply to my posts and try to help.

I didn't try the mod test, I don't know what it is.

I know about floating point numbers and integer numbers but I don't understand the notation used in avisynth. I presume the mode test is "current_frame%100" = 0. What does the % do ? How does the construction of this make it a mod test ? Can you guide me to documentation on the mathematical notation that avisynth uses, I'm keen to learn.

I also tried ... current_frame > 1000 ? ImageWriter(video, file="d:\mpegproject\caps\cap", start=current_frame, end=current_frame) ... to print the frames after 1000 but an error message indicates my line is wrong. So.... I'm having difficulty with the notation that avisynth uses.

Thanks for the replies so far.

Last edited by madhatter300871; 23rd September 2009 at 07:51.
madhatter300871 is offline   Reply With Quote
Old 23rd September 2009, 09:05   #10  |  Link
foxyshadis
Angel of Night
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Tangled in the silks
Posts: 9,559
x%y is shorthand for "The remainder of x/y", so it's only 0 every cycle of y. Thus you'd use Conditionalfilter(....,"current_frame%100","equals","0")

It's very ugly, you might just want to look at stickboy's ApplyEvery.
foxyshadis is offline   Reply With Quote
Old 23rd September 2009, 09:56   #11  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
Quote:
Originally Posted by madhatter300871 View Post
Hi

SelectEvery(100,100) doesnt work because I want to encode some video AND also grab every 100th frame.

Using select every does just that... selects every 100th frame. So I'll only be encoding every 100th frame also.

Am I wrong ??
That's true, but it's also easy to do two passes. (That is, encode your video, and then use a second script to grab every 100th frame from the new video.)
stickboy is offline   Reply With Quote
Old 23rd September 2009, 10:22   #12  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by madhatter300871 View Post
I hope you can be patient with me if you decide you will still reply to my posts and try to help.
Sure. We were all novices once.
Quote:
I know about floating point numbers and integer numbers but I don't understand the notation used in avisynth. I presume the mode test is "current_frame%100" = 0. What does the % do ? How does the construction of this make it a mod test ? Can you guide me to documentation on the mathematical notation that avisynth uses, I'm keen to learn.
foxyshadis has explained the % (mod, or modulus) operator.
For the full list of operators, see here.
Quote:
I also tried ... current_frame > 1000 ? ImageWriter(video, file="d:\mpegproject\caps\cap", start=current_frame, end=current_frame) ... to print the frames after 1000 but an error message indicates my line is wrong. So.... I'm having difficulty with the notation that avisynth uses.
As I said, the 'current_frame' variable can only be used inside the Run-time environment, so you need to use ConditionalFilter. This is one of the more difficult areas of Avisynth, so you are jumping in at the deep end here. It would probably be simpler to follow stickboy's suggestion and do the encoding and frame saving in separate scripts.

@foxyshadis: ApplyEvery won't work here because each frame selected will have the same frame number and overwrite the same file.
Gavino is offline   Reply With Quote
Old 23rd September 2009, 18:24   #13  |  Link
madhatter300871
Registered User
 
Join Date: Nov 2005
Posts: 255
Thanks guys. I have had a look at the links, got a better understanding of the mathematical operators and am looking at the ApplyEvery script......

I'll post what I end up doing just for completeness sake.

Many thanks.
madhatter300871 is offline   Reply With Quote
Old 23rd September 2009, 18:51   #14  |  Link
madhatter300871
Registered User
 
Join Date: Nov 2005
Posts: 255
It works as you suggested.

video=Mpeg2Source( source)
image=ImageWriter(video.ConvertToRGB(), file="filename", type="jpg")
ConditionalFIlter(video,image,video.ConvertToRGB(), "current_frame%1000", "equals", "0")

So, if I simply play this in a media player the movie playes and every 1000th frame is captured to a jpg as we go.

One more question, I can't figure this out by sight ... When the conditional filter returns the imagewriter every 1000th frame, is the media player actually skipping a frame ? So does the conditional filter only return one of either source1 or source2 ?

Thanks.
madhatter300871 is offline   Reply With Quote
Old 23rd September 2009, 19:34   #15  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by madhatter300871 View Post
When the conditional filter returns the imagewriter every 1000th frame, is the media player actually skipping a frame ? So does the conditional filter only return one of either source1 or source2 ?
Yes, it returns only one, either source1 or source2 depending on the condition (which varies from frame to frame, of course).

But since ImageWriter, as well as writing to the file, also returns the clip itself, all frames are passed on to the media player (one way or the other) and nothing is skipped.
Gavino is offline   Reply With Quote
Old 24th September 2009, 08:36   #16  |  Link
madhatter300871
Registered User
 
Join Date: Nov 2005
Posts: 255
Thanks guys.

Well I've got my first script working, albeit not a very interesting script, some may argue it's not really a script at all. But I have gained a much better understanding of how to script, how the operators work, the sequence of work flow through the script and the idea of returning a clip.

I'm going to have a go at making a function next, maybe just put my conditional filter in a function and call it from my script to get started.

Thanks for the help so far.
madhatter300871 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 08:28.


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