Пример #1
0
 def __init__(self, text, filename=''):
     self.error = None
     self.incorrect_colorspace = False
     self.env = avisynth.avs_create_script_environment(3)
     curdir = os.getcwdu()
     dirname, basename = os.path.split(filename)
     if os.path.isdir(dirname):
         self.env.SetWorkingDir(dirname)
     self.file = avisynth.AVS_Value(filename)
     self.name = avisynth.AVS_Value(basename)
     self.dir = avisynth.AVS_Value(dirname)
     self.env.SetGlobalVar("$ScriptFile$", self.file)
     self.env.SetGlobalVar("$ScriptName$", self.name)
     self.env.SetGlobalVar("$ScriptDir$", self.dir)
     try:
         clip = self.env.Invoke('Eval', avisynth.AVS_Value(text), 0)
     except avisynth.AvisynthError, err:
         self.error = str(err)
         os.chdir(curdir)
         return
Пример #2
0
 def __init__(self, script, filename='', env=None, fitHeight=None, fitWidth=None, oldFramecount=240, keepRaw=False, matrix='Rec601', interlaced=False, swapuv=False):
     # Internal variables
     self.initialized = False
     self.error_message = None
     self.current_frame = -1
     self.bmih = BITMAPINFOHEADER()
     self.pgf = LONG()
     self.pBits = None
     self.pInfo = None
     self.clipRaw = None
     self.ptrY = self.ptrU = self.ptrV = None
     # Avisynth script properties
     self.Width = -1
     self.Height = -1
     self.Framecount = -1
     self.Framerate = -1.0
     self.FramerateNumerator = -1
     self.FramerateDenominator = -1
     self.Audiorate = -1.0
     self.Audiolength = -1
     #~ self.AudiolengthF = None
     self.Audiochannels = -1
     self.Audiobits = -1
     self.IsAudioFloat = None
     self.IsAudioInt = None
     self.IsRGB = None
     self.IsRGB24 = None
     self.IsRGB32 = None
     self.IsYUY2 = None
     self.IsYV12 = None
     self.IsYUV = None
     self.IsPlanar = None
     self.IsInterleaved = None
     self.IsFieldBased = None
     self.IsFrameBased = None
     self.GetParity  = None
     self.HasAudio = None
     self.HasVideo = None
     self.Colorspace = None
     # Create the Avisynth script clip
     if (env is not None) and not isinstance(env,avisynth.PIScriptEnvironment):
         raise TypeError("env must be a PIScriptEnvironment or None")
     if env is None:
         if isinstance(script,avisynth.PClip):
             raise ValueError("env must be defined when providing a clip") 
         try:
             self.env=avisynth.avs_create_script_environment(3)
         except WindowsError:
             return
     if isinstance(script,avisynth.PClip):
         self.clip=script
         self.env=env
     else:
         if type(script) != unicode:
             f=unicode(script)
         else:
             f = script
         arg=avisynth.AVS_Value(f)           #assign to AVSValue
         scriptdirname, scriptbasename = os.path.split(filename)
         if os.path.isdir(scriptdirname):
             self.env.SetWorkingDir(scriptdirname)
         arg2=avisynth.AVS_Value(scriptbasename)
         args=avisynth.AVS_Value([arg,arg2])
         try:
             avsfile=self.env.Invoke("eval",args,0) #use eval to load it
             self.clip=avsfile.AsClip(self.env)
         except avisynth.AvisynthError, err:
             fontSize=24
             self.error_message = str(err)
             lineList = []
             yLine = 0
             nChars = 0
             for errLine in str(err).split('\n'):
                 lineList.append('Subtitle("""%s""",y=%i,size=%i,text_color=$FF0000,align=8)' % (errLine, yLine, fontSize))
                 yLine += fontSize
                 nChars = max(nChars, len(errLine))
             eLength = oldFramecount
             eWidth = nChars * fontSize / 2
             eHeight = yLine + fontSize/4
             firstLine = 'BlankClip(length=%(eLength)i,width=%(eWidth)i,height=%(eHeight)i)' % locals()
             errText = firstLine + '.'.join(lineList)
             arg = avisynth.AVS_Value(errText)
             try:
                 avsfile=self.env.Invoke("eval",arg,0) #use eval to load it
                 self.clip=avsfile.AsClip(self.env)
             except avisynth.AvisynthError, err:
                 return
Пример #3
0
        print 'GetParity =', AVI.GetParity 
        print 'HasAudio =', AVI.HasAudio
        print 'HasVideo =', AVI.HasVideo
        AVI._x_SaveFrame("C:\\workspace\\test_file.bmp", 100)
    else:
        print AVI.error_message
    AVI = None
    
    AVI = AvsClip('Blackness()', 'test.avs')
    if AVI.initialized:
        print AVI.Width
    else:
        print AVI.error_message
    AVI = None
    
    s="""    Version().ConvertToYV12()
    Sharpen(1.0)
    FlipVertical()
    """
    env = avisynth.avs_create_script_environment(3)
    r=env.Invoke("eval",avisynth.AVS_Value(s),0)
    AVI = AvsClip(r.AsClip(env),env=env)
    AVI._x_SaveFrame("test_file2.bmp", 100)
    AVI._GetFrame(100)
    AVI = None
    env.Release()
    env = None
    
    print "Exit program."

