using gstreamer within kivy

1,087 views
Skip to first unread message

web...@gmx.net

unread,
Feb 1, 2016, 3:53:28 PM2/1/16
to Kivy users support
Hello everybody,

do I have the full gstreamer framework available (similar to having the python bindings for gstreamer installed) when I have installed the dependency for gstreamer?
I would like to use the normal gstreamer framwork methods instead of using kivys.

If so, how to do it (import?)?

If not, how can I include "the complete framework" within gstreamer?

Oliver

web...@gmx.net

unread,
Feb 4, 2016, 1:10:14 PM2/4/16
to Kivy users support
Hello everybody,

is my question too stupid or too difficult?
Presse give me at least a hint!

Thanks a lot to all!

Oliver

web...@gmx.net

unread,
Feb 11, 2016, 12:52:42 PM2/11/16
to Kivy users support
I have now made a simple example with kivy and gstreamer. But I imported gstreamer as I would do in a normal python program.
Can I made a portable distribution from that, so that it is usable e.g. from Android?

Python Code:
import kivy
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from kivy.properties import StringProperty

import gi
gi
.require_version('Gst', '1.0')
from gi.repository import Gst

#set up debug level for gstreamer
import os
os
.environ["GST_DEBUG"] = "*:0"


# root widget
class MyRootWidget(BoxLayout):

   
def __init__(self, mainApp,**kwargs):
       
super(MyRootWidget, self).__init__(**kwargs)
       
self.mainApp = mainApp

   
#property for the label --> changing it's value will change the text of the label
    fileTxt
= StringProperty('Test started, press button...')

   
#callback for play button
   
def playIt(self):
       
self.fileTxt = os.path.abspath(self.mainApp.filename) + ' started!'
       
self.mainApp.startPlaying()

   
#callback for stop button
   
def stopIt(self):
       
self.fileTxt = os.path.abspath(self.mainApp.filename) + ' stopped!'
       
self.mainApp.stopPlaying()


# main application class, kv file with same name (first letter lower case) will be loaded automatically
class KivyGst(App):

    filename
= "test.mp3"

   
def build(self):
       
self.rootWidget = MyRootWidget(self)

       
self.initGst()
       
return self.rootWidget


   
def on_stop(self):
       
self.pipeline.set_state(Gst.State.NULL)


   
def initGst(self):

       
Gst.init(None)

       
#set up pipeline
       
self.pipeline = Gst.Pipeline("mypipeline")

       
#get the source and add it to the pipeline
       
self.file = Gst.ElementFactory.make("filesrc", "file")
       
self.file.set_property("location", self.filename)
       
self.pipeline.add(self.file)

       
#set up the decoder, the source pad will be generated dynamically, thus we need a callback to link it with the converter
       
self.decode = Gst.ElementFactory.make("decodebin", "decode")
       
self.decode.connect("pad-added", self.decode_src_created)
       
self.pipeline.add(self.decode)

       
#set up the converter
       
self.convert = Gst.ElementFactory.make("audioconvert", "convert")
       
self.pipeline.add(self.convert)

       
#set up the output
       
self.sink = Gst.ElementFactory.make("autoaudiosink", "sink")
       
self.pipeline.add(self.sink)

       
#link the things together
       
self.file.link(self.decode)
       
self.convert.link(self.sink)

   
#start playing
   
def startPlaying(self):
       
self.pipeline.set_state(Gst.State.PLAYING)

   
#stop playing
   
def stopPlaying(self):
       
self.pipeline.set_state(Gst.State.NULL)


   
#handler taking care of linking the decoder's newly created source pad to the sink
   
def decode_src_created(self, element, pad):
       
print "decode pad created"
        pad
.link(self.convert.get_static_pad("sink"))


if __name__ == '__main__':
   
KivyGst().run()


kv-File:

<MyRootWidget>:
    orientation: 'vertical'

    Label:
        text: root.fileTxt

    Button:
        text: 'Play'
        on_press: root.playIt()

    Button:
        text: 'Stop'
        on_press: root.stopIt()





Reply all
Reply to author
Forward
0 new messages