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 13th October 2008, 14:17   #1  |  Link
zee944
Registered User
 
Join Date: Apr 2007
Posts: 240
How to get current frame number in AviSynth?

Can anyone tell me how can I have the current frame number in AviSynth?

Within ScriptClip command, I can display it such as:

Code:
ScriptClip("subtitle(string(current_frame))")
...but AviSynth doesn't recognize a stand-alone 'current_frame'.

What I actually want to do is to increase saturation from zero to maximum during playback. The first frame is B&W, the last has the original saturation. If 'current_frame' would work, my line would look like this:

Code:
Tweak(sat=(current_frame/FrameCount)*1.00)
Could anybody help?
zee944 is offline   Reply With Quote
Old 13th October 2008, 15:07   #2  |  Link
Sagekilla
x264aholic
 
Join Date: Jul 2007
Location: New York
Posts: 1,752
Try animate:

Code:
ColorBars().ConvertToYV12()
src = last
start_frame = 0
end_frame = 99

src.Animate(start_frame,end_frame, "Tweak", 0,0.0, 0,1.0)
__________________
You can't call your encoding speed slow until you start measuring in seconds per frame.
Sagekilla is offline   Reply With Quote
Old 13th October 2008, 15:16   #3  |  Link
J_Darnley
Registered User
 
J_Darnley's Avatar
 
Join Date: May 2006
Posts: 957
Cast the frames to floats so that you don't use integer division and then put it all in a ScriptClip().
ScriptClip( "Tweak( sat=( float(current_frame)/float(FrameCount) )*1.0 )" )
__________________
x264 log explained || x264 deblocking how-to
preset -> tune -> user set options -> fast first pass -> profile -> level
Doom10 - Of course it's better, it's one more.
J_Darnley is offline   Reply With Quote
Old 13th October 2008, 16:11   #4  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by zee944 View Post
...but AviSynth doesn't recognize a stand-alone 'current_frame'
current_frame is only visible within the run-time environment provided by filters such as ScriptClip.

Hence J_Darnley's solution is closest to your original idea (though clearly the 1.0 is redundant). However, for a case like this, I prefer Sagekilla's approach with Animate.
Gavino is offline   Reply With Quote
Old 13th October 2008, 21:54   #5  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Code:
MergeChroma(FadeIn0(100))
IanB is offline   Reply With Quote
Old 14th October 2008, 14:44   #6  |  Link
zee944
Registered User
 
Join Date: Apr 2007
Posts: 240
Quote:
Originally Posted by J_Darnley View Post
ScriptClip( "Tweak( sat=( float(current_frame)/float(FrameCount) )*1.0 )" )
Thank you for all of you. This one worked damn perfectly, so I didn't even try the others!
zee944 is offline   Reply With Quote
Old 14th October 2008, 23:06   #7  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
The other approaches are better...
stickboy is offline   Reply With Quote
Old 14th October 2008, 23:15   #8  |  Link
Sagekilla
x264aholic
 
Join Date: Jul 2007
Location: New York
Posts: 1,752
If you look at it speedwise, I believe IanB's would be the fastest. A copy of the chroma channel is faster than multiplying the saturation by some float (which is calculated based on what frame you're on and the total frame count, another calculation) I think.


I think all methods are fast enough that decoding is slower still, though.
__________________
You can't call your encoding speed slow until you start measuring in seconds per frame.
Sagekilla is offline   Reply With Quote
Old 15th October 2008, 07:30   #9  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
IanB's is also the most AviSynth-like.

The ScriptClip way encourages wrong thinking.
stickboy is offline   Reply With Quote
Old 16th October 2008, 05:35   #10  |  Link
Sagekilla
x264aholic
 
Join Date: Jul 2007
Location: New York
Posts: 1,752
Not to mention the most elegant for that matter, No need to futz around with worrying about types or anything. Just two function calls
__________________
You can't call your encoding speed slow until you start measuring in seconds per frame.
Sagekilla is offline   Reply With Quote
Old 3rd December 2008, 13:14   #11  |  Link
blausand
Registered User
 
blausand's Avatar
 
Join Date: Mar 2007
Posts: 15
chasing the current_frame...

To be honest, the absence of current_frame still really gets me down from time to time. And stickboy, i agree that all of these Scriptclip-solutions feel conceptually wrong whenever i hassle around with them.

look at this:
Code:
clp = AVISource("some.avi")
import("someNumberedStrings.txt")

index = ((current_frame+3) % 20) > 10 ? int(current_frame/20) : 0

topSlate = Eval("topslate_"+string(index, "%03d"))
bottomSlate = Eval("bottomslate_"+string(index, "%03d"))

subtitle(bottomSlate, align=2)
subtitle(topSlate, align=8)
I need some math-munging to evaluate the right slates. Then i tried to put everything in a function.
Both approaches yield the error: "I don't know what 'current_frame' is."

I also tried to relate current_frame to a clip: clp.current_frame, and that yields:
"There's no function named 'current_frame' "
And even wrapping everything in FrameEvaluates didn't solve anything.
Is there no workaround to get a current_frame integer based on a specified clip?
blausand is offline   Reply With Quote
Old 3rd December 2008, 14:31   #12  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by blausand View Post
Is there no workaround to get a current_frame integer based on a specified clip?
It normally makes no sense to talk of the 'current' frame of a clip because Avisynth deals in complete clips, not individual frames.

The only place it does makes sense is inside a "run-time" script as processed by ScriptClip, as these are (re-)evaluated for every frame of their surrounding 'normal' script. Even here, the processing required can most often be done without caring what the actual frame number is.

See here for an example of how to solve your problem using ConditionalReader.

Last edited by Gavino; 3rd December 2008 at 14:38. Reason: ConditionalReader pointer
Gavino is offline   Reply With Quote
Old 3rd December 2008, 20:16   #13  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
Quote:
Originally Posted by blausand View Post
To be honest, the absence of current_frame still really gets me down from time to time. And stickboy, i agree that all of these Scriptclip-solutions feel conceptually wrong whenever i hassle around with them.
Code:
...
subtitle(bottomSlate, align=2)
subtitle(topSlate, align=8)
I need some math-munging to evaluate the right slates. Then i tried to put everything in a function.
Both approaches yield the error: "I don't know what 'current_frame' is."

I also tried to relate current_frame to a clip: clp.current_frame, and that yields:
"There's no function named 'current_frame' "
And even wrapping everything in FrameEvaluates didn't solve anything.
Is there no workaround to get a current_frame integer based on a specified clip?
Why do you need current_frame at all? Why not use ApplyRange?
stickboy is offline   Reply With Quote
Old 3rd December 2008, 21:19   #14  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by stickboy View Post
Why do you need current_frame at all? Why not use ApplyRange?
ApplyRange won't do it easily because he wants the thing to be dynamic.
But it could be done with Animate something like this:
Code:
function DoTitles(clip c, int index) {
  topSlate = Eval("topslate_"+string(index, "%03d"))
  bottomSlate = Eval("bottomslate_"+string(index, "%03d"))
  c
  subtitle(bottomSlate, align=2)
  subtitle(topSlate, align=8)
}

import("someNumberedStrings.txt") # needs to declare strings global
nTitles = ... # no of titles 
start = ... #start frame
end = ... #end frame
clp = AVISource("some.avi")

Animate(clp, start, end, "DoTitles", 1, nTitles)
@blausand
Instead of thinking in terms of current_frame, it is usually better to use a built-in filter that produces a dynamic effect, eg Animate, FadeIn, Dissolve, etc.
Gavino is offline   Reply With Quote
Reply

Tags
current_frame, scriptclip

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 10:16.


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