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. |
13th October 2008, 14:17 | #1 | Link |
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))") 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) |
13th October 2008, 15:07 | #2 | Link |
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. |
13th October 2008, 15:16 | #3 | Link |
Registered User
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. |
13th October 2008, 16:11 | #4 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,437
|
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. |
14th October 2008, 23:15 | #8 | Link |
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. |
16th October 2008, 05:35 | #10 | Link |
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. |
3rd December 2008, 13:14 | #11 | Link |
Registered User
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) 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? |
3rd December 2008, 14:31 | #12 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,437
|
Quote:
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 |
|
3rd December 2008, 20:16 | #13 | Link | |
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
Quote:
|
|
3rd December 2008, 21:19 | #14 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,437
|
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) 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. |
Tags |
current_frame, scriptclip |
Thread Tools | Search this Thread |
Display Modes | |
|
|