Пример #4
0
 def __init__(self, script, filename='', workdir='', env=None, fitHeight=None, 
              fitWidth=None, oldFramecount=240, display_clip=True, reorder_rgb=False, 
              matrix=['auto', 'tv'], interlaced=False, swapuv=False):
     # Internal variables
     self.initialized = False
     self.error_message = None
     self.current_frame = -1
     self.pBits = None
     self.display_clip = None
     self.ptrY = self.ptrU = self.ptrV = None
     # Avisynth script properties
     self.Width = -1
     self.Height = -1
     self.WidthSubsampling = -1
     self.HeightSubsampling = -1
     self.Framecount = -1
     self.Framerate = -1.0
     self.FramerateNumerator = -1
     self.FramerateDenominator = -1
     self.Audiorate = -1.0
     self.Audiolength = -1
     #~ self.AudiolengthF = None
     self.Audiochannels = -1
     self.Audiobits = -1
     self.IsAudioFloat = None
     self.IsAudioInt = None
     self.IsRGB = None
     self.IsRGB24 = None
     self.IsRGB32 = None
     self.IsYUV = None
     self.IsYUY2 = None
     self.IsYV24 = None
     self.IsYV16 = None
     self.IsYV12 = None
     self.IsYV411 = None
     self.IsY8 = None
     self.IsPlanar = None
     self.IsInterleaved = None
     self.IsFieldBased = None
     self.IsFrameBased = None
     self.GetParity  = None
     self.HasAudio = None
     self.HasVideo = None
     self.Colorspace = None
     self.ffms_info_cache = {}
     
     # Create the Avisynth script clip
     if env is not None:
         if isinstance(env,avisynth.PIScriptEnvironment):
             self.env = env
         else:
             raise TypeError("env must be a PIScriptEnvironment or None")
     else:
         if isinstance(script,avisynth.PClip):
             raise ValueError("env must be defined when providing a clip") 
         try:
             self.env=avisynth.avs_create_script_environment(3)
         except OSError:
             return
         if hasattr(self.env, 'GetError'):
             self.error_message = self.env.GetError()
             if self.error_message: return
     if isinstance(script,avisynth.PClip):
         self.clip=script
     else:
         if type(script) != unicode:
             f=unicode(script)
         else:
             f = script
         # vpy hack, remove when VapourSynth is supported
         if os.name == 'nt' and filename.endswith('.vpy'):
             f = ur'AviSource("{0}")'.format(filename)
         arg=avisynth.AVS_Value(f)           #assign to AVSValue
         scriptdirname, scriptbasename = os.path.split(filename)
         curdir = os.getcwdu()
         workdir = os.path.isdir(workdir) and workdir or scriptdirname
         if os.path.isdir(workdir):
             self.env.SetWorkingDir(workdir)
         self.file = avisynth.AVS_Value(scriptbasename)
         self.name = avisynth.AVS_Value(filename)
         self.dir = avisynth.AVS_Value(scriptdirname)
         self.env.SetGlobalVar("$ScriptFile$", self.file)
         self.env.SetGlobalVar("$ScriptName$", self.name)
         self.env.SetGlobalVar("$ScriptDir$", self.dir)
         arg2=avisynth.AVS_Value(filename)
         args=avisynth.AVS_Value([arg,arg2])
         try:
             avsfile=self.env.Invoke("eval",args,0) #use eval to load it
             self.clip=avsfile.AsClip(self.env)
         except avisynth.AvisynthError, err:
             fontSize=24
             self.error_message = str(err)
             lineList = []
             yLine = 0
             nChars = 0
             for errLine in str(err).split('\n'):
                 lineList.append('Subtitle("""%s""",y=%i,size=%i,text_color=$FF0000,align=8)' % (errLine, yLine, fontSize))
                 yLine += fontSize
                 nChars = max(nChars, len(errLine))
             eLength = oldFramecount
             eWidth = nChars * fontSize / 2
             eHeight = yLine + fontSize/4
             firstLine = 'BlankClip(length=%(eLength)i,width=%(eWidth)i,height=%(eHeight)i)' % locals()
             errText = firstLine + '.'.join(lineList)
             arg = avisynth.AVS_Value(errText)
             try:
                 avsfile=self.env.Invoke("eval",arg,0) #use eval to load it
                 self.clip=avsfile.AsClip(self.env)
             except avisynth.AvisynthError, err:
                 return
