From ff3136d0e8179a91591b75b8955dd886a1a1b1d9 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Thu, 29 Mar 2012 22:52:39 +0200 Subject: [PATCH] Cleanded up video imports, removed PyGTK dependency --- mediagoblin/media_types/video/processing.py | 2 +- mediagoblin/media_types/video/transcoders.py | 66 +++++++++----------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py index 6a5ce364..d4b4e983 100644 --- a/mediagoblin/media_types/video/processing.py +++ b/mediagoblin/media_types/video/processing.py @@ -89,7 +89,7 @@ def process_video(entry): height=transcoder.dst_data.videoheight) # Create a temporary file for the video thumbnail - tmp_thumb = tempfile.NamedTemporaryFile() + tmp_thumb = tempfile.NamedTemporaryFile(suffix='.jpg') with tmp_thumb: # Create a thumbnail.jpg that fits in a 180x180 square diff --git a/mediagoblin/media_types/video/transcoders.py b/mediagoblin/media_types/video/transcoders.py index e0bd0d3d..088f6e1e 100644 --- a/mediagoblin/media_types/video/transcoders.py +++ b/mediagoblin/media_types/video/transcoders.py @@ -17,43 +17,38 @@ from __future__ import division import os -os.putenv('GST_DEBUG_DUMP_DOT_DIR', '/tmp') - import sys import logging import urllib +import multiprocessing +import gobject +import gst +import struct +import Image -_log = logging.getLogger(__name__) +from gst.extend import discoverer + +gobject.threads_init() CPU_COUNT = 2 -try: - import multiprocessing - try: - CPU_COUNT = multiprocessing.cpu_count() - except NotImplementedError: - _log.warning('multiprocessing.cpu_count not implemented') - pass -except ImportError: - _log.warning('Could not import multiprocessing, defaulting to 2 CPU cores') try: - import gtk -except ImportError: - raise Exception('Could not find pygtk') + CPU_COUNT = multiprocessing.cpu_count() +except NotImplementedError: + _log.warning('multiprocessing.cpu_count not implemented') -try: - import gobject - gobject.threads_init() -except ImportError: - raise Exception('gobject could not be found') +_log = logging.getLogger(__name__) -try: - import pygst - pygst.require('0.10') - import gst - from gst.extend import discoverer -except ImportError: - raise Exception('gst/pygst 0.10 could not be found') +os.putenv('GST_DEBUG_DUMP_DOT_DIR', '/tmp') + + +def pixbuf_to_pilbuf(buf): + data = list() + for i in range(0, len(buf), 3): + r, g, b = [i for i in struct.unpack('BBB', buf[i:i + 3])] + data.append((r, g, b)) + + return data class VideoThumbnailer: @@ -228,21 +223,18 @@ class VideoThumbnailer: width = filters["width"] height = filters["height"] - pixbuf = gtk.gdk.pixbuf_new_from_data( - buff.data, gtk.gdk.COLORSPACE_RGB, False, 8, - width, height, width * 3) + im = Image.new('RGB', (width, height)) - # NOTE: 200x136 is sort of arbitrary. it's larger than what - # the ui uses at the time of this writing. - # new_width, new_height = scaled_size((width, height), (200, 136)) + data = pixbuf_to_pilbuf(buff.data) - #pixbuf = pixbuf.scale_simple( - #new_width, new_height, gtk.gdk.INTERP_BILINEAR) + im.putdata(data) + + im.save(self.dest_path); - pixbuf.save(self.dest_path, 'jpeg') _log.info('Saved thumbnail') - del pixbuf + self.shutdown() + except gst.QueryError: pass return False -- 2.25.1