Log in

View Full Version : Any way to get input's FPS within script?


AlekseiV
17th September 2010, 04:25
For example, a script to speed up a video by 5x:
SetMTMode(2,4)
LoadPlugin("C:\Program Files (x86)\megui\tools\ffms\ffms2.dll")
audio = FFAudioSource("some_video.mkv")
video = FFVideoSource("some_video.mkv")
comb = AudioDub(video, audio)

framerate = 23.976 # needs to match input
speedup = 5 # speedup factor

# do any editing here with combined clip

# speedup
video_fast = comb.AssumeFPS(speedup*framerate).ChangeFPS(framerate)
SetMTMode(3)
audio_fast = comb.TimeStretch(tempo = (speedup*framerate)/(framerate)*100.0, sequence=50, overlap=10)
return AudioDub(video_fast, audio_fast).ConvertToYV12()

Is there any way to get the FPS within the script, so it does not need to be manually defined?
Obviously this is not some huge effort to manually define the script, but it saves some time and may be easier for newbie. Is there a function for it?

Didée
17th September 2010, 10:52
Sure, the is a function "Framerate(clip)". So you can easily do e.g.

videoFPS = framerate( video )

As you see, I would suggest using another name for the numeric variable. Avisynth usually is smart enough to tell apart objects and filters even when they have the same name, but it's unnecessarily confusing ... imagine "foo = foo ? foo(foo) : foo". Using different names is easier.

IanB
17th September 2010, 23:07
As Didée says use FrameRate(clip), however this only uses the value as set by the source filter.

With video container formats that support VFR content like ASF/WMV and MKV this can be a little tricky, some assumptions have to be made to calculate a FPS value from the available information. e.g DirectShowSource() first tries to use the Directshow VIDEOINFOHEADER(2) AvgTimePerFrame value, but not all splitters provide this value. Other attempts use the IMediaSeeking::GetDuration() call. Finally in desperation getting the duration of the first frame and comparing it to commonly known values is tried. FFVideoSource() has it's own similar bag of tricks. For some media all these cunning attempts still fail, this is why DirectShowSource(), etc have the option to force the FPS.

Bottom like for some media format the human (you) has to interrogate the value by some external means and write the script appropriately.

AlekseiV
19th September 2010, 11:56
Thanks, both of you!

Does FFVideoSource (or XSources in general) get the right FPS for MPEG-2 and AVC .TS files? I assume it gets it right for CFR MKV.