View Full Version : Displaying duration as HH:MM:SS.mmm


hello_hello
11th August 2017, 23:53
Aside from Info(), is there a way to display the total audio and/or video duration with Avisynth? If there is, I haven't been clever enough to find it.

I wanted to display the total duration as part of a function I was playing around with, and not being able to find an easy way, I created a function for converting seconds to HH:MM:SS.
So far it seems to be working fine but my maths isn't the best. Could somebody please confirm I haven't done anything silly (or feel free to suggest a better way)?

For converting seconds to HH:MM:SS format:

function HMSConvert(float sec)
{
Hour = floor(sec/3600)
Minute = floor(sec/60 - Hour*60)
Second = floor(sec - Minute*60 - Hour*3600)
Millisecond = round((sec - floor(sec))*1000)

Hours = string(Hour, "%02.0f")
Minutes = string(Minute, "%02.0f")
Seconds = string(Second, "%02.0f")
Milliseconds = string(Millisecond, "%03.0f")

Converted_Duration = Hours + """ : """ + Minutes + """ : """ + Seconds + """ . """ + Milliseconds
return Converted_Duration
}

Same again except taking the duration info from the AudioDuration() function.

function HMSAudioConvert(clip c)
{
Hour = floor(c.AudioDuration/3600)
Minute = floor(c.AudioDuration/60 - Hour*60)
Second = floor(c.AudioDuration - Minute*60 - Hour*3600)
Millisecond = round((c.AudioDuration - floor(c.AudioDuration))*1000)

Hours = string(Hour, "%02.0f")
Minutes = string(Minute, "%02.0f")
Seconds = string(Second, "%02.0f")
Milliseconds = string(Millisecond, "%03.0f")

Converted_Audio_Duration = Hours + """ : """ + Minutes + """ : """ + Seconds + """ . """ + Milliseconds
return Converted_Audio_Duration
}


Have I done anything silly?
Thanks.

StainlessS
12th August 2017, 02:43
HH,
I'm sure your stuff is great, but here some from another time (cant say which is better, I'm feelin' a bit under the weather, well bit pissed at the mo):-

Function HoursMinutesSeconds(Clip Last)
{ # "%02.xf" for fractional seconds where:- x=0 None,1=tenths,2=hundredths,3=thousandths
ScriptClip("""subtitle( \
string(int(current_frame/FrameRate/3600))+ ":" + \
string((int(current_frame/FrameRate/60) % 60),"%02.0f") + ":" + \
string((int(current_frame/FrameRate*10000) % 600000)/10000.0,"%02.3f") \
)""")
}

Function MinutesSeconds(Clip Last)
{ # "%02.xf" for fractional seconds where:- x=0 None,1=tenths,2=hundredths,3=thousandths
ScriptClip("""subtitle( \
string((int(current_frame/FrameRate/60) % 60),"%02.0f") + ":" + \
string((int(current_frame/FrameRate*10000) % 600000)/10000.0,"%02.0f") \
)""")
}

Function Seconds(Clip Last)
{ # "%0.xf" for fractional seconds where:- x=0 None,1=tenths,2=hundredths,3=thousandths
ScriptClip("""subtitle( \
string(current_frame/FrameRate,"%0.3f") \
)""")
}

Function Frames(Clip Last)
{
ScriptClip("subtitle(string(current_frame))")
}

Hopefully summick useful amonst that lot above.

EDIT:
Have I done anything silly?
I'll tell in the morn.
I hope that you have taken into account that leap years happen every 4 years, but every 100 years you forget the leap year, except in every 1000 years you dont. (or summick like that), anyways, looks fine to me.

hello_hello
12th August 2017, 05:24
Cheers. I just wanted to make sure I hadn't created something that'd bite me later, although I'll check out the functions you posted too.

I hope you're feeling better (or more sober) soon. :)

Thanks.

I still can't believe there's not a built in HH:MM:SS function though, aside from Info().