View Full Version : Displaying Frame #'s
Ejoc
12th October 2003, 01:38
First off I know about ShowFrameNumber() and ShowFrameSMPTE(). But I dont like their outputs.
What I want to do is basicly have a function I would call like this:
BetterShowFrame("Optional Text",x,y)
It would mirror subtitle() but tack on the frame number and/or time.
Because of the editing I want to do, I need to be able to place the current frame count in different places on the screen. That way I can have frame counts for the clips, and an overall frame count for the whole project.
I'm sure this is not hard, I just havent use AVISynth to make new functions.
Thanks
Manao
12th October 2003, 09:14
You should read the documentation given with Avisynth. You would wee that there isn't only filters in avisynth, but also functions which give access to the parameters of the clip ( width, height, framecount.. ).
So you just have to use something like that :
Clip = MPEG2Source("foo.d2v")
return Subtitle(String(Framecount(clip),...)
sh0dan
12th October 2003, 09:56
@Manao: Your script will only display the total framecount.
Use:
ScriptClip("subtitle(string(current_frame))")
- adjust as you see fit.
Manao
12th October 2003, 10:10
Oops, my bad. In that case, I'll make an apology for the rudeness of my previous post because I didn't find the current_frame in the documentation :rolleyes:
neily
12th October 2003, 10:17
@sh0dan,
I apologise, but I was someone who pestered you before about giving ShowFrameNumber() more formatting options, and at the time you said it was on your to do list. Does your reply mean that this is no longer the case? I guess it is not a high priority.
sh0dan
12th October 2003, 12:43
http://sourceforge.net/tracker/?atid=482676&group_id=57023&func=browse
Ejoc
12th October 2003, 16:15
Thanks all. I was searching alot yesterday, and never came across that current_frame variable, which will easily solve my needs. Thanks again.
Ejoc
12th October 2003, 19:01
So I finally got what I wanted, here's how I did it:
function MyFrameTimeNumber(clip c,string s,int x,int y,bool show_time,bool show_frame)
{
global _g_s = s
global _g_x = x
global _g_y = y
global _g_fr = c.Framerate
global _g_show_time = show_time
global _g_show_frame = show_frame
c2 = ScriptClip(c,"subtitle(_g_s2,_g_x,_g_y)")
c3 = FrameEvaluate(c2,"_MyFrameTimeNumber()")
c4 = FrameEvaluate(c3,"global _g_cf = current_frame")
return c4
}
function _MyFrameTimeNumberCalc()
{
tot_sec = int(_g_cf / _g_fr)
hrs = tot_sec / 3600
min = (tot_sec % 3600) / 60
sec = tot_sec % 60
x = int(((_g_cf / _g_fr) - tot_sec) * 100)
return ((hrs<10)?"0"+string(hrs):string(hrs)) + ":" + \
((min<10)?"0"+string(min):string(min)) + ":" + \
((sec<10)?"0"+string(sec):string(sec)) + "." + \
((x<10)?string(x)+"0":string(x)) + " "
}
function _MyFrameTimeNumber()
{
s1 = (_g_show_time==true) ? _MyFrameTimeNumberCalc() : ""
s2 = (_g_show_frame==true) ? "(" + string(_g_cf) + ")" : ""
global _g_s2 = _g_s + s1 + s2
}
I call it with MyFrameTimeNumber(c,"Clip 1 ",50,50,true,true)
and I'll get "Clip 1 00:00:00.00 (0)" at loc 50,50
I'm sure this can be optimized, but it does what I want.
oof
13th October 2003, 03:38
Avisynth is great fun.
# Add time to a movie
CR = chr(13)
SP = " "
t = 0.0
avisource( "movie.avi" )
W = Width
H = Height
ftime = 1.0/Framerate
ScriptClip( last , " t = t + ftime " + CR + \
" s = time_str( t ) " + CR + \
" Subtitle( s , x = (W/2) , y = (H-20) ) " )
return( last )
# Returns a string representing "sec" seconds in HH:MM:SS.SSS format
Function time_str( float sec )
{
f = int( (Frac(sec) * 1000.0) + 0.5 )
t = int( sec )
ss = t % 60
t = t / 60
mm = t % 60
t = t / 60
hh = t
str = LeftStr( ( "0" + String( hh ) ) , 2 ) + ":" + \
LeftStr( ( "0" + String( mm ) ) , 2 ) + ":" + \
LeftStr( ( "0" + String(ss ) ) , 2 ) + "." + \
LeftStr( ( String(f) + "00" ) , 3 )
return( str )
}
Ejoc
14th October 2003, 02:41
Thanks oof, you got me thinking.
I was able to drop all the goobals, and a function, yea.
Now I can do an import() and run MyFrameTimeNumber() on multiple clips and keep track of times/frames/source.
function MyFrameTimeNumber(clip c,string s,int x,int y,bool show_time,bool show_frame)
{
CR = chr(13)
QUOTES = chr(34)
ScriptClip(c,"cf = current_frame" + CR + \
((show_time==true) ? ("s1 = _MyFrameTimeNumberCalc(cf,last.Framerate)") : ("s1 = " + QUOTES + QUOTES)) +CR + \
((show_frame==true) ? ("s2 = " + QUOTES + "(" + QUOTES + " + string(cf) + " + QUOTES + ")" + QUOTES) : ("s2 = " + QUOTES + QUOTES)) + CR + \
"s3 = " + QUOTES + s + QUOTES + " + s1 + s2" + CR + \
"subtitle(s3," + string(x) + "," + string(y) + ")")
}
function _MyFrameTimeNumberCalc(int cf,float fr)
{
tot_sec = int(cf / fr)
hrs = tot_sec / 3600
min = (tot_sec % 3600) / 60
sec = tot_sec % 60
x = int(((cf / fr) - tot_sec) * 100)
return ((hrs<10)?"0"+string(hrs):string(hrs)) + ":" + \
((min<10)?"0"+string(min):string(min)) + ":" + \
((sec<10)?"0"+string(sec):string(sec)) + "." + \
((x<10)?string(x)+"0":string(x)) + " "
}
stickboy
14th October 2003, 07:01
Could you guys please use [ code ] ... [ /code ] tags?
oof
14th October 2003, 14:36
Sorry , didn't know they existed.
Is there any advantage other than delimiting the code ?
stickboy
14th October 2003, 19:51
It makes it much easier for others to read.
oof
14th October 2003, 21:16
I'll try it
avisource( "movie.avi" )
W = Width
H = Height
ftime = 1.0/Framerate
ScriptClip( last , " t = t + ftime " + CR + \
" s = time_str( t ) " + CR + \
" Subtitle( s , x = (W/2) , y = (H-20) ) " )
I don't see a whole lot of improvement.
stickboy
14th October 2003, 23:30
That's because your code has no indentation. Compare Ejoc's previous two posts, or suppose you had written:avisource( "movie.avi" )
W = Width
H = Height
ftime = 1.0/Framerate
ScriptClip( last , " t = t + ftime " + CR
\ + " s = time_str( t ) " + CR
\ + " Subtitle( s , x = (W/2) , y = (H-20) ) " )Trust me, it's easier, especially for functions.
Ejoc
14th October 2003, 23:53
I'm having an odd thing happen when I use ScriptClip() If I do something like:
AviSource("test.avi")
ScriptClip("subtitle(string(current_frame))")
when I play it in WMP or VirtualDub, it will play, but as I watch the frames being displayed appear like:0,1,2,4,5,10,20,40,80,160,320 The frames appear when they should, but there are no frames displayed inbetween. The numbers will vary, but there is a doubling issuing occuring. But if I go back to the beginning and replay it, it will play most of the frames as it should. TMPGEnc seems ok with it, but I'm a little puzzled.
ImaWeTodd
15th October 2003, 15:40
For avisynth 2.07 you can do this with this type of script :)
Function myFunc(clip c, int x) {
return Subtitle(c,String(x))
}
Animate (Version(), 1,Version().FrameCount()
\ , "myFunc", 1,Version().FrameCount())
Wilbert
15th October 2003, 21:03
when I play it in WMP or VirtualDub, it will play, but as I watch the frames being displayed appear like:0,1,2,4,5,10,20,40,80,160,320 The frames appear when they should, but there are no frames displayed inbetween. The numbers will vary, but there is a doubling issuing occuring. But if I go back to the beginning and replay it, it will play most of the frames as it should. TMPGEnc seems ok with it, but I'm a little puzzled.
Can you give some more info. Because I can't duplicate it with huffyuv or xvid. What kind of avi do you use, do you try it with other codecs, etc? AviSynth version?
I assume that with playing you mean frame by frame scrolling ...
sh0dan
15th October 2003, 21:33
WMP will skip frames if your computer cannot keep up with the framerate, therefore not displaying every frame.
If you have "Drop frames when behind" activated in Vdub it will do the same. Disabling it or using the cursor keys to advance frames should eliminate this problem.
Ejoc
15th October 2003, 22:15
I've had it happen with huuffyuv and picvideo mjpeg AVI files using AVISynth 2.52. It is dropping frames, but the number of frames being dropped keeps doubling, which I've never had it do before. I'm used to some frames being dropeed if I am doing alot of filtering, but nothing like this.
Plus the fact that if I return to the beginning and play it again, it will play pretty much as it should... I did have it give me a Video Out of sync warning a few times after I let it play all the way thru, and went back to the beginning to let it play again.
*Sorry for typos, this keyboard at work sucks :angry:
Ejoc
18th October 2003, 18:25
I found out how to fix my problem, just not sure whats causing it. I have to convert my clip to RGB and then it works properly.
oof
18th October 2003, 21:21
A lot of Avisynth programs will not work if
you randomly seek around in them with Vdub.
They don't store the previous states .
You must cause the frameclient to progressively ask
for each frame in order or they will break.
You can't even skip forward.
Ejoc
19th October 2003, 03:44
It was not being in RGB that caused the problem oof, once converted to RGB it works as it should.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.