Thread: Vapoursynth
View Single Post
Old 23rd January 2021, 09:00   #4243  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 321
ok, I got that, thanks, but then I could not figure out how to have array/list of clips done by that, that code is too much for me, I settled with something like this at the end:
Code:
import vapoursynth as vs
from vapoursynth import core
import collections

class Clips(list):    
    def __init__(self, inputs):
        list.__init__(self,[])
        
        self.Clip_data = collections.namedtuple('Clip_data', ['clip','rgb','isError','log','output_index'])

        if isinstance(inputs, type(vs.get_outputs())):
            inputs = [ (clip, output_index) for output_index, clip in inputs.items()]
                                         
        elif isinstance(inputs, list):
            inputs = [ (clip, None) for clip in inputs]
        else:
            raise ValueError('wrong input')
        for clip, output_index in inputs:
            self.append(self.set(clip, output_index))
 
    def set(self, clip, output_index=None):
        rgb, isError, log = self.toRGB(clip)
        #other work
        return self.Clip_data(clip=clip, rgb=rgb, isError=isError, log=log, output_index=output_index)
        
    def replace(self, index, clip, output_index=None):
        self[index] = self.set(clip, output_index)

    def appending(self, clip, output_index=None):
        self.append(self.set(clip, output_index))
        
    def toRGB(self, c):
        #conversion to rgb, mocking a return for show
        return core.resize.Bicubic(c, matrix_in_s='170m',format=vs.RGB24), False, 'this is a conversion log'
    
vs.clear_outputs()
clip = core.std.BlankClip(format=vs.YUV420P8)
clip.set_output(0)

bright = clip.std.Expr(['x 40 +','',''])
bright.set_output(1)

clips = Clips([clip, bright])
##clips = Clips(vs.get_outputs())

print(clips[0].clip)
print(clips[0].rgb)
print(clips[0].log)
print(clips[1].clip)
#...

#replacing clip on index 1
brightest = clip.std.Expr(['x 100 +','',''])
clips.replace(1, brightest)

#apending clip
clip = core.std.BlankClip(color=(255,0,0)).resize.Point(matrix_s='170m',format=vs.YUV420P8)
clips.appending(clip)
_Al_ is offline   Reply With Quote