![](/img/trans.png)
[英]How to receive byte-stream by using gstreamer with python subprocess module or gst-launch-1.0 command?
[英]How do you get a stream details using Gst 1.0
我想創建一個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()
應用程序方面的更改很小,因此更多的問題是運行和修復錯誤所在。
這應該對更改有所幫助: http : //cgit.freedesktop.org/gstreamer/gstreamer/tree/docs/random/porting-to-1.0.txt https://wiki.ubuntu.com/Novacut/GStreamer1.0
通常,可以將C API直接映射到python。 一旦您讓我們知道什么是行不通的,就可以給出更精確的答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.