I want to create a python file that will output details of a audio stream. I found a good example (https://blogs.gnome.org/uraeus/2011/01/17/back-on-transmageddon-and-new-gstreamer-features/) but it uses GST 0.10 for my project I need Gstreamer 1.0. Below is the code I have done so far but it dosent really work as it should. Thanks in advance
#!/usr/bin/env python
import sys, os, time, thread
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstPbutils', '1.0')
from gi.repository import GObject, GLib, Gst, GstPbutils, GstTag
from gi.repository.GstPbutils import DiscovererAudioInfo,DiscovererStreamInfo, DiscovererInfo
Gst.init(None)
GObject.threads_init()
class discover:
def __init__(self):
print"..starting \n"
self.audiostreams=[]
self.error = None
def on_discovered(discoverer, ismedia, infile):
print '\non_discovered:', infile
discoverer.print_info()
def set_file(self,file):
self.file_uri=(file)
discoverer = GstPbutils.Discoverer.new(10 * Gst.SECOND)
self.info = discoverer.discover_uri(self.file_uri)
discoverer.connect('discovered',self.on_discovered)
print self.info.get_caps()
self.streaminfo=self.info.get_stream_info()
self.duration= (self.info.get_duration()/1000000000.0)
self.container = self.streaminfo.get_caps()
seekbool = self.info.get_seekable()
if seekbool is True:
self.seekable="Yes"
else:
self.seekable="No"
audiostreamcounter=-1
for i in self.info.get_stream_list():
audiostreamcounter=audiostreamcounter+1
if isinstance(i, GstPbutils.DiscovererAudioInfo):
audiocaps=i.get_caps()
self.audiostreams.append( self.info.get_codec_description(audiocaps))
self.audiotags=i.get_tags()
def discover(self, uri):
self.discovered.discover_uri_async(uri)
def create_report(self):
# Create properties report
print "Analyzing " + str(self.file_uri)
print "Topology:"
print " container: " + gst.pbutils.get_codec_description(self.container)
beancounter=0
for item in self.audiostreams:
beancounter=beancounter+1
print " audio stream " +str(beancounter) + ": " + self.audiostreams[beancounter-1]
print "Properties:"
print " Duration: " + str(self.duration)
print " Seekable: " + str(self.seekable)
print " Audio Tags: "
audiofile_tags = {}
for akey in self.audiotags.keys():
audiofile_tags[akey] = self.audiotags[akey]
print " " + akey, '\t', self.audiotags[akey]
if __name__=="__main__":
# if len(sys.argv)>1:
#file = sys.argv[1]
file = 'http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p?s=1455176207&e=1455190607&h=139a4cf601e4a2edf77bf475b$
#pwd = os.getcwd()
#filepath = os.path.join(pwd,file)
discovering = discover()
discovering.set_file(file)
discovering.create_report()