videos with no audio streams - python gstreamer

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

videos with no audio streams - python gstreamer

Adrian Ulges
Hi there,

I'm using gstreamer for python (python-gst0.10) for extracting audio
streams from video files:

=======================
import gst

command = ("filesrc location=%s ! "
    "decodebin2  name=dec dec.src1 ! "
    "audioconvert ! "
    "audio/x-raw-float, width=64, channels=1 ! "
    "appsink name=sink sync=false "
    %(filename))

pipeline = gst.parse_launch(command)
pipeline.set_state(gst.STATE_PLAYING)
sink = pipeline.get_by_name('sink')
data = sink.emit('pull-buffer')
========================

The problem is: when opening a video with no audio stream, the code
freezes on the 'sink.emit' statement.

My question is: Is there a way to check files for the presence of
audio streams (preferably in python-gst), or is there a way to check a
pipeline before pulling data, or can I get it to throw an error
instead of freezing?

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

Re: videos with no audio streams - python gstreamer

Robert Kesterson
On 3/13/2012 12:02 PM, Adrian Ulges wrote:

> Hi there,
>
> I'm using gstreamer for python (python-gst0.10) for extracting audio
> streams from video files:
>
> =======================
> import gst
>
> command = ("filesrc location=%s ! "
>      "decodebin2  name=dec dec.src1 ! "
>      "audioconvert ! "
>      "audio/x-raw-float, width=64, channels=1 ! "
>      "appsink name=sink sync=false "
>      %(filename))
>
> pipeline = gst.parse_launch(command)
> pipeline.set_state(gst.STATE_PLAYING)
> sink = pipeline.get_by_name('sink')
> data = sink.emit('pull-buffer')
> ========================
>
> The problem is: when opening a video with no audio stream, the code
> freezes on the 'sink.emit' statement.
>
> My question is: Is there a way to check files for the presence of
> audio streams (preferably in python-gst), or is there a way to check a
> pipeline before pulling data, or can I get it to throw an error
> instead of freezing?

You can use discoverer to find out about the audio streams.  Something
along the lines of:

         import gst.pbutils

         discoverer = gst.pbutils.Discoverer(50000000000)
         info = discoverer.discover_uri(filename)    # needs to start
with file:// for local files
         info.get_stream_info()
         for sinfo in info.get_stream_list():
             if isinstance(info, gst.pbutils.DiscovererAudioInfo):
                 # you've got audio
                 ...
             elif isinstance(info, gst.pbutils.DiscovererVideoInfo):
                 # you've got video
                 ...

--
   Robert Kesterson
   [hidden email]

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

Re: videos with no audio streams - python gstreamer

Robert Kesterson
On 3/14/2012 10:51 AM, Robert Kesterson wrote:

> On 3/13/2012 12:02 PM, Adrian Ulges wrote:
>> Hi there,
>>
>> I'm using gstreamer for python (python-gst0.10) for extracting audio
>> streams from video files:
>> ...
>> The problem is: when opening a video with no audio stream, the code
>> freezes on the 'sink.emit' statement.
>>
>> My question is: Is there a way to check files for the presence of
>> audio streams (preferably in python-gst), or is there a way to check a
>> pipeline before pulling data, or can I get it to throw an error
>> instead of freezing?
>
> You can use discoverer to find out about the audio streams.  Something
> along the lines of:
>
>         import gst.pbutils
>
>         discoverer = gst.pbutils.Discoverer(50000000000)
>         info = discoverer.discover_uri(filename)    # needs to start
> with file:// for local files
>         info.get_stream_info()
>         for sinfo in info.get_stream_list():
>             if isinstance(info, gst.pbutils.DiscovererAudioInfo):
>                 # you've got audio
>                 ...
>             elif isinstance(info, gst.pbutils.DiscovererVideoInfo):
>                 # you've got video
>                 ...

Oops.  Those isinstance lines should be about "sinfo", not "info".  But
hopefully you get the idea.

--
   Robert Kesterson
   [hidden email]

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