videos with no audio streams - python gstreamer
Robert Kesterson
robertk at robertk.com
Wed Mar 14 08:51:15 PDT 2012
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
robertk at robertk.com
More information about the gstreamer-devel
mailing list