Cleanded up video imports, removed PyGTK dependency
This commit is contained in:
parent
90b25eb2d1
commit
ff3136d0e8
@ -89,7 +89,7 @@ def process_video(entry):
|
|||||||
height=transcoder.dst_data.videoheight)
|
height=transcoder.dst_data.videoheight)
|
||||||
|
|
||||||
# Create a temporary file for the video thumbnail
|
# Create a temporary file for the video thumbnail
|
||||||
tmp_thumb = tempfile.NamedTemporaryFile()
|
tmp_thumb = tempfile.NamedTemporaryFile(suffix='.jpg')
|
||||||
|
|
||||||
with tmp_thumb:
|
with tmp_thumb:
|
||||||
# Create a thumbnail.jpg that fits in a 180x180 square
|
# Create a thumbnail.jpg that fits in a 180x180 square
|
||||||
|
@ -17,43 +17,38 @@
|
|||||||
from __future__ import division
|
from __future__ import division
|
||||||
|
|
||||||
import os
|
import os
|
||||||
os.putenv('GST_DEBUG_DUMP_DOT_DIR', '/tmp')
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import urllib
|
import urllib
|
||||||
|
import multiprocessing
|
||||||
|
import gobject
|
||||||
|
import gst
|
||||||
|
import struct
|
||||||
|
import Image
|
||||||
|
|
||||||
|
from gst.extend import discoverer
|
||||||
|
|
||||||
|
gobject.threads_init()
|
||||||
|
|
||||||
|
CPU_COUNT = 2
|
||||||
|
|
||||||
|
try:
|
||||||
|
CPU_COUNT = multiprocessing.cpu_count()
|
||||||
|
except NotImplementedError:
|
||||||
|
_log.warning('multiprocessing.cpu_count not implemented')
|
||||||
|
|
||||||
_log = logging.getLogger(__name__)
|
_log = logging.getLogger(__name__)
|
||||||
|
|
||||||
CPU_COUNT = 2
|
os.putenv('GST_DEBUG_DUMP_DOT_DIR', '/tmp')
|
||||||
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')
|
|
||||||
|
|
||||||
try:
|
def pixbuf_to_pilbuf(buf):
|
||||||
import gobject
|
data = list()
|
||||||
gobject.threads_init()
|
for i in range(0, len(buf), 3):
|
||||||
except ImportError:
|
r, g, b = [i for i in struct.unpack('BBB', buf[i:i + 3])]
|
||||||
raise Exception('gobject could not be found')
|
data.append((r, g, b))
|
||||||
|
|
||||||
try:
|
return data
|
||||||
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')
|
|
||||||
|
|
||||||
|
|
||||||
class VideoThumbnailer:
|
class VideoThumbnailer:
|
||||||
@ -228,21 +223,18 @@ class VideoThumbnailer:
|
|||||||
width = filters["width"]
|
width = filters["width"]
|
||||||
height = filters["height"]
|
height = filters["height"]
|
||||||
|
|
||||||
pixbuf = gtk.gdk.pixbuf_new_from_data(
|
im = Image.new('RGB', (width, height))
|
||||||
buff.data, gtk.gdk.COLORSPACE_RGB, False, 8,
|
|
||||||
width, height, width * 3)
|
|
||||||
|
|
||||||
# NOTE: 200x136 is sort of arbitrary. it's larger than what
|
data = pixbuf_to_pilbuf(buff.data)
|
||||||
# the ui uses at the time of this writing.
|
|
||||||
# new_width, new_height = scaled_size((width, height), (200, 136))
|
|
||||||
|
|
||||||
#pixbuf = pixbuf.scale_simple(
|
im.putdata(data)
|
||||||
#new_width, new_height, gtk.gdk.INTERP_BILINEAR)
|
|
||||||
|
im.save(self.dest_path);
|
||||||
|
|
||||||
pixbuf.save(self.dest_path, 'jpeg')
|
|
||||||
_log.info('Saved thumbnail')
|
_log.info('Saved thumbnail')
|
||||||
del pixbuf
|
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
|
|
||||||
except gst.QueryError:
|
except gst.QueryError:
|
||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user