View Single Post
Old 25th December 2012, 07:25   #6  |  Link
Chikuzen
typo lover
 
Chikuzen's Avatar
 
Join Date: May 2009
Posts: 595
Quote:
Originally Posted by Myrsloik View Post
Why not simply show this concept with a script? There aready is a built in function to calculate the average difference for a frame.
Like this?
Code:
#!/bin/env python3

import vapoursynth as vs
import sys

class SceneChangeDetect(object):
    def __init__(self, core):
        self.std = core.std
        self.resize = core.resize.Point
        self.th = 0

    def set_scene_change(self, n, f):
        fout = f[0].copy()
        fout.props._SceneChange = ((f[1].props.DiffPrev[0] > self.th) +
                                   (f[1].props.DiffNext[0] > self.th))
        return fout

    def detect(self, clip, th=0.0588, interval_h=None, interval_v=None):
        self.th = th
        if interval_h is None:
            interval_h = int(clip.width / 320)
        if interval_v is None:
            interval_v = int(clip.width / 320)
        curr = self.resize(clip, int(clip.width / interval_h),
                           int(clip.width / interval_v), vs.GRAY8)
        prev = curr[0] + curr
        next = curr[1:]
        curr = self.std.PlaneDifference([curr, prev], 0, 'DiffPrev')
        curr = self.std.PlaneDifference([curr, next], 0, 'DiffNext')
        return self.std.ModifyFrame([clip, curr], self.set_scene_change)

if __name__ == '__main__':
    core = vs.Core()
    core.std.LoadPlugin('G:/vsplugins/d2vsource_beta4_v2.dll')

    clip = core.d2v.Source('D:\HD_Source\sample_1080i_00.d2v", nocrop=True)
    clip = SceneChangeDetect(core).detect(clip)

    log = open('scenecange.log', 'w')
    for n in range(clip.num_frames):
        scene_change = clip.get_frame(n).props._SceneChange[0]
        if scene_change:
            print(n, file=log)
    log.close()
Because I’m used to thinking on C rather than Python

EDIT:
The true reason is for removing scene change detection from the code of temporalsoften(VS version).
I assumed that the biggest bottleneck of that is the part , and considered how to remove them.
As the results, I proposed adding _SceneChange to you, and wrote this plugin.
Since origin was written in C, I've never noticed the way written in Python.
__________________
my repositories

Last edited by Chikuzen; 25th December 2012 at 16:16.
Chikuzen is offline   Reply With Quote