PDA

View Full Version : time display via avs script?


guru1968
29th September 2003, 17:58
hello buddies!
is there any way other then the one describe HERE (http://forum.doom9.org/showthread.php?s=&threadid=61688) to get a counting timer on the screen?

maybe one with selectable font/size/position/counting direction(upwards,downwards)/effects(fading,rolling,whatever)...

I want to make a DVD containing as an extra some songs and it'll be nice that during playback the time would be displayed (playtime or remaining time)!

So I have some background image or a clip and want to get the playtime on top of this displayed...

Or - is there any other way besides avisynth to have this done?
I am not familiar with premiere or virtualdub filters or such tools and searching for this only resulted in above link (which is not really what I want because this filter is only for DV sources)!

ch33rs,
guru

Kurosu
29th September 2003, 19:54
Someone may come up with a more elegant, or less CPU-hungry function, (SSA script?) but here's a general start point for you:


function counter(clip clip, int n)
{
n = n / clip.framerate()
day = int(n / 86400)
days = string(day)
days = strlen(days) < 2 ? "0" + days : days
n = n - day * 86400
hour = int(n / 3600)
hours = string(hour)
hours = strlen(hours) < 2 ? "0" + hours : hours
n = n - hour * 3600
min = int(n / 60)
mins = string(min)
mins = strlen(mins) < 2 ? "0" + mins : mins
n = n - min * 60
sec = int(n)
secs = string(sec)
secs = strlen(secs) < 2 ? "0" + secs : secs
ms = string(int(1000 * (n - sec)))
ms = strlen(ms) < 2 ? "0" + ms : ms
ms = strlen(ms) < 3 ? "0" + ms : ms
clip.subtitle(days + ":" + hours + ":" + mins + ":" + secs + ":" + ms)
}

clip = avisource("rb-2.avi").trim(0,300)
animate( 0, clip.framecount(), "counter", clip, 0, clip, clip.framecount())


You'll of course have to modify (even tweak for fancier effects - n is left untouched for that purpose) the parameters to subtitle.

Nota: it crashed once on me, and the rounding (mattering only for the milliseconds display) doesn't always match VDub count.

guru1968
30th September 2003, 01:16
well that's more or less exactly what I had in mind :-D

But - maybe I am stupid or blind or whatever,
How do I load a single bitmap as a source which is repeated a specified framecount times to produce a clip?

the imagereader function is not feasible as I need ntsc (29.97fps) plus as far as I understood I would need an image sequence...

I only have one single image as a background, than the audio which gives the length of the clip and the nice function above (a little modified to only have minutes and seconds remaining) to have the play-time counting down to zero and the prerequsite that it has to be NTSC.

okay, well I can first make an mpeg from the still-image plus the audio using TMPGEnc, saving as elementary video only but I fear a quality loss then - any other, better and faster way???


(This sounds to me a very basic functionality, so again sorry for asking but I haven't found it in the docs...)

ch33rs,
guru

Wilbert
30th September 2003, 10:42
How do I load a single bitmap as a source which is repeated a specified framecount times to produce a clip?
Just use loop and assumefps.

guru1968
30th September 2003, 11:09
*** deleted ***

okay - I have it :-7



Thanks all

ch33rs,
guru

guru1968
30th September 2003, 15:23
well, taking the function above plus:

video = ImageReader("background.bmp").trim(0,-1).changefps(29.97)
# trim(0,-1) because otherwise ImageReader() always produces a 41 second long video without!
# ... strange but true

audio = WavSource("test.wav")
clip = AudioDub(video, audio).assumefps(29.97)
animate( 0, clip.framecount(), "counter", clip, 0, clip, clip.framecount())

results in a clip with the length of the audio (that's what I wanted indeed) but it only has one single frame!?!?
- so the "counter" function frome above is not counting at all!

You can verify this by exchanging the animate() line by "info(clip)"
the fps is correctly set to 29.970 but the framenumber is not increasing - it stays all the time to '0'

-> I am using avisynth_2.52
Is this a bug? or how do I have to dub a single-image video source with an audio source to have a correct amount of frames in the final clip???

ch33rs,
guru

Wilbert
30th September 2003, 17:09
Look up the length of the wav in sec., and multiply this with 29.97 fps, to get the number of frames (say x frames).

video = ImageReader("background.bmp").trim(0,-1).loop(x).assume(29.97)
# trim(0,-1) because otherwise ImageReader() always produces a 41 second long video without!
# ... strange but true

audio = WavSource("test.wav")

audio(video,audio)
-----

Maybe framecount(audio) gives also the number of frames (can be checked with subtitle and blankclip), but you will have to try that, since I'm not sure about this.

guru1968
30th September 2003, 18:04
Originally posted by Wilbert
Look up the length of the wav in sec., and multiply this with 29.97 fps, to get the number of frames (say x frames).

video = ImageReader("background.bmp").trim(0,-1).loop(x).assume(29.97)
# trim(0,-1) because otherwise ImageReader() always produces a 41 second long video without!
# ... strange but true

audio = WavSource("test.wav")

audio(video,audio)
-----

Maybe framecount(audio) gives also the number of frames (can be checked with subtitle and blankclip), but you will have to try that, since I'm not sure about this.

Exactly this number for X is what I need...
'normally' I would use something like:
X=audio.assumefps(29.97).framecount()
but "framecount()" for any audio-only clip always delivers '0', not very useful :(

Wilbert
30th September 2003, 20:34
Originally posted by guru1968
Exactly this number for X is what I need...
'normally' I would use something like:
X=audio.assumefps(29.97).framecount()
but "framecount()" for any audio-only clip always delivers '0', not very useful :(

Audiolength(clip), returns the size in samples:

http://www.avisynth.org/index.php?page=ClipProperties

Audiorate(clip), is the sample rate (I guess). Thus your script should look something like:

audio = WavSource("test.wav")
x = 29.97*audiolength(audio)/audiorate(audio)
video = ImageReader("background.bmp").trim(0,-1).loop(x).assume(29.97)
audiodub(video, audio)

I don't have enough time to check it for you, but I hope this is enough info to proceed :)

guru1968
1st October 2003, 01:14
Thanks a lot, folks!

<AVS>
function counter(clip clip, int n)
{
n = n / clip.framerate()
min = int(n / 60)
mins = string(min)
mins = min < 10 ? "0" + mins : mins
n = n - min * 60
sec = int(n)
secs = string(sec)
secs = sec < 10 ? "0" + secs : secs
time = mins + ":" + secs
clip.subtitle(time, x=510, y=370, font="frutiger", size=48)
}
audio = wavsource("audio.wav")
frames = int((29.97 * audiolength(audio)) / audiorate(audio))
video = imagereader("image.bmp").trim(0,-1).loop(frames).assumefps(29.97)

#for upcounting time:
animate(0, frames, "counter", video, 0, video, frames)

#for remaining time:
#animate(0, frames, "counter", video, frames, video, 0)
</AVS>

That does all it needs for me (audio will be muxed in later on as this was only intented to feed an mpeg encoder...)


ch33rs,
guru

WarpEnterprises
2nd October 2003, 17:48
You can also use ScriptClip for these things:


avisource(file)
scriptclip("counter(current_frame)")
#scriptclip("counter(framecount-current_frame)")

return last

function counter(clip clip, int n)
{
n = n / clip.framerate()
min = int(n / 60)
mins = string(min)
mins = min < 10 ? "0" + mins : mins
n = n - min * 60
sec = int(n)
secs = string(sec)
secs = sec < 10 ? "0" + secs : secs
time = mins + ":" + secs
clip.subtitle(time, x=510, y=370, font="frutiger", size=48)
}

Paky
5th March 2005, 14:45
Originally posted by WarpEnterprises
You can also use ScriptClip for these things:


avisource(file)
scriptclip("counter(current_frame)")
#scriptclip("counter(framecount-current_frame)")

return last

function counter(clip clip, int n)
{
n = n / clip.framerate()
min = int(n / 60)
mins = string(min)
mins = min < 10 ? "0" + mins : mins
n = n - min * 60
sec = int(n)
secs = string(sec)
secs = sec < 10 ? "0" + secs : secs
time = mins + ":" + secs
clip.subtitle(time, x=510, y=370, font="frutiger", size=48)
}


and to add in this script
time = mins + ":" + secs + ":" + currentframe
?:confused:

WarpEnterprises
7th March 2005, 09:14
version()
scriptclip("counter(current_frame)")
#scriptclip("counter(framecount-current_frame)")

return last

function counter(clip clip, int n)
{
current_frame = n
n = n / clip.framerate()
min = int(n / 60)
mins = string(min)
mins = min < 10 ? "0" + mins : mins
n = n - min * 60
sec = int(n)
secs = string(sec)
secs = sec < 10 ? "0" + secs : secs
time = mins + ":" + secs + ":" + string(current_frame)
clip.subtitle(time, x=10, y=70, font="frutiger", size=48)
}

Paky
7th March 2005, 18:46
many thanks :)