Discussion:
[gst-devel] Synchronizing audio stream with system clock
Steven Barth
2010-01-31 19:54:35 UTC
Permalink
Hello,

I'm new to gstreamer and need a hint on how to synchronize an audio stream
from a filesrc or fdsrc with the system clock.


My setup is like this:
I have a little Python application that utilizes gstreamer to convert a raw
CD-like audio stream into vorbis and stream it with an fdsink through a pipe
to another application.



I use the following code snippet (Python).


pipeline = gst.parse_launch("filesrc location=/home/steven/03.pcm ! capsfilter
caps=audio/x-raw-int,rate=44100,channels=2,depth=16,signed=true ! identity
datarate=176400 sync=true ! audioresample ! audioconvert ! vorbisenc ! oggmux
! fdsink fd="+str(pipeout))
pipeline.set_clock(gst.system_clock_obtain())
pipeline.set_state(gst.STATE_PLAYING)



It kind of works, but it encodes the data as fast as it can. I however want it
to synchronize the playback / encoding speed with real time. I want to avoid
doing the time handling on the application at the other end of the pipe
because I dont't want to touch or analyse the data there in detail.

As you can see I tried to set the pipeline clock to the system clock and use
identity to set the datarate and synchronize it with the clock but
unfortunately it does not work.

I probably misunderstood some of the concepts of gstreamer here or just forgot
about something. Please give me a hint on how I can solve this problem.


Cheers,
Steven
Tim-Philipp Müller
2010-01-31 20:23:49 UTC
Permalink
Post by Steven Barth
I'm new to gstreamer and need a hint on how to synchronize an audio stream
from a filesrc or fdsrc with the system clock.
I have a little Python application that utilizes gstreamer to convert a raw
CD-like audio stream into vorbis and stream it with an fdsink through a pipe
to another application.
I use the following code snippet (Python).
pipeline = gst.parse_launch("filesrc location=/home/steven/03.pcm ! capsfilter
caps=audio/x-raw-int,rate=44100,channels=2,depth=16,signed=true ! identity
datarate=176400 sync=true ! audioresample ! audioconvert ! vorbisenc ! oggmux
! fdsink fd="+str(pipeout))
Instead of the capsfilter ! identity datarate=..., better use the
audioparse element from gst-plugins-bad.

As for syncing against the clock, fdsink sync=true, should be all that's
needed really (oggmux should output buffers that are properly
timestamped).
Post by Steven Barth
pipeline.set_clock(gst.system_clock_obtain())
I don't think you need this either.

Cheers
-Tim
Steven Barth
2010-01-31 21:38:51 UTC
Permalink
Thanks you very much for your help.
I changed the code to:

pipeline = gst.parse_launch("filesrc location=/home/steven/03.pcm ! audioparse
! identity sync=true ! audioresample ! audioconvert ! vorbisenc ! oggmux !
fdsink sync=true fd="+str(pipeout))
pipeline.set_state(gst.STATE_PLAYING)

and now it works fine.
It seems it needs the "identity sync=true" though otherwise the syncing does
not work. The sync parameter on the fdsink doesn't seem to have any effect in
this case.

Cheers,
Steven

Loading...