Getting sample rate / sample format/ channels cound of playbin in python

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

Getting sample rate / sample format/ channels cound of playbin in python

Pavel Hofman
Hello,

I am sorry for this very likely simple question yet I could not find any
example of this.

Please how can rate/channels information be read in python from the
playbin element? I found the "get-audio-pad" signal of playbin which
likely provides these capabilities but how can I get the pad from the
"playbin" element in python (gstreamer 1.0, Gst)?

I very much appreciate any help. Thank you.

Best regards,

Pavel.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Getting sample rate / sample format/ channels cound of playbin in python

Tim Müller
On Wed, 2017-12-06 at 23:16 +0100, Pavel Hofman wrote:

Hi,

> Please how can rate/channels information be read in python from the
> playbin element? I found the "get-audio-pad" signal of playbin which
> likely provides these capabilities but how can I get the pad from
> the  "playbin" element in python (gstreamer 1.0, Gst)?

The signal gives you the pad. From the pad you can query the caps with
something like

 caps = pad.get_current_caps()

and then from the caps you can get the rate/channel fields from the
first caps structure:

 rate = caps[0]['rate']
 chans = caps[0]['channels']

or so.

If you don't actually need to play the file you can also use the
GstDiscoverer API from the pbutils library instead.

With playbin3 this is slightly nicer, you get a STREAM_COLLECTION
message on the bus with the streams and can query the info (caps etc.)
from the stream object instead.

Cheers
 -Tim
--
Tim Müller, Centricular Ltd - http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Getting sample rate / sample format/ channels cound of playbin in python

Pavel Hofman
Hi Tim,

 >
 > The signal gives you the pad. From the pad you can query the caps with
 > something like
 >
 >   caps = pad.get_current_caps()
 >
 > and then from the caps you can get the rate/channel fields from the
 > first caps structure:
 >
 >   rate = caps[0]['rate']
 >   chans = caps[0]['channels']
Thanks a lot. Actually I was able to find examples of getting the rate
from the pad -> caps, but I cannot find/do not know how to get the
correct pad from the gst 1.0 playbin (playbin2 ). May I ask you for help
with this?

 >
 > If you don't actually need to play the file you can also use the
 > GstDiscoverer API from the pbutils library instead.

Very good to know. For this I am using Python audio tools
http://audiotools.sourceforge.net/ but perhaps standardizing on
gstreamer would be an advantage.>

 > With playbin3 this is slightly nicer, you get a STREAM_COLLECTION
 > message on the bus with the streams and can query the info (caps etc.)
 > from the stream object instead.

I will take a look at playbin3, my project needs no backward
compatibility. Is playbin3 stable enough?

I very much appreciate your help, thanks a lot.

Pavel.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Getting sample rate / sample format/ channels cound of playbin in python

Tim Müller
On Fri, 2017-12-08 at 08:01 +0100, Pavel Hofman wrote:

Hi,

> Thanks a lot. Actually I was able to find examples of getting the
> rate  from the pad -> caps, but I cannot find/do not know how to get
> the  correct pad from the gst 1.0 playbin (playbin2 ). May I ask you
> for help  with this?

Ah, I think something like this should work (untested).

  pad = playbin.emit('get-audio-pad', 0)

