diff options
author | Boris Bobrov <breton@cynicmansion.ru> | 2014-05-29 14:50:32 +0400 |
---|---|---|
committer | Boris Bobrov <breton@cynicmansion.ru> | 2015-02-15 05:52:22 +0300 |
commit | 7e266d5a374fe16355375f82be45e2c5707450d1 (patch) | |
tree | 532d4ecbdbf6747876f6ea1c4b273e2ea2b0fd45 /mediagoblin/tests | |
parent | a02de38f9105bd6ffa54133d4b1ccdd33ec34034 (diff) | |
download | mediagoblin-7e266d5a374fe16355375f82be45e2c5707450d1.tar.lz mediagoblin-7e266d5a374fe16355375f82be45e2c5707450d1.tar.xz mediagoblin-7e266d5a374fe16355375f82be45e2c5707450d1.zip |
Rewrite thumbnailer
Previous thumbnailer didn't always work properly. It was also not ready
to be ported to GStreamer 1.0
The rewrite makes it shorter, more pythonic and prepares it for porting.
- no longer uses playbin2;
- is tested
- logs some events
- previous thumbnailer is removed
Diffstat (limited to 'mediagoblin/tests')
-rw-r--r-- | mediagoblin/tests/test_video.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/mediagoblin/tests/test_video.py b/mediagoblin/tests/test_video.py new file mode 100644 index 00000000..0fe58f60 --- /dev/null +++ b/mediagoblin/tests/test_video.py @@ -0,0 +1,71 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2013 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import tempfile +import shutil +import os +import pytest +from contextlib import contextmanager +import logging +import imghdr + +#TODO: this should be skipped if video plugin is not enabled +import pygst +pygst.require('0.10') +import gst + +from mediagoblin.media_types.video.transcoders import capture_thumb + +@contextmanager +def create_data(suffix): + video = tempfile.NamedTemporaryFile() + src = gst.element_factory_make('videotestsrc') + src.set_property('num-buffers', 50) + enc = gst.element_factory_make('theoraenc') + mux = gst.element_factory_make('oggmux') + dst = gst.element_factory_make('filesink') + dst.set_property('location', video.name) + pipeline = gst.Pipeline() + pipeline.add(src, enc, mux, dst) + gst.element_link_many(src, enc, mux, dst) + pipeline.set_state(gst.STATE_PLAYING) + # wait for finish + bus = pipeline.get_bus() + message = bus.timed_pop_filtered(gst.CLOCK_TIME_NONE, + gst.MESSAGE_ERROR | gst.MESSAGE_EOS) + thumb = tempfile.NamedTemporaryFile(suffix=suffix) + pipeline.set_state(gst.STATE_NULL) + yield (video.name, thumb.name) + + +#TODO: this should be skipped if video plugin is not enabled +def test_thumbnails(): + ''' + Test thumbnails generation. + 1. Create a video from gst's videotestsrc + 3. Capture thumbnail + 4. Remove it + ''' + #data create_data() as (video_name, thumbnail_name): + test_formats = [('.png', 'png'), ('.jpg', 'jpeg'), ('.gif', 'gif')] + for suffix, format in test_formats: + with create_data(suffix) as (video_name, thumbnail_name): + capture_thumb(video_name, thumbnail_name, width=40) + # check if png + assert imghdr.what(thumbnail_name) == format + # TODO: check height and width + # FIXME: it doesn't work with small width, say, 10px. This should be + # fixed somehow |