コード例 #1
0
 def CreateDisplayClip(self,
                       matrix=['auto', 'tv'],
                       interlaced=None,
                       swapuv=False,
                       bit_depth=None):
     self.current_frame = -1
     self.display_clip = self.clip
     self.RGB48 = False
     self.bit_depth = bit_depth
     if bit_depth:
         try:
             if bit_depth == 'rgb48':  # TODO
                 if self.IsYV12:
                     self.RGB48 = True
                     self.DisplayWidth /= 2
                     self.DisplayHeight /= 2
                     return True
             elif self.IsYV12 or self.IsYV24 or self.IsY8:
                 if bit_depth == 's16':
                     args = [self.display_clip, 0, 0, 0, self.Height / 2]
                     self.display_clip = self.env.invoke('Crop', args)
                 elif bit_depth == 's10':
                     if self.env.function_exists('mt_lutxy'):
                         args = (
                             'avsp_raw_clip\n'
                             'msb = Crop(0, 0, Width(), Height() / 2)\n'
                             'lsb = Crop(0, Height() / 2, Width(), Height() / 2)\n'
                             'mt_lutxy(msb, lsb, "x 8 << y + 2 >>", chroma="process")'
                         )
                         self.display_clip = self.env.invoke('Eval', args)
                 elif bit_depth == 'i16':
                     args = (
                         'avsp_raw_clip.AssumeBFF().TurnLeft().SeparateFields().'
                         'TurnRight().AssumeFrameBased().SelectOdd()')
                     self.display_clip = self.env.invoke('Eval', args)
                 elif bit_depth == 'i10':
                     if self.env.function_exists('mt_lutxy'):
                         args = (
                             'avsp_raw_clip.AssumeBFF().TurnLeft().SeparateFields().TurnRight().AssumeFrameBased()\n'
                             'mt_lutxy(SelectOdd(), SelectEven(), "x 8 << y + 2 >>", chroma="process")'
                         )
                         self.display_clip = self.env.invoke('Eval', args)
                 if not isinstance(self.display_clip, avisynth.AVS_Clip):
                     raise avisynth.AvisynthError("Not a clip")
                 vi = self.display_clip.get_video_info()
                 self.DisplayWidth = vi.width
                 self.DisplayHeight = vi.height
         except avisynth.AvisynthError, err:
             return self.CreateErrorClip(display_clip_error=True)
コード例 #2
0
 def CreateErrorClip(self, err='', display_clip_error=False):
     fontFace, fontSize = global_vars.options['errormessagefont'][:2]
     if display_clip_error:
         if not err:
             err = _('Error trying to display the clip')
             if self.bit_depth:
                 err += '\n' + _('Is bit-depth set correctly?')
     else:
         err = str(err)
         self.error_message = err
     lineList = []
     yLine = 0
     nChars = 0
     for errLine in err.split('\n'):
         lineList.append(
             'Subtitle("""%s""",y=%i,font="%s",size=%i,text_color=$FF0000,align=8)'
             % (errLine, yLine, fontFace.encode(
                 sys.getfilesystemencoding()), fontSize))
         yLine += fontSize
         nChars = max(nChars, len(errLine))
     eLength = self.Framecount
     eWidth = nChars * fontSize / 2
     eHeight = yLine + fontSize / 4
     firstLine = 'BlankClip(length=%(eLength)i,width=%(eWidth)i,height=%(eHeight)i)' % locals(
     )
     errText = firstLine + '.'.join(lineList)
     try:
         clip = self.env.invoke('Eval', errText)
         if not isinstance(clip, avisynth.AVS_Clip):
             raise avisynth.AvisynthError("Not a clip")
         if display_clip_error:
             self.display_clip = clip
             vi = self.display_clip.get_video_info()
             self.DisplayWidth = vi.width
             self.DisplayHeight = vi.height
         else:
             self.clip = clip
     except avisynth.AvisynthError, err:
         return
コード例 #3
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.name = filename
        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.AVS_ScriptEnvironment):
                self.env = env
            else:
                raise TypeError("env must be a PIScriptEnvironment or None")
        else:
            if isinstance(script, avisynth.AVS_Clip):
                raise ValueError("env must be defined when providing a clip")
            try:
                self.env = avisynth.AVS_ScriptEnvironment(3)
            except OSError:
                return
            if hasattr(self.env, 'get_error'):
                self.error_message = self.env.get_error()
                if self.error_message: return
        if isinstance(script, avisynth.AVS_Clip):
            self.clip = script
        else:
            # vpy hack, remove when VapourSynth is supported
            if os.name == 'nt' and filename.endswith('.vpy'):
                if self.env.function_exists('AutoloadPlugins'):  # AviSynth+
                    self.env.invoke('AutoloadPlugins')
                if self.env.function_exists('VSImport'):
                    script = ur'VSImport("{0}", stacked=true)'.format(filename)
                else:
                    script = ur'AviSource("{0}")'.format(filename)
            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.set_working_dir(workdir)
            self.env.set_global_var("$ScriptFile$", scriptbasename)
            self.env.set_global_var("$ScriptName$", filename)
            self.env.set_global_var("$ScriptDir$", scriptdirname)
            try:
                self.clip = self.env.invoke('Eval', [script, filename])
                if not isinstance(self.clip, avisynth.AVS_Clip):
                    raise avisynth.AvisynthError("Not a clip")
            except avisynth.AvisynthError, err:
                self.Framecount = oldFramecount
                if not self.CreateErrorClip(err):
                    return
            finally:
コード例 #4
0
                    raise
                self.env.set_var("last", self.clip)
            self.env.set_var("avsp_raw_clip", self.clip)
            if self.env.function_exists('AutoloadPlugins'):  # AviSynth+
                self.env.invoke('AutoloadPlugins')

        # Set the video properties
        self.vi = self.clip.get_video_info()
        self.HasVideo = self.vi.has_video()
        if not self.HasVideo:
            self.clip = None
            errText = 'MessageClip("No video")'
            try:
                self.clip = self.env.invoke('Eval', errText)
                if not isinstance(self.clip, avisynth.AVS_Clip):
                    raise avisynth.AvisynthError("Not a clip")
            except avisynth.AvisynthError, err:
                return
            try:
                if not isinstance(self.env.get_var('last'), avisynth.AVS_Clip):
                    self.env.set_var('last', self.clip)
            except avisynth.AvisynthError as err:
                if str(err) != 'NotFound':
                    raise
                self.env.set_var('last', self.clip)
            self.vi = self.clip.get_video_info()
            self.HasVideo = self.vi.has_video()
        self.Framecount = self.vi.num_frames
        self.Width = self.vi.width
        self.Height = self.vi.height
        if self.vi.is_yuv() and not self.vi.is_y8():