Exemplo n.º 1
0
    def __init__(self,
                 filename,
                 decode_file=False,
                 buffersize=200000,
                 nbytes=2,
                 fps=44100):

        AudioClip.__init__(self)

        self.filename = filename
        self.reader = FFMPEG_AudioReader(
            filename,
            decode_file=decode_file,
            fps=fps,
            nbytes=nbytes,
            buffersize=buffersize,
        )
        self.fps = fps
        self.duration = self.reader.duration
        self.end = self.reader.duration
        self.buffersize = self.reader.buffersize
        self.filename = filename

        self.make_frame = lambda t: self.reader.get_frame(t)
        self.nchannels = self.reader.nchannels
Exemplo n.º 2
0
    def __init__(self, filename, buffersize=200000, nbytes=2, fps=44100):

        AudioClip.__init__(self)

        self.filename = filename
        self.reader = FFMPEG_AudioReader(filename,
                                         fps=fps,
                                         nbytes=nbytes,
                                         bufsize=buffersize + 100)
        self.fps = fps
        self.duration = self.reader.duration
        self.end = self.duration

        self.nframes = self.reader.nframes
        self.buffersize = buffersize
        self.buffer = None
        self._fstart_buffer = 1
        self._buffer_around(1)

        def gf(t):
            bufsize = self.buffersize
            if isinstance(t, np.ndarray):
                # lazy implementation, but should not cause problems in
                # 99.99 %  of the cases
                result = np.zeros((len(t), 2))
                in_time = (t >= 0) & (t < self.duration)
                inds = (self.fps * t + 1).astype(int)[in_time]
                f_tmin, f_tmax = inds.min(), inds.max()

                if not (0 <=
                        (f_tmin - self._fstart_buffer) < len(self.buffer)):
                    self._buffer_around(f_tmin)
                elif not (0 <=
                          (f_tmax - self._fstart_buffer) < len(self.buffer)):
                    self._buffer_around(f_tmax)

                try:
                    tup = in_time.nonzero()
                    inds2 = inds - self._fstart_buffer
                    result[in_time] = self.buffer[inds - self._fstart_buffer]
                    return result
                except IndexError as error:
                    print("Error: wrong indices in video buffer. Maybe" +
                          " buffer too small.")
                    raise error

            else:
                ind = int(self.fps * t)
                if ind < 0 or ind > self.nframes:  # out of time: return 0
                    return np.zeros(self.nchannels)

                if not (0 <= (ind - self._fstart_buffer) < len(self.buffer)):
                    # out of the buffer: recenter the buffer
                    self._buffer_around(ind)

                # read the frame in the buffer
                return self.buffer[ind - self._fstart_buffer]

        self.get_frame = gf
Exemplo n.º 3
0
    def __init__(self, filename, buffersize=200000, nbytes=2, fps=44100):
        

        AudioClip.__init__(self)
            
        self.filename = filename
        self.reader = FFMPEG_AudioReader(filename,fps=fps,nbytes=nbytes,
                                         bufsize=buffersize+100)
        self.fps = fps
        self.duration = self.reader.duration
        self.end = self.duration
        
        self.nframes = self.reader.nframes
        self.buffersize= buffersize
        self.buffer= None
        self._fstart_buffer = 1
        self._buffer_around(1)
        
        def gf(t):
            bufsize = self.buffersize
            if isinstance(t,np.ndarray):
                # lazy implementation, but should not cause problems in
                # 99.99 %  of the cases
                result = np.zeros((len(t),2))
                in_time = (t>=0) & (t < self.duration)
                inds = (self.fps*t+1).astype(int)[in_time]
                f_tmin, f_tmax = inds.min(), inds.max()
                
                if not (0 <= (f_tmin - self._fstart_buffer) < len(self.buffer)):
                    self._buffer_around(f_tmin)
                elif not (0 <= (f_tmax - self._fstart_buffer) < len(self.buffer)):
                    self._buffer_around(f_tmax)
                    
                try:
                    tup = in_time.nonzero()
                    inds2 = inds - self._fstart_buffer
                    result[in_time] = self.buffer[inds - self._fstart_buffer]
                    return result
                except IndexError as error:
                    print ("Error: wrong indices in video buffer. Maybe"+
                           " buffer too small.")
                    raise error
                    
            else:
                ind = int(self.fps*t)
                if ind<0 or ind> self.nframes: # out of time: return 0
                    return np.zeros(self.nchannels)
                    
                if not (0 <= (ind - self._fstart_buffer) <len(self.buffer)):
                    # out of the buffer: recenter the buffer
                    self._buffer_around(ind)
                    
                # read the frame in the buffer
                return self.buffer[ind - self._fstart_buffer]

        self.get_frame = gf
Exemplo n.º 4
0
    def __init__(self, filename, buffersize=200000, nbytes=2, fps=44100):

        AudioClip.__init__(self)

        self.filename = filename
        reader = FFMPEG_AudioReader(filename, fps=fps, nbytes=nbytes, buffersize=buffersize)

        self.reader = reader
        self.fps = fps
        self.duration = reader.duration
        self.end = reader.duration

        self.make_frame = lambda t: reader.get_frame(t)
        self.nchannels = reader.nchannels
Exemplo n.º 5
0
    def __init__(self, filename, buffersize=200000, nbytes=2, fps=44100):
        

        AudioClip.__init__(self)
            
        self.filename = filename
        reader = FFMPEG_AudioReader(filename,fps=fps,nbytes=nbytes,
                                         buffersize=buffersize)
        
        self.reader = reader
        self.fps = fps
        self.duracion = reader.duracion
        self.fin = reader.duracion
        
        
        self.make_frame =  lambda t: reader.get_frame(t)
        self.nchannels = reader.nchannels