def transcode(self, photo, **kwargs): log.info("Transcode Photo: %s" % kwargs) #default format is the current format, and default is no resize formats = kwargs.get("formats", photo.get_mimetype()).split(',') newSize = kwargs.get("size", NO_RESIZE) #resize if necessary if newSize != NO_RESIZE: w, h = photo.get_photo_size() width, height = Utils.get_proportional_resize( desiredW=int(newSize.split('x')[0]), desiredH=int(newSize.split('x')[1]), currentW=int(w), currentH=int(h)) doResize = True else: width = None height = None doResize = False #check if the photo is in the allowed format, otherwise we must convert it mimeType = photo.get_mimetype() doReformat = False if mimeType not in formats: #convert photo to default format mimeType = kwargs.get("default-format", "image/jpeg") doReformat = True #convert the mimetype to the image type for gdk pixbuf save method format = self._get_pixbuf_capabilities()[mimeType] self._convert(photo, format, width, height, doResize, doReformat) return photo
def transcode_video(self, video, **kwargs): #FIXME: This code fails with flv. Should we add an exception? mimetype = video.get_mimetype() if not Video.mimetype_is_video(mimetype): log.debug("File %s is not video type: %s" % (video, mimetype)) return None #Check if we need to convert the video if kwargs.get('mimetype', None) == mimetype: #Check if the video is smaller or equal then the required dimensions #If it does, we dont need to convert it width = kwargs.get('width', None) height = kwargs.get('height', None) if width or height: (video_width, video_height) = video.get_video_size() if (not width or video_width <= width) and \ (not height or video_height <= height): log.debug( "Video matches the required dimensions, not converting" ) return video else: #There is no required dimensions, and we match the mimetype, #so we dont convert it log.debug("Video matches the mimetype, not converting") return video kwargs['in_file'] = video.get_local_uri() kwargs['out_file'] = self._get_output_file(kwargs['in_file'], **kwargs) if os.path.exists(kwargs['out_file']): log.debug('Converted video already exists, using it') return Video.Video(kwargs['out_file']) if 'width' in kwargs and 'height' in kwargs: (width, height) = video.get_video_size() if not width and not height: log.debug("Can't get video dimensions") return None kwargs['width'], kwargs['height'] = Utils.get_proportional_resize( desiredW=int(kwargs['width']), desiredH=int(kwargs['height']), currentW=int(width), currentH=int(height)) log.debug("Scaling video to %swx%sh" % (kwargs['width'], kwargs['height'])) try: gst_converter = GStreamerConverter() sucess = gst_converter.convert(**kwargs) except Exception, e: log.debug("Error transcoding video: %s" % e) return None
def transcode_video(self, video, **kwargs): #FIXME: This code fails with flv. Should we add an exception? mimetype = video.get_mimetype() if not Video.mimetype_is_video(mimetype): log.debug("File %s is not video type: %s" % (video,mimetype)) return None #Check if we need to convert the video if kwargs.get('mimetype', None) == mimetype: #Check if the video is smaller or equal then the required dimensions #If it does, we dont need to convert it width = kwargs.get('width', None) height = kwargs.get('height', None) if width or height: (video_width, video_height) = video.get_video_size() if (not width or video_width <= width) and \ (not height or video_height <= height): log.debug("Video matches the required dimensions, not converting") return video else: #There is no required dimensions, and we match the mimetype, #so we dont convert it log.debug("Video matches the mimetype, not converting") return video kwargs['in_file'] = video.get_local_uri() kwargs['out_file'] = self._get_output_file(kwargs['in_file'], **kwargs) if os.path.exists(kwargs['out_file']): log.debug('Converted video already exists, using it') return Video.Video(kwargs['out_file']) if 'width' in kwargs and 'height' in kwargs: (width, height) = video.get_video_size() if not width and not height: log.debug("Can't get video dimensions") return None kwargs['width'],kwargs['height'] = Utils.get_proportional_resize( desiredW=int(kwargs['width']), desiredH=int(kwargs['height']), currentW=int(width), currentH=int(height) ) log.debug("Scaling video to %swx%sh" % (kwargs['width'],kwargs['height'])) try: gst_converter = GStreamerConverter() sucess = gst_converter.convert(**kwargs) except Exception, e: log.debug("Error transcoding video: %s" % e) return None
def transcode(self, photo, **kwargs): log.info("Transcode Photo: %s" % kwargs) #default format is the current format, and default is no resize formats = kwargs.get("formats",photo.get_mimetype()).split(',') newSize = kwargs.get("size",NO_RESIZE) #resize if necessary if newSize != NO_RESIZE: w,h = photo.get_photo_size() width,height = Utils.get_proportional_resize( desiredW=int(newSize.split('x')[0]), desiredH=int(newSize.split('x')[1]), currentW=int(w), currentH=int(h) ) doResize = True else: width = None height = None doResize = False #check if the photo is in the allowed format, otherwise we must convert it mimeType = photo.get_mimetype() doReformat = False if mimeType not in formats: #convert photo to default format mimeType = kwargs.get("default-format","image/jpeg") doReformat = True #convert the mimetype to the image type for gdk pixbuf save method format = self._get_pixbuf_capabilities()[mimeType] self._convert( photo, format, width, height, doResize, doReformat ) return photo
if is_online(): ts = Utils.get_http_resource_last_modified("http://files.conduit-project.org/Conduit-0.3.0-screencast-small.mpeg") ok("Got mtime (timestamp) of http resource", ts == 1178419656.0) mimetype = Utils.get_http_resource_mimetype("http://files.conduit-project.org/Conduit-0.3.0-screencast-small.mpeg") ok("Got mimetype of http resource", mimetype == 'video/mpeg') size = Utils.get_http_resource_size("http://files.conduit-project.org/Conduit-0.3.0-screencast-small.mpeg") ok("Got size of http resource", size == 4792300) date1 = Utils.get_http_resource_last_modified("http://foo.com/1/2/3") ok("Got no mtime from missing http resource", date1 == None) #Test facebook dimensions # 1024x768 -> 604x453 w,h = Utils.get_proportional_resize(604,604,1024,768) ok("Resized Image into facebook dimensions (%sx%s)" % (w,h), w==604 and h==453) # 480x640 -> 453x604 # w,h = Utils.get_proportional_resize(604,604,480,640) # ok("Resized Image into facebook dimensions (%sx%s)" % (w,h), w==453 and h==604) w,h = Utils.get_proportional_resize(100,-1,200,100) ok("Resized Image in one dimension OK", w==100 and h==50) w,h = Utils.get_proportional_resize(-1,1000,200,100) ok("Resized Image in one dimension OK", w==2000 and h==1000) w,h = Utils.get_proportional_resize(200,1000,200,100) ok("Resized Image in both dimension OK", w==2000 and h==1000) w,h = Utils.get_proportional_resize(2000,100,200,100) ok("Resized Image in both dimension OK", w==2000 and h==1000) w,h = Utils.get_proportional_resize(10,5,200,100) ok("Resized Image in both dimension OK", w==10 and h==5)