0

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=' \
                     +str(framerate)+'/1'
    self.playing = False
    self.paused = False
    self.make_pipeline()
    self.play_pipeline()

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.filesink.set_property("location","custom.ts")
    self.appsrc = self.pipeline.get_by_name("source")
    self.appsrc.set_property("is-live",True)
    self.gstcaps = Gst.Caps.from_string(self.capstring)
    self.appsrc.set_property("caps",self.gstcaps)

def play_pipeline(self):
    self.pipeline.set_state(Gst.State.PLAYING)

def stop_pipeline(self):
    self.pipeline.set_state(Gst.State.READY)

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

def flush(self):
    self.stop_pipeline()

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')
    pipeline.add(self._bin)
    pipeline.add(gtksink)
    # Link the pipeline to the sink that will display the video.
    self._bin.link(gtksink)
    self.pack_start(gtksink.props.widget, True, True, 0)
    gtksink.props.widget.show()
    # Start the video
    pipeline.set_state(Gst.State.PLAYING)

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.