Log in

View Full Version : Non-runtime script / loop possible ?


BobbingBob
30th January 2009, 18:33
I'm trying to make a script to generate a thumbnail sheet preview of a video. Now this is working very well with fixed frame numbers, but as with other preview generators you often get frames that are in the middle of a scene transition or other garbage. So I'd like to add scene change detection and use scene start frames to generate the thumbnails.

So my question is this: is there a way to loop on a series of frames to look for a scene change without the frames being requested by the calling application? Something like this seems to work fine in finding non solid scene change frames, but I can't figure out how to script this without playing the whole video... is it possible or was AviSynth simply not designed for that?

scene_end = BlankClip(last)
scene_begin = last
global_motion = BlankClip(last)

last_sc = 0

ScriptClip(last, "SCSelect(scene_begin, scene_end, global_motion, dfactor=4)")

FrameEvaluate(last, "last_sc = Crop(0, 0, last.Width/2, 0).AverageChromaU() == Crop(last.Width/2, 0, 0, 0).AverageChromaU() ? last_sc : current_frame")

ScriptClip(last, "SubTitle(last, String(last_sc), x=Round(0*last.Width), y=Round(0.1*last.Height), align=4, size=70)")

Otherwise I guess I could playback a script that writes scene start frames to a text file, run it with mplayer -vo null -speed 100 and then use that info in another script, but it doesn't sound like a very nice solution...

Any tips would be appreciated :thanks:

IanB
31st January 2009, 21:36
Yes, Avisynth is not really designed for this, but can be bent. :devil:

To do what you say, you need to access all the frames to find the transitions. Perhaps a 2 pass approach will serve you better. Pass 1 collect all the metrics on all the frames, pass 2 access the actual frames that meet your conditions, and process to suit. Use perl/awk/vb/... to "read" your pass 1 metrics and then "compose" a suitable pass 2 script. The mplayer -vo null -speed 100 or VDub run analysis pass are easy ways to generate the pass 1 metrics.