예제 #1
0
    def open(self, path):
        """Open input file."""
        ss = gizmo.Demux(path).getStreamsInfo()
        streams = {s.no: s for s in ss}

        for t in ['video', 'audio', 'subtitle/text']:
            if t in [s.type for s in ss]:
                self.filetype = t
                break

        self.path = path
        self.streams = streams
        self.no = None
        self.lang = None
        self.enc = None
        self.channels = ChannelsMap.auto()
        self.fps = None

        for stream in ss:
            if stream.frameRate:
                self.fps = stream.frameRate
                break

        if len(streams) > 0:
            self.selectFirstMatchingStream()
예제 #2
0
    def deserialize(data, types=None):
        if data:
            path = data.get('path', None)
            res = InputFile(path=path, types=types)

            if 'stream' in data: res.select(data['stream'] - 1)
            if 'lang' in data: res.lang = data['lang']
            if 'enc' in data: res.enc = data['enc']
            if 'fps' in data: res.fps = data['fps']
            if 'channels' in data:
                res.channels = ChannelsMap.deserialize(data['channels'])
            return res
예제 #3
0
    def __init__(self, path=None, types=None, stream=None):
        self.path = path
        self.no = None
        self.type = None
        self.types = types
        self.streams = {}
        self.fps = None
        self.lang = None
        self.enc = None
        self.channels = ChannelsMap.auto()
        self.filetype = None

        if path != None:
            self.open(path)

        if stream != None:
            self.assign(stream)
예제 #4
0
    def __init__(self,
                 path=None,
                 stream=None,
                 *,
                 streamByType=None,
                 streamByLang=None,
                 lang=None,
                 enc=None,
                 fps=None,
                 channels=None):
        """
        Parameters
        ----------
        path: str
            Input file path.
        stream: int, optional
            Stream number, 1-based.
        streamByType: str, optional
            Select stream by type ('sub' or 'audio').
        streamByLang: str, optional
            Select stream by 3-letter language code, relies of file metadata.
        lang: str, optional
            Stream language as 2- or 3-letter ISO code.
        enc: str, optional
            Character encoding, `None` for auto detection based by `lang`.
        fps: float, optional
            Framerate.
        channels: str or subsync.synchro.channels.ChannelsMap, optional
            Audio channels to listen to, could be 'auto' or `None` for auto
            selection, 'all' to listen to all channels, or comma separated
            channels abbreviation, e.g. 'FL,FR'.

        Notes
        -----
        Here stream number is 1-based (first stream in file has number 1) but
        other methods expects 0-based numbers.
        """
        self.path = path
        self.no = None
        self.type = None
        self.streams = {}
        self.fps = None
        self.lang = None
        self.enc = None
        self.channels = ChannelsMap.auto()
        self.filetype = None

        if not hasattr(self, 'types'):
            self.types = None

        if path is not None:
            self.open(path)

        if stream is not None:
            self.select(stream - 1)

        if streamByType or streamByLang:
            self.selectBy(type=streamByType, lang=streamByLang)
        self.lang = lang or self.lang
        self.enc = enc or self.enc
        self.fps = fps or self.fps

        if type(channels) is str:
            self.channels = ChannelsMap.deserialize(channels)
        elif channels is not None:
            self.channels = channels