converting between audio formats using GStreamer

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

converting between audio formats using GStreamer

cppb
hi,

I am a beginner and want to develop some apps using Python and GStreamer.

I am using the following pipeline to convert a wav file to mp3.


   m = gst.parse_launch("filesrc location=~/music.wav ! decodebin
! audioconvert !  lame ! filesink location=~/music.mp3")

  m.set_state(gst.STATE_PLAYING)

# the following prints a traceback
# d = m.get_duration(gst.FORMAT_TIME)

this creates mp3 file, but it is not complete. I tried time.sleep(seconds) call in the above code. This helped at least write some data to the mp3 file created.

for time.sleep() call, I tried different time intervals, but still it doesn't create the file with full data as the original.

I don't want to use time.sleep() and want to know if there is a better way to do this. Can anyone help?

Also tried the get_duration() method but it throws an error "query failed"
Reply | Threaded
Open this post in threaded view
|

Re: converting between audio formats using GStreamer

Tim-Philipp Müller-2
On Sun, 2010-01-31 at 10:36 -0800, cppb wrote:

> this creates mp3 file, but it is not complete. I tried time.sleep(seconds)
> call in the above code. This helped at least write some data to the mp3 file
> created.
>
> for time.sleep() call, I tried different time intervals, but still it
> doesn't create the file with full data as the original.
>
> I don't want to use time.sleep() and want to know if there is a better way
> to do this. Can anyone help?
>
> Also tried the get_duration() method but it throws an error "query failed"

You should use the pipeline's bus (GstBus) and wait for either an EOS
message or an ERROR message.

For progress udpates you could insert a progressreport element (from
gst-plugins-good) into the pipeline, somewhere between decodebin and the
encoder, and then you'll get regular element messages with the progress
(see progressreport element docs). Alternatively you could probably just
query decodebin directly for position/duration in TIME format instead of
the pipeline (since filesink will most likely drop the query as it
doesn't understand TIME format).

Cheers
 -Tim



------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: converting between audio formats using GStreamer

Ron McOuat
In reply to this post by cppb


On 10-01-31 10:36 AM, cppb wrote:

> hi,
>
> I am a beginner and want to develop some apps using Python and GStreamer.
>
> I am using the following pipeline to convert a wav file to mp3.
>
>
>     m = gst.parse_launch("filesrc location=~/music.wav ! decodebin
> ! audioconvert !  lame ! filesink location=~/music.mp3")
>
>    m.set_state(gst.STATE_PLAYING)
>
> # the following prints a traceback
> # d = m.get_duration(gst.FORMAT_TIME)
>
> this creates mp3 file, but it is not complete. I tried time.sleep(seconds)
> call in the above code. This helped at least write some data to the mp3 file
> created.
>
> for time.sleep() call, I tried different time intervals, but still it
> doesn't create the file with full data as the original.
>
> I don't want to use time.sleep() and want to know if there is a better way
> to do this. Can anyone help?
>
> Also tried the get_duration() method but it throws an error "query failed"
>
>    
Check out this URL for Python info

http://pygstdocs.berlios.de/

The tutorials should help
http://pygstdocs.berlios.de/pygst-tutorial/index.html

Example 2.3 is a command line version of a program which plays a file so
you should be able to put your gst_launch into the __init__ function and
replace the gst.element_factory_make("playbin2",... As you can see from
the program you need to run an event loop with glib.Mainloop(),
loop.run() and listen for the EOS message which occurs once the input
file is consumed with the thread that runs CLI_Main.start().

You could also use gst-launch as a general command line tool and feed it
the pipeline definition that you use for gst.parse_launch().


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: converting between audio formats using GStreamer

cppb
In reply to this post by cppb
Thanks Ron and Tim!

The tutorial that Ron suggested was very useful and solved this issue.