English 中文(简体)
Convert FLAC to MP3 with GStreamer +-030?
原标题:Convert FLAC to MP3 with GStreamer + Python?

这里,Im指挥试图复制:

gst-launch filesrc location=test.flac ! flacdec ! lame ! filesink location=test.mp3

当我掌管这一指挥时,它工作得很好。 我曾尝试用无uck的装饰器复制这种弹药。 我没有发现这些文字中的任何错误,但他们没有按预期工作:

当我管理这本文字时,我只收到一份空洞的MP3文件:

import gst
pipeline = gst.parse_launch( filesrc location="test.flac" ! flacdec ! lame ! filesink location="test.mp3" )
pipeline.set_state(gst.STATE_PLAYING)

当我管理这封信件时,我收到了腐败的议员3号档案:

import gst

converter = gst.Pipeline( converter )

source = gst.element_factory_make( filesrc ,  file-source )
source.set_property( location ,  test.flac )

decoder = gst.element_factory_make( flacdec ,  decoder )

encoder = gst.element_factory_make( lame ,  encoder )

sink = gst.element_factory_make( filesink ,  sink )
sink.set_property( location ,  test.mp3 )

converter.add(source, decoder, encoder, sink)

source.link(sink)

converter.set_state(gst.STATE_PLAYING)

任何人都知道我做错了什么?

最佳回答

Gstreamer uses GObject as a framework, so you need to run gobject.MainLoop() to start message flow in pipeline:

import gobject
import gst
pipeline = gst.parse_launch( filesrc location="test.flac" ! flacdec ! lame ! filesink location="test.mp3" )
pipeline.set_state(gst.STATE_PLAYING)

gobject.threads_init()
gobject.MainLoop().run()

In the second example you also need to run MainLoop and link all the pipeline elements (e.g. with element_link_many). You connected only source to sink, so your actual pipeline is just filesrc ! filesink.

兹更正成法典:

import gobject
import gst

converter = gst.Pipeline( converter )

source = gst.element_factory_make( filesrc ,  file-source )
source.set_property( location ,  test.flac )

decoder = gst.element_factory_make( flacdec ,  decoder )
encoder = gst.element_factory_make( lame ,  encoder )

sink = gst.element_factory_make( filesink ,  sink )
sink.set_property( location ,  test.mp3 )

converter.add(source, decoder, encoder, sink)
gst.element_link_many(source, decoder, encoder, sink)

converter.set_state(gst.STATE_PLAYING)

gobject.threads_init()
gobject.MainLoop().run()
问题回答

Some people end up at this answer looking for the command line / bash solution. Here is a good conversion script.

#!/bin/bash

#Take a lossless flac audio track from and transcode it as a constant rate mp3 playable on some older audio equipment that can t play mp4s or variable bit rate mp3 s.

if [ -z "$1" ];then
   echo usage: $0 [infile.flac]
   exit
fi

INFILE=$(basename $1)
WKDIR=$(dirname $1)
OUTFILE=$WKDIR/$( echo $INFILE | sed  s/.flac// ).mp3

#play ===================
#gst- launch filesrc location=1.flac 
#! flacdec 
#! autoaudiosink

#transcode ==============
gst-launch filesrc location=$INFILE 
! queue 
! flacdec 
! audioconvert 
! audioresample 
! lamemp3enc quality=2 target=bitrate bitrate=192 cbr=true 
! id3v2mux 
! filesink location=$OUTFILE




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签