我想创建一个python文件,它将输出音频流的详细信息。我找到了一个很好的例子(https://blogs.gnome.org/uraeus/2011/01/17/back-on-transmageddon-and-new-gstreamer-features/),但它在我的项目中使用GST 0.10我需要Gstreamer 1.0。下面是我到目前为止所做的代码,但它确实可以正常工作。提前致谢
#!/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()
答案 0 :(得分:0)
应用程序端的更改很少,因此更多的是运行和修复错误。
这应该有助于改变: http://cgit.freedesktop.org/gstreamer/gstreamer/tree/docs/random/porting-to-1.0.txt https://wiki.ubuntu.com/Novacut/GStreamer1.0
C API通常可以直接映射到python。一旦你告诉我们究竟什么不起作用,就可以给出更准确的答案。