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 #os.environ['GST_DEBUG'] = '4,python:4'
27 #TODO: this should be skipped if video plugin is not enabled
29 gi
.require_version('Gst', '1.0')
30 from gi
.repository
import Gst
33 from mediagoblin
.media_types
.audio
.transcoders
import (AudioTranscoder
,
35 from mediagoblin
.media_types
.tools
import discover
40 audio
= tempfile
.NamedTemporaryFile()
41 src
= Gst
.ElementFactory
.make('audiotestsrc', None)
42 src
.set_property('num-buffers', 50)
43 enc
= Gst
.ElementFactory
.make('flacenc', None)
44 dst
= Gst
.ElementFactory
.make('filesink', None)
45 dst
.set_property('location', audio
.name
)
46 pipeline
= Gst
.Pipeline()
52 pipeline
.set_state(Gst
.State
.PLAYING
)
53 state
= pipeline
.get_state(3 * Gst
.SECOND
)
54 assert state
[0] == Gst
.StateChangeReturn
.SUCCESS
55 bus
= pipeline
.get_bus()
56 bus
.timed_pop_filtered(
58 Gst
.MessageType
.ERROR | Gst
.MessageType
.EOS
)
59 pipeline
.set_state(Gst
.State
.NULL
)
64 def create_data_for_test():
65 with
create_audio() as audio_name
:
66 second_file
= tempfile
.NamedTemporaryFile()
67 yield (audio_name
, second_file
.name
)
70 def test_transcoder():
72 Tests AudioTransocder's transcode method
74 transcoder
= AudioTranscoder()
75 with
create_data_for_test() as (audio_name
, result_name
):
76 transcoder
.transcode(audio_name
, result_name
, quality
=0.3,
77 progress_callback
=None)
78 info
= discover(result_name
)
79 assert len(info
.get_audio_streams()) == 1
80 transcoder
.transcode(audio_name
, result_name
, quality
=0.3,
81 mux_name
='oggmux', progress_callback
=None)
82 info
= discover(result_name
)
83 assert len(info
.get_audio_streams()) == 1
86 def test_thumbnails():
87 '''Test thumbnails generation.
89 The code below heavily repeats
90 audio.processing.CommonAudioProcessor.create_spectrogram
92 2. Convert it to OGG source for spectogram using transcoder
93 3. Create spectogram in jpg
96 thumbnailer
= AudioThumbnailer()
97 transcoder
= AudioTranscoder()
98 with
create_data_for_test() as (audio_name
, new_name
):
99 transcoder
.transcode(audio_name
, new_name
, mux_name
='oggmux')
100 thumbnail
= tempfile
.NamedTemporaryFile(suffix
='.jpg')
101 # fft_size below is copypasted from config_spec.ini
102 thumbnailer
.spectrogram(new_name
, thumbnail
.name
, width
=100,
104 assert imghdr
.what(thumbnail
.name
) == 'jpeg'