1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2013 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from contextlib
import contextmanager
25 #TODO: this should be skipped if video plugin is not enabled
30 from mediagoblin
.media_types
.video
.transcoders
import capture_thumb
33 def create_data(suffix
):
34 video
= tempfile
.NamedTemporaryFile()
35 src
= gst
.element_factory_make('videotestsrc')
36 src
.set_property('num-buffers', 50)
37 enc
= gst
.element_factory_make('theoraenc')
38 mux
= gst
.element_factory_make('oggmux')
39 dst
= gst
.element_factory_make('filesink')
40 dst
.set_property('location', video
.name
)
41 pipeline
= gst
.Pipeline()
42 pipeline
.add(src
, enc
, mux
, dst
)
43 gst
.element_link_many(src
, enc
, mux
, dst
)
44 pipeline
.set_state(gst
.STATE_PLAYING
)
46 bus
= pipeline
.get_bus()
47 message
= bus
.timed_pop_filtered(gst
.CLOCK_TIME_NONE
,
48 gst
.MESSAGE_ERROR | gst
.MESSAGE_EOS
)
49 thumb
= tempfile
.NamedTemporaryFile(suffix
=suffix
)
50 pipeline
.set_state(gst
.STATE_NULL
)
51 yield (video
.name
, thumb
.name
)
54 #TODO: this should be skipped if video plugin is not enabled
55 def test_thumbnails():
57 Test thumbnails generation.
58 1. Create a video from gst's videotestsrc
62 #data create_data() as (video_name, thumbnail_name):
63 test_formats
= [('.png', 'png'), ('.jpg', 'jpeg'), ('.gif', 'gif')]
64 for suffix
, format
in test_formats
:
65 with
create_data(suffix
) as (video_name
, thumbnail_name
):
66 capture_thumb(video_name
, thumbnail_name
, width
=40)
68 assert imghdr
.what(thumbnail_name
) == format
69 # TODO: check height and width
70 # FIXME: it doesn't work with small width, say, 10px. This should be