Esempio n. 1
0
def extract_duration(qtmovie):
    try:
        qttime = qtmovie.duration()
        if qttimeutils.qttimescale(qttime) == 0:
            return -1
        return int((qttimeutils.qttimevalue(qttime) /
                   float(qttimeutils.qttimescale(qttime))) * 1000)
    except Exception:
        return -1
Esempio n. 2
0
def extract_duration(qtmovie):
    try:
        qttime = qtmovie.duration()
        if qttimeutils.qttimescale(qttime) == 0:
            return -1
        return int((qttimeutils.qttimevalue(qttime) /
                    float(qttimeutils.qttimescale(qttime))) * 1000)
    except Exception:
        return -1
Esempio n. 3
0
def extract_thumbnail(qtmovie, target, width=0, height=0):
    try:
        qttime = qtmovie.duration()
        qttime = qttimeutils.qttimevalue_set(qttime,
          int(qttimeutils.qttimevalue(qttime) * 0.5))

        frame = qtmovie.frameImageAtTime_(qttime)
        if frame is nil:
            return False

        frame_size = frame.size()
        if frame_size.width == 0 or frame_size.height == 0:
            return False

        if (width == 0) and (height == 0):
            width = frame_size.width
            height = frame_size.height

        srcsize = frame.size()
        srcratio = srcsize.width / srcsize.height
        destsize = NSSize(width, height)
        destratio = destsize.width / destsize.height

        if srcratio > destratio:
            size = NSSize(destsize.width, destsize.width / srcratio)
            pos = NSPoint(0,
              (destsize.height - size.height) / 2.0)
        else:
            size = NSSize(destsize.height * srcratio, destsize.height)
            pos = NSPoint((destsize.width - size.width) / 2.0, 0)

        dest = NSImage.alloc().initWithSize_(destsize)
        try:
            dest.lockFocus()
            context = NSGraphicsContext.currentContext()
            context.setImageInterpolation_(NSImageInterpolationHigh)
            NSColor.blackColor().set()
            NSRectFill(((0,0), destsize))
            frame.drawInRect_fromRect_operation_fraction_((pos, size),
              ((0,0), srcsize), NSCompositeSourceOver, 1.0)
        finally:
            dest.unlockFocus()

        tiff_data = dest.TIFFRepresentation()
        image_rep = NSBitmapImageRep.imageRepWithData_(tiff_data)
        properties = {NSImageCompressionFactor: 0.8}
        jpeg_data = image_rep.representationUsingType_properties_(
          NSJPEGFileType, properties)
        if jpeg_data is nil:
            return False

        jpeg_data.writeToFile_atomically_(target, YES)
    except Exception:
        return False

    return True
Esempio n. 4
0
def extract_thumbnail(qtmovie, target, width=0, height=0):
    try:
        qttime = qtmovie.duration()
        qttime = qttimeutils.qttimevalue_set(
            qttime, int(qttimeutils.qttimevalue(qttime) * 0.5))

        frame = qtmovie.frameImageAtTime_(qttime)
        if frame is nil:
            return False

        frame_size = frame.size()
        if frame_size.width == 0 or frame_size.height == 0:
            return False

        if (width == 0) and (height == 0):
            width = frame_size.width
            height = frame_size.height

        srcsize = frame.size()
        srcratio = srcsize.width / srcsize.height
        destsize = NSSize(width, height)
        destratio = destsize.width / destsize.height

        if srcratio > destratio:
            size = NSSize(destsize.width, destsize.width / srcratio)
            pos = NSPoint(0, (destsize.height - size.height) / 2.0)
        else:
            size = NSSize(destsize.height * srcratio, destsize.height)
            pos = NSPoint((destsize.width - size.width) / 2.0, 0)

        dest = NSImage.alloc().initWithSize_(destsize)
        try:
            dest.lockFocus()
            context = NSGraphicsContext.currentContext()
            context.setImageInterpolation_(NSImageInterpolationHigh)
            NSColor.blackColor().set()
            NSRectFill(((0, 0), destsize))
            frame.drawInRect_fromRect_operation_fraction_(
                (pos, size), ((0, 0), srcsize), NSCompositeSourceOver, 1.0)
        finally:
            dest.unlockFocus()

        tiff_data = dest.TIFFRepresentation()
        image_rep = NSBitmapImageRep.imageRepWithData_(tiff_data)
        properties = {NSImageCompressionFactor: 0.8}
        jpeg_data = image_rep.representationUsingType_properties_(
            NSJPEGFileType, properties)
        if jpeg_data is nil:
            return False

        jpeg_data.writeToFile_atomically_(target, YES)
    except Exception:
        return False

    return True