Beispiel #1
0
    def next(self):
        r = lib.mjpg_next_head(self.m)
        if r == lib.ERROR_EOF:
            raise StopIteration
        if r != lib.OK:
            raise UnsupportedFormatError
        if self.channels == 1:
            shape = (self.m.height, self.m.width)
        else:
            shape = (self.m.height, self.m.width, self.channels)
        img = Frame(shape, 'B')
        if img.__array_interface__['strides'] is not None:
            raise UnsupportedFormatError
        self.m.pixels = ffi.cast('unsigned char *',
                                 img.__array_interface__['data'][0])

        r = lib.mjpg_next_data(self.m)
        if r == lib.ERROR_EOF:
            raise StopIteration
        if r != lib.OK:
            raise UnsupportedFormatError

        # img = img.reshape(shape).view(type=Frame)
        img.timestamp = self.m.timestamp_sec + self.m.timestamp_usec / 1000000.0
        img.systime = img.timestamp
        img.index = self.fcnt
        self.fcnt += 1
        return img
Beispiel #2
0
    def decode_frame(self, frm, pixels, pts, grey):
        if frm.len == 0:
            return 0
        m = mjpg_ffi.new("struct mjpg *")
        if grey:
            r = mjpg_lib.mjpg_open_buffer(m, frm.data, frm.len, mjpg_lib.IMTYPE_GRAY, mjpg_lib.IMORDER_INTERLEAVED)
        else:
            r = mjpg_lib.mjpg_open_buffer(m, frm.data, frm.len, mjpg_lib.IMTYPE_RGB, mjpg_lib.IMORDER_INTERLEAVED)
        if r != mjpg_lib.OK:
            raise IOError("Failed to decode frame")

        if mjpg_lib.mjpg_next_head(m) != mjpg_lib.OK:
            return 0
        m.pixels = mjpg_ffi.cast('unsigned char *', pixels)
        if mjpg_lib.mjpg_next_data(m) != mjpg_lib.OK:
            return 0
        pts[0] = m.timestamp_sec * 1000000 + m.timestamp_usec
        mjpg_lib.mjpg_close(m)

        return 1
Beispiel #3
0
    def next(self):
        r = lib.mjpg_next_head(self.m)
        if r != lib.OK:
            raise StopIteration
        if self.channels == 1:
            shape = (self.m.height, self.m.width)
        else:
            shape = (self.m.height, self.m.width, self.channels)
        img = Frame(shape, 'B')
        assert img.__array_interface__['strides'] is None
        self.m.pixels = ffi.cast('unsigned char *', img.__array_interface__['data'][0])

        r = lib.mjpg_next_data(self.m)
        if r != lib.OK:
            raise StopIteration

        # img = img.reshape(shape).view(type=Frame)
        img.timestamp = self.m.timestamp_sec + self.m.timestamp_usec / 1000000.0
        img.systime = img.timestamp
        img.index = self.fcnt
        self.fcnt += 1
        return img