Пример #5
0
        print 'GetParity =', AVI.GetParity 
        print 'HasAudio =', AVI.HasAudio
        print 'HasVideo =', AVI.HasVideo
        #AVI._x_SaveFrame("C:\\workspace\\test_file.bmp", 100)
    else:
        print AVI.error_message
    AVI = None
    
    AVI = AvsClip('Blackness()', 'test.avs')
    if AVI.initialized:
        print AVI.Width
    else:
        print AVI.error_message
    AVI = None
    
    s="""    Version().ConvertToYV12()
    Sharpen(1.0)
    FlipVertical()
    """
    env = avisynth.avs_create_script_environment(3)
    r=env.Invoke("eval",avisynth.AVS_Value(s),0)
    AVI = AvsClip(r.AsClip(env),env=env)
    #AVI._x_SaveFrame("C:\\workspace\\test_file2.bmp", 100)
    AVI._GetFrame(100)
    AVI = None
    env.Release()
    env = None
    
    print "Exit program."

Пример #6
0
 def __init__(self, script, filename='', workdir='', env=None, fitHeight=None, 
              fitWidth=None, oldFramecount=240, display_clip=True, reorder_rgb=False, 
              matrix=['auto', 'tv'], interlaced=False, swapuv=False, bit_depth=None):
     # Internal variables
     self.initialized = False
     self.error_message = None
     self.current_frame = -1
     self.pBits = None
     self.display_clip = None
     self.ptrY = self.ptrU = self.ptrV = None
     # Avisynth script properties
     self.Width = -1
     self.Height = -1
     self.WidthSubsampling = -1
     self.HeightSubsampling = -1
     self.Framecount = -1
     self.Framerate = -1.0
     self.FramerateNumerator = -1
     self.FramerateDenominator = -1
     self.Audiorate = -1.0
     self.Audiolength = -1
     #~ self.AudiolengthF = None
     self.Audiochannels = -1
     self.Audiobits = -1
     self.IsAudioFloat = None
     self.IsAudioInt = None
     self.IsRGB = None
     self.IsRGB24 = None
     self.IsRGB32 = None
     self.IsYUV = None
     self.IsYUY2 = None
     self.IsYV24 = None
     self.IsYV16 = None
     self.IsYV12 = None
     self.IsYV411 = None
     self.IsY8 = None
     self.IsPlanar = None
     self.IsInterleaved = None
     self.IsFieldBased = None
     self.IsFrameBased = None
     self.GetParity  = None
     self.HasAudio = None
     self.HasVideo = None
     self.Colorspace = None
     self.ffms_info_cache = {}
     
     # Create the Avisynth script clip
     if env is not None:
         if isinstance(env,avisynth.PIScriptEnvironment):
             self.env = env
         else:
             raise TypeError("env must be a PIScriptEnvironment or None")
     else:
         if isinstance(script,avisynth.PClip):
             raise ValueError("env must be defined when providing a clip") 
         try:
             self.env=avisynth.avs_create_script_environment(3)
         except OSError:
             return
         if hasattr(self.env, 'GetError'):
             self.error_message = self.env.GetError()
             if self.error_message: return
         if self.env.FunctionExists('AutoloadPlugins'): # AviSynth+
             self.env.Invoke('AutoloadPlugins')    
     if isinstance(script,avisynth.PClip):
         self.clip=script
     else:
         if type(script) != unicode:
             f=unicode(script)
         else:
             f = script
         # vpy hack, remove when VapourSynth is supported
         if os.name == 'nt' and filename.endswith('.vpy'):
             if self.env.FunctionExists('VSImport'):
                 f = ur'VSImport("{0}", stacked=true)'.format(filename)
             else:
                 f = ur'AviSource("{0}")'.format(filename)
         arg=avisynth.AVS_Value(f)           #assign to AVSValue
         scriptdirname, scriptbasename = os.path.split(filename)
         curdir = os.getcwdu()
         workdir = os.path.isdir(workdir) and workdir or scriptdirname
         if os.path.isdir(workdir):
             self.env.SetWorkingDir(workdir)
         self.file = avisynth.AVS_Value(scriptbasename)
         self.name = avisynth.AVS_Value(filename)
         self.dir = avisynth.AVS_Value(scriptdirname)
         self.env.SetGlobalVar("$ScriptFile$", self.file)
         self.env.SetGlobalVar("$ScriptName$", self.name)
         self.env.SetGlobalVar("$ScriptDir$", self.dir)
         arg2=avisynth.AVS_Value(filename)
         args=avisynth.AVS_Value([arg,arg2])
         try:
             avsfile=self.env.Invoke("eval",args,0) #use eval to load it
             self.clip=avsfile.AsClip(self.env)
         except avisynth.AvisynthError, err:
             self.Framecount = oldFramecount
             if not self.CreateErrorClip(err):
                 return
         finally: