import mutagen
-class Mp3Encoder(Processor):
+class Mp3Encoder(GstEncoder):
""" gstreamer-based mp3 encoder """
implements(IEncoder)
@interfacedoc
def setup(self, channels=None, samplerate=None, nframes=None):
- self.channels = channels
super(Mp3Encoder, self).setup(channels, samplerate, nframes)
- #TODO: open file for writing
- # the output data format we want
+
self.pipe = '''appsrc name=src
! audioconvert
! lamemp3enc target=quality quality=2 encoding-engine-quality=standard ! id3v2mux
self.pipe += '! filesink location=%s async=False sync=False ' % self.filename
else:
self.pipe += '! queue ! appsink name=app sync=False '
-
- self.pipeline = gst.parse_launch(self.pipe)
- # store a pointer to appsrc in our encoder object
- self.src = self.pipeline.get_by_name('src')
- # store a pointer to appsink in our encoder object
- self.app = self.pipeline.get_by_name('app')
-
- srccaps = gst.Caps("""audio/x-raw-float,
- endianness=(int)1234,
- channels=(int)%s,
- width=(int)32,
- rate=(int)%d""" % (int(channels), int(samplerate)))
- self.src.set_property("caps", srccaps)
-
- self.pipeline.set_state(gst.STATE_PLAYING)
+
+ self.start_pipeline(channels, samplerate)
@staticmethod
@interfacedoc
id3.save()
except:
raise IOError('EncoderError: cannot write tags')
-
- @interfacedoc
- def process(self, frames, eod=False):
- self.eod = eod
- buf = numpy_array_to_gst_buffer(frames)
- self.src.emit('push-buffer', buf)
- if self.streaming:
- self.chunk = self.app.emit('pull-buffer')
- if self.eod and self.metadata and self.filename:
- self.write_metadata()
- return frames, eod
class Mp3EncoderSubprocess(object):
"""MP3 encoder in a subprocess pipe"""
stream = self.core_process(command, source)
for __chunk in stream:
yield __chunk
-