where 0 is the audio stream number (you can get the number of
audio/video/subtitle streams via the 'n-audio' etc. properties.

> I will take a look at playbin3, my project needs no backward
> compatibility. Is playbin3 stable enough?

Depends what you're doing exactly, but should be, yes. Please file any
issues you're encountering in bugzilla.

Cheers
-Tim

--
Tim Müller, Centricular Ltd - http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Getting sample rate / sample format/ channels cound of playbin in python

Pavel Hofman
Hi Tim,

Dne 8.12.2017 v 10:47 Tim Müller napsal(a):
> On Fri, 2017-12-08 at 08:01 +0100, Pavel Hofman wrote:
>
>
> Ah, I think something like this should work (untested).
>
>    pad = playbin.emit('get-audio-pad', 0)

Works like charm, thanks a lot! Please when is the proper time to check
the caps of the pad? When pad.get_current_caps() is called too early,
the result is None. Is there a specific message in which handler to get
the caps the caps? Is there perhaps a way to register a callback and
monitor these capabilities for change? I need to send a message further
down my system when the audio parameters change.

Please what specific pad of the whole pipeline graph does the
"get-audio-pad" signal returns? Is it the pad which my audio sink is
attached to in playbin by calling

playbin.set_property('audio-sink', audio_sink) ?

Thanks a lot.

>> I will take a look at playbin3, my project needs no backward
>> compatibility. Is playbin3 stable enough?
>
> Depends what you're doing exactly, but should be, yes. Please file any
> issues you're encountering in bugzilla.

Thanks a lot, I will try to install playbin3 into my mint and test it.

Best regards,

Pavel.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Getting sample rate / sample format/ channels cound of playbin in python

Tim Müller
On Fri, 2017-12-08 at 19:29 +0100, Pavel Hofman wrote:

> Works like charm, thanks a lot! Please when is the proper time to
> check  the caps of the pad? When pad.get_current_caps() is called too
> early,  the result is None. Is there a specific message in which
> handler to get  the caps the caps?

When you get an ASYNC_DONE message on the pipeline's bus.


> Is there perhaps a way to register a callback and
> monitor these capabilities for change? I need to send a message
> further down my system when the audio parameters change.

You can connect to the pad's "notify::caps" signal. This is a GObject
feature, and the callback will be called from a streaming thread.

Alternatively you can use the python equivalent of

  gst_element_add_property_deep_notify_watch()

probably something like

  playbin.add_property_deep_notify_watch('caps', True)

then you will get messages on the bus whenever the caps on any pad in
the pipeline change. You will then need to filter for the right pads
and ignore the others.

If you set your own audio-sink and video-sink on playbin(3) you can
also use this API on the sink elements, then you just get notified of
changes in the effective output caps.


> Please what specific pad of the whole pipeline graph does the
> "get-audio-pad" signal returns? Is it the pad which my audio sink is
> attached to in playbin by calling
>
> playbin.set_property('audio-sink', audio_sink) ?

No, it's a pad somewhere inside playbin before input selection takes
place (so you can get the caps/metadata for pads even if the stream is
not currently active/selected).

Cheers
-Tim

--
Tim Müller, Centricular Ltd - http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Getting sample rate / sample format/ channels cound of playbin in python

Pavel Hofman
Hi Tim,

Dne 8.12.2017 v 19:35 Tim Müller napsal(a):
> On Fri, 2017-12-08 at 19:29 +0100, Pavel Hofman wrote:
>
>> Works like charm, thanks a lot! Please when is the proper time to
>> check  the caps of the pad? When pad.get_current_caps() is called too
>> early,  the result is None. Is there a specific message in which
>> handler to get  the caps the caps?
>
> When you get an ASYNC_DONE message on the pipeline's bus.

Works great again. In the end I put the check to Message.STREAM_START
handler and now I get correct audio params any time the stream is
changed (scheduled in on-about-to -finish).

>> Is there perhaps a way to register a callback and
>> monitor these capabilities for change? I need to send a message
>> further down my system when the audio parameters change.
>
> You can connect to the pad's "notify::caps" signal. This is a GObject
> feature, and the callback will be called from a streaming thread.
>
> Alternatively you can use the python equivalent of
>
>    gst_element_add_property_deep_notify_watch()
>
> probably something like
>
>    playbin.add_property_deep_notify_watch('caps', True)
>
> then you will get messages on the bus whenever the caps on any pad in
> the pipeline change. You will then need to filter for the right pads
> and ignore the others.

Thanks, I will keep your insightful information for further
developement. For now I think the STREAM_START handler will suffice.

> If you set your own audio-sink and video-sink on playbin(3) you can
> also use this API on the sink elements, then you just get notified of
> changes in the effective output caps.

Will look at that.

>
> No, it's a pad somewhere inside playbin before input selection takes
> place (so you can get the caps/metadata for pads even if the stream is
> not currently active/selected).

The audio-pad works just perfect, I always get correct audiodetails of
the currently played file/stream.

Tim, I very much appreciate your answers. You have pushed me forward a lot!

Regards,

Pavel.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel