Exemplo n.º 1
0
def jpg_info(filename):
    """
    Reads a single jpeg image from the file *filename* and extracts the Axis user data header.
    The information it contains is returned as a dict with the keys "hwid", "serial_numer" and
    "firmware_version".
    """
    if sys.version_info > (3, ):
        filename = bytes(filename, "utf8")
    m = ffi.new("struct mjpg *")
    r = lib.mjpg_open(m, filename, lib.IMTYPE_GRAY, lib.IMORDER_PLANAR)
    lib.mjpg_next_head(m)
    res = {
        'hwid': ffi.string(m.hwid),
        'serial_number': ffi.string(m.serial),
        'firmware_version': ffi.string(m.firmware),
        'timestamp': m.timestamp_sec + m.timestamp_usec / 1000000.0
    }
    lib.mjpg_close(m)
    return res
Exemplo n.º 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
Exemplo n.º 3
0
 def __del__(self):
     lib.mjpg_close(self.m)