Well, today I began to program in Python and I'm doing a graphical app with PyGtk in Anjuta. My first objective is to get the stream of the PiCamera in a window. But I'm getting problems to manage the pipelines, this is my code:

class CamStreamer(object):
def __init__(self,videoFormat,resolution,framerate):
    self.size = 0
    self.capstring = 'video/x-'+videoFormat+',width='+str(resolution[0]) \
                     +',height='+str(resolution[1])+',framerate=' \
    self.playing = False
    self.paused = False

def make_pipeline(self):
    CLI = [
              'appsrc name="source" ! ',
              'h264parse ! video/x-h264,stream-format=avc ! ',
              'h264parse ! video/x-h264,stream-format=byte-stream ! ',
              'mpegtsmux ! filesink name="sink"'
    gcmd = "".join(CLI)
    self.pipeline = Gst.parse_launch(gcmd)
    self.filesink = self.pipeline.get_by_name("sink")
    self.appsrc = self.pipeline.get_by_name("source")
    self.gstcaps = Gst.Caps.from_string(self.capstring)

def play_pipeline(self):

def stop_pipeline(self):

def write(self,s):
    gstbuff = Gst.Buffer.new_wrapped(s)
    ret = self.appsrc.emit("push-buffer",gstbuff)

def flush(self):

I found this classes searching here in the forum

class GstWidget(Gtk.Box):
def __init__(self, pipeline):
    super(GstWidget, self).__init__()
    # Only setup the widget after the window is shown.
    self.connect('realize', self._on_realize)

    # Parse a gstreamer pipeline and create it.
    self._bin = Gst.parse_bin_from_description(pipeline, True)

def _on_realize(self, widget):
    pipeline = Gst.Pipeline()
    factory = pipeline.get_factory()
    gtksink = factory.make('gtksink')
    # Link the pipeline to the sink that will display the video.
    self.pack_start(gtksink.props.widget, True, True, 0)
    # Start the video

And then, in the examples they call

    camera = picamera.PiCamera()
    camera.start_recording(self.streamer,format=self.format, bitrate=self.bitrate)
    widget = GstWidget('videotestsrc')

This shows the test video. I don't know what pass to GsWidget to stream the PiCam. Thanks

  • 1
    Please avoid gangnam style English, as in "de pipelines" and "mi code". – Dmitry Grigoryev Jul 10 at 6:53
  • @DmitryGrigoryev well you know, I live in Argentina and obviously the Android language is spanish. Some autocorrections passed my filter and being not critical I really prefer to avoid this types of comments, I need help with the code. Excuse me to harm you eyes with the gambang style English. – David Zamudio Jul 10 at 17:25
  • @DmitryGrigoryev please don't reply any comment, I really want to see a notification looking for help – David Zamudio Jul 10 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.