Getting video width / height

Kip Warner kip at thevertigo.com
Sun Apr 7 17:57:48 PDT 2013


On Sat, 2013-04-06 at 10:20 +0100, Tim-Philipp Müller wrote:
> The PyGI API works pretty much exactly like the C API, the only thing
> where it's a bit different is when there are 'out' arguments (like &pad
> here) in the C API, then you might get a tuple with multiple return
> values in python.

Hey Tim. I wish it were that straightforward. My experience has been the
PyGI API tends to not always use namespaces with predictable names or
members. Sometimes it misses things completely in its bindings (.gir
issues), and other times it has them available, but the documentation
misses key things a developer needs (e.g. calling Gst.init()). But I
think that I will definitely consider using the C API over PyGI for
future applications until the documentation is more complete.

> Try something like this (untested):
> 
> from gi.repository import Gst
> Gst.init(None)
> playbin=Gst.ElementFactory.make('playbin',None)
> playbin.set_property('uri','file:///path/to/video')
> playbin.set_state(Gst.State.PLAYING)
> #wait for state change to finish, but max 5secs
> playbin.get_state(5000000000)
> pad=playbin.emit('get-video-pad',0)
> caps=pad.get_current_caps()
> print caps.to_string()

Thanks a lot. Here's what I'm trying...

        # Check the video's dimensions...
        ...
        self._playBin.set_state(Gst.State.PAUSED)
        self._playBin.get_state(5000000000)
        videoPad=self._playBin.emit("get-video-pad", 0)
        videoPadCapabilities=videoPad.get_current_caps()
        (success, videoWidth) = \
        videoPadCapabilities.get_structure(0).get_int("width")
        (success, videoHeight) = \
        videoPadCapabilities.get_structure(0).get_int("height")
        assert(success)

It works fine, but I'd like to understand better what the get_state call
and its magic number parameter is doing? I'm guessing you are trying to
buffer enough data for the video's metadata (e.g. width / height) to
have been extracted from the stream? But as usual, when I check
get_state's documentation, it leaves me wanting:

<http://pygstdocs.berlios.de/pygst-reference/class-gstelement.html#method-gstelement--get-state>

It doesn't look like it takes a parameter, or maybe it's overridden at
a higher level? Or am I just totally reading the API documentation
wrong? The link is, after all, for the old Python 2 bindings.

> I'm sure you can find a pygi tutorial somewhere so you don't have to
> stab in the dark any longer.

The tutorials are great, but they can cover only so much. That's really
where API documentation comes in. But if you try and look for complete
PyGI documentation anywhere, you won't find it. The best you'll be able
to come up with is generating your own via g-ir-doc-tool which are
still incomplete unfortunately. But hey, I'm grateful that Gst even
exists.

> On the python interpreter command line you can also do
> 
>   help(playbin)
>
> to see what methods are offered.

I haven't tried it for playbin, but I've found that most of the time I
need to use the help function, what I end up getting is a documentation
stub that was machine generated and lacking what I actually needed
unfortunately.

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20130407/07ba959c/attachment.pgp>


More information about the gstreamer-devel mailing list