2010-06-07 15 views
10

मैं पाइथन के साथ एक जीस्ट्रीमर एप्लिकेशन तारित कर रहा हूं।पायथन के जीएसटी के जीस्ट्रीमर। लिंक्स त्रुटि समस्या

import pygst 
pygst.require('0.10') 
import gst 

import pygtk 
pygtk.require('2.0') 
import gtk 

# this is very important, without this, callbacks from gstreamer thread 
# will messed our program up 
gtk.gdk.threads_init() 

def main(): 
    pipeline = gst.Pipeline('pipleline') 

    filesrc = gst.element_factory_make("filesrc", "filesrc") 
    filesrc.set_property('location', 'C:/a.mp3') 

    decode = gst.element_factory_make("decodebin", "decode") 

    convert = gst.element_factory_make('audioconvert', 'convert') 

    sink = gst.element_factory_make("autoaudiosink", "sink") 

    pipeline.add(filesrc, decode, convert, sink) 
    gst.element_link_many(filesrc, decode, convert, sink) 

    pipeline.set_state(gst.STATE_PLAYING) 

    gtk.main() 

main() 

और त्रुटि:: और मैं निम्नलिखित कोड के साथ एक LinkError मिल

ImportError: could not import gio 
Traceback (most recent call last): 
    File "H:\workspace\ggg\src\test2.py", line 37, in <module> 
    main() 
    File "H:\workspace\ggg\src\test2.py", line 31, in main 
    gst.element_link_many(filesrc, decode, convert, sink) 
gst.LinkError: failed to link decode with convert 

यह बहुत अजीब बात है, एक ही पाइप लाइन के साथ है, लेकिन parse_launch के साथ बनाया गया है, यह काम करता है। क्यों मैनुअल एक में विफल रहा है

import pygst 
pygst.require('0.10') 
import gst 

import pygtk 
pygtk.require('2.0') 
import gtk 

# this is very important, without this, callbacks from gstreamer thread 
# will messed our program up 
gtk.gdk.threads_init() 

def main(): 
    player = gst.parse_launch('filesrc location=C:/a.mp3 ! decodebin ! audioconvert ! autoaudiosink') 
    player.set_state(gst.STATE_PLAYING) 
    gtk.main() 

main() 

यहाँ, सवाल आता है, लेकिन पार्स एक सफलता: यहाँ कोड है? इसमें गलत क्या है? मेरे द्वारा यह कैसे किया जा सकता है?

धन्यवाद।

+0

, मुझे आपके द्वारा सूचीबद्ध पहली त्रुटि नहीं मिली है: "आयात त्रुटि: जीओ आयात नहीं कर सका"। मैं उन्हें बाकी प्राप्त करता हूं, हालांकि, नीचे –

उत्तर

20

आपकी समस्या यहाँ है:

gst.element_link_many(filesrc, decode, convert, sink) 

कारण यह है कि नहीं सभी तत्वों को सरल, स्थिर इनपुट और आउटपुट है। आपके कार्यक्रम में इस बिंदु पर, आपके डिकोडबिन में कोई स्रोत पैड नहीं है (वह है: कोई आउटपुट नहीं)।

एक पैड निप्पल की तरह है - यह एक तत्व के लिए एक इनपुट/आउटपुट है। पैड प्रकट हो सकते हैं, गायब हो सकते हैं या बस वहां बैठ सकते हैं। पैड के तीन श्रेणियां हैं: स्थिर पैड (सबसे आसान और आप उम्मीद करेंगे क्या), अनुरोध पैड (है कि केवल दिखाई देते हैं जब आप उनके लिए पूछना) और कभी कभी पैड (केवल तभी दिखाई दें जब तत्व बनाना चाहता है वे प्रकट होते हैं)। decodebin के आउटपुट कभी-कभी पैड होते हैं।

अगर आप gst-inspect decodebin के उत्पादन का निरीक्षण किया, तो आप खुद के लिए यह देख सकते हैं:

Pad Templates: 
    SINK template: 'sink' 
    Availability: Always 
    Capabilities: 
     ANY 

    SRC template: 'src%d' 
    Availability: Sometimes 
    Capabilities: 
     ANY 

अपने कार्यक्रम की लाइन 26 पर, आप कुछ भी करने के लिए डिकोड लिंक नहीं कर सकते, क्योंकि यह किसी भी स्रोत नहीं है साथ जोड़ने के लिए पैड। एक डिकोडबिन पर स्रोत पैड केवल तभी दिखाई देता है जब इनपुट स्ट्रीम डीकोड किया जाता है: यह तत्काल नहीं होता है। स्रोत पैड की कोई भी संख्या दिखाई दे सकती है (उदाहरण के लिए ऑडियो स्ट्रीम के लिए, दो ऑडियो के साथ वीडियो स्ट्रीम के लिए, कोई भी एक डीकोडेबल स्ट्रीम के लिए नहीं)।

आपको पैड बनाए जाने तक प्रतीक्षा करने की आवश्यकता है, और फिर उन्हें लिंक करें। यह घटित होने पर आपको यह बताने के लिए डिकोडबिन एक सिग्नल उत्सर्जित करता है, "नया-डीकोडेड-पैड" (यह gst-inspect decodebin में भी प्रलेखित है)। आपको कॉलबैक फ़ंक्शन को इस सिग्नल से कनेक्ट करना होगा, और कॉलबैक में अपने डिकोड और ऑडियोऑनवर्ट को लिंक करना होगा।

#!/usr/bin/python 

import pygst 
pygst.require('0.10') 
import gst 

import pygtk 
pygtk.require('2.0') 
import gtk 

# this is very important, without this, callbacks from gstreamer thread 
# will messed our program up 
gtk.gdk.threads_init() 

def on_new_decoded_pad(dbin, pad, islast): 
    decode = pad.get_parent() 
    pipeline = decode.get_parent() 
    convert = pipeline.get_by_name('convert') 
    decode.link(convert) 
    pipeline.set_state(gst.STATE_PLAYING) 
    print "linked!" 

def main(): 
    pipeline = gst.Pipeline('pipleline') 

    filesrc = gst.element_factory_make("filesrc", "filesrc") 
    filesrc.set_property('location', 'C:/a.mp3') 

    decode = gst.element_factory_make("decodebin", "decode") 

    convert = gst.element_factory_make('audioconvert', 'convert') 

    sink = gst.element_factory_make("autoaudiosink", "sink") 

    pipeline.add(filesrc, decode, convert, sink) 
    gst.element_link_many(filesrc, decode) 
    gst.element_link_many(convert, sink) 

    decode.connect("new-decoded-pad", on_new_decoded_pad) 

    pipeline.set_state(gst.STATE_PAUSED) 

    gtk.main() 

main() 

gst.parse_launch काम करता है, क्योंकि यह आप के लिए इन सभी निगली विवरण का ख्याल रखता है: यहाँ अपने को सही कोड है। उच्च स्तरीय तत्व playbin भी है जो स्वचालित रूप से एक डीकोडबिन बनाता है और लिंक करता है। रिकॉर्ड के लिए

+0

[डीकोडबिन] देखें (http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-components-decodebin.html) भी समझाया गया है जीस्ट्रीमर एप्लीकेशन डेवलपमेंट मैनुअल में। – Dejan

संबंधित मुद्दे