Exemplo n.º 1
0
def extract_duration(qtmovie):
    try:
        qttime = qtmovie.duration()
        if utils.qttimescale(qttime) == 0:
            return -1
        return int((utils.qttimevalue(qttime) / float(utils.qttimescale(qttime))) * 1000)
    except Exception, e:
        return -1
Exemplo n.º 2
0
def extract_duration(qtmovie):
    try:
        qttime = qtmovie.duration()
        if utils.qttimescale(qttime) == 0:
            return -1
        return int((utils.qttimevalue(qttime) / float(utils.qttimescale(qttime))) * 1000)
    except Exception:
        return -1
Exemplo n.º 3
0
    def can_open_file(self, qtmovie):
        threads.warn_if_not_on_main_thread('quicktime.Player.can_open_file')
        can_open = False
        duration = utils.qttimevalue(qtmovie.duration())
        
        if qtmovie is not None and duration > 0:
            allTracks = qtmovie.tracks()
            if len(qtmovie.tracks()) > 0:
                # Make sure we have at least one track with a non zero length
                allMedia = [track.media() for track in allTracks]
                for media in allMedia:
                    mediaType = media.attributeForKey_(QTMediaTypeAttribute)
                    mediaDuration = utils.qttimevalue(media.attributeForKey_(QTMediaDurationAttribute).QTTimeValue())
                    if mediaType in self.supported_media_types and mediaDuration > 0:
                        can_open = True
                        break

        return can_open
Exemplo n.º 4
0
def extract_thumbnail(qtmovie, target, width=0, height=0):
    try:
        qttime = qtmovie.duration()
        qttime = utils.qttimevalue_set(qttime, int(utils.qttimevalue(qttime) * 0.5))
        frame = qtmovie.frameImageAtTime_(qttime)
        if frame is objc.nil:
            return "Failure"

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

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

        source_size = frame.size()
        source_ratio = source_size.width / source_size.height
        destination_size = Foundation.NSSize(width, height)
        destination_ratio = destination_size.width / destination_size.height

        if source_ratio > destination_ratio:
            size = Foundation.NSSize(destination_size.width, destination_size.width / source_ratio)
            pos = Foundation.NSPoint(0, (destination_size.height - size.height) / 2.0)
        else:
            size = Foundation.NSSize(destination_size.height * source_ratio, destination_size.height)
            pos = Foundation.NSPoint((destination_size.width - size.width) / 2.0, 0)

        destination = AppKit.NSImage.alloc().initWithSize_(destination_size)
        try:
            destination.lockFocus()
            AppKit.NSGraphicsContext.currentContext().setImageInterpolation_(AppKit.NSImageInterpolationHigh)
            AppKit.NSColor.blackColor().set()
            AppKit.NSRectFill(((0, 0), destination_size))
            frame.drawInRect_fromRect_operation_fraction_(
                (pos, size), ((0, 0), source_size), AppKit.NSCompositeSourceOver, 1.0
            )
        finally:
            destination.unlockFocus()

        tiff_data = destination.TIFFRepresentation()
        image_rep = AppKit.NSBitmapImageRep.imageRepWithData_(tiff_data)
        properties = {AppKit.NSImageCompressionFactor: 0.8}
        jpeg_data = image_rep.representationUsingType_properties_(AppKit.NSJPEGFileType, properties)
        if jpeg_data is objc.nil:
            return "Failure"

        jpeg_data.writeToFile_atomically_(target, objc.YES)
    except Exception:
        return "Failure"

    return "Success"
Exemplo n.º 5
0
def extract_thumbnail(qtmovie, target, width=0, height=0):
    try:
        qttime = qtmovie.duration()
        qttime = utils.qttimevalue_set(qttime, int(utils.qttimevalue(qttime) * 0.5))
        frame = qtmovie.frameImageAtTime_(qttime)
        if frame is objc.nil:
            return "Failure"

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

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

        source_size = frame.size()
        source_ratio = source_size.width / source_size.height
        destination_size = Foundation.NSSize(width, height)
        destination_ratio = destination_size.width / destination_size.height

        if source_ratio > destination_ratio:
            size = Foundation.NSSize(destination_size.width, destination_size.width / source_ratio)
            pos = Foundation.NSPoint(0, (destination_size.height - size.height) / 2.0)
        else:
            size = Foundation.NSSize(destination_size.height * source_ratio, destination_size.height)
            pos = Foundation.NSPoint((destination_size.width - size.width) / 2.0, 0)

        destination = AppKit.NSImage.alloc().initWithSize_(destination_size)
        try:
            destination.lockFocus()
            AppKit.NSGraphicsContext.currentContext().setImageInterpolation_(AppKit.NSImageInterpolationHigh)
            AppKit.NSColor.blackColor().set()
            AppKit.NSRectFill(((0,0), destination_size))
            frame.drawInRect_fromRect_operation_fraction_((pos, size), ((0,0), source_size), AppKit.NSCompositeSourceOver, 1.0)
        finally:
            destination.unlockFocus()

        tiff_data = destination.TIFFRepresentation()
        image_rep = AppKit.NSBitmapImageRep.imageRepWithData_(tiff_data)
        properties = {AppKit.NSImageCompressionFactor: 0.8}
        jpeg_data = image_rep.representationUsingType_properties_(AppKit.NSJPEGFileType, properties)
        if jpeg_data is objc.nil:
            return "Failure"

        jpeg_data.writeToFile_atomically_(target, objc.YES)
    except Exception:
        return "Failure"

    return "Success"