Python gi.repository.Gst.caps_from_string() Examples

The following are 5 code examples of gi.repository.Gst.caps_from_string(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gst , or try the search function .
Example #1
Source File: video_gi.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def _gst_init(self):
        # self._appsink will receive the buffers so we can upload them to GPU
        self._appsink = Gst.ElementFactory.make('appsink', '')
        self._appsink.props.caps = Gst.caps_from_string(
            'video/x-raw,format=RGB')

        self._appsink.props.async = True
        self._appsink.props.drop = True
        self._appsink.props.qos = True
        self._appsink.props.emit_signals = True
        self._appsink.connect('new-sample', partial(
            _gst_new_buffer, ref(self)))

        # playbin, takes care of all, loading, playing, etc.
        self._playbin = Gst.ElementFactory.make('playbin', 'playbin')
        self._playbin.props.video_sink = self._appsink

        # gstreamer bus, to attach and listen to gst messages
        self._bus = self._playbin.get_bus()
        self._bus.add_signal_watch()
        self._bus.connect('message', _on_gst_message)
        self._bus.connect('message::eos', partial(
            _on_gst_eos, ref(self))) 
Example #2
Source File: video_gi.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def _gst_init(self):
        # self._appsink will receive the buffers so we can upload them to GPU
        self._appsink = Gst.ElementFactory.make('appsink', '')
        self._appsink.props.caps = Gst.caps_from_string(
            'video/x-raw,format=RGB')

        self._appsink.props.async = True
        self._appsink.props.drop = True
        self._appsink.props.qos = True
        self._appsink.props.emit_signals = True
        self._appsink.connect('new-sample', partial(
            _gst_new_buffer, ref(self)))

        # playbin, takes care of all, loading, playing, etc.
        self._playbin = Gst.ElementFactory.make('playbin', 'playbin')
        self._playbin.props.video_sink = self._appsink

        # gstreamer bus, to attach and listen to gst messages
        self._bus = self._playbin.get_bus()
        self._bus.add_signal_watch()
        self._bus.connect('message', _on_gst_message)
        self._bus.connect('message::eos', partial(
            _on_gst_eos, ref(self))) 
Example #3
Source File: video.py    From visual_dynamics with MIT License 5 votes vote down vote up
def _create_main_pipeline(self, device, size, fps, sync):
        self.pipeline = Gst.Pipeline()

        self.source = Gst.ElementFactory.make('v4l2src', 'source')
        self.source.set_property('device', device)
        self.source.set_property('do-timestamp', 'true')
        # run 'v4l2-ctl --list-ctrls' for full list of controls
        struct, _ = Gst.structure_from_string('name,\
                                               white_balance_temperature_auto=(bool){0},\
                                               backlight_compensation=(int){0},\
                                               exposure_auto=0,\
                                               focus_auto=(bool){0}')
        self.source.set_property('extra-controls', struct)

        caps = Gst.caps_from_string('video/x-raw,format=(string){BGR},width=%d,height=%d,framerate=%d/1'%(size[1], size[0], fps))
        self.sink = Gst.ElementFactory.make('appsink', 'sink')
        self.sink.set_property('emit-signals', True)
        self.sink.set_property('sync', sync)
        self.sink.set_property('drop', True)
        self.sink.set_property('max-buffers', 1)
        self.sink.set_property('caps', caps)
        self.sink.emit('pull-preroll')

        self.pipeline.add(self.source)
        self.pipeline.add(self.sink)

        Gst.Element.link(self.source, self.sink) 
Example #4
Source File: decoder2.py    From kaldi-gstreamer-server with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def init_request(self, id, caps_str):
        self.request_id = id
        logger.info("%s: Initializing request" % (self.request_id))
        if caps_str and len(caps_str) > 0:
            logger.info("%s: Setting caps to %s" % (self.request_id, caps_str))
            caps = Gst.caps_from_string(caps_str)
            self.appsrc.set_property("caps", caps)
        else:
            #caps = Gst.caps_from_string("")
            self.appsrc.set_property("caps", None)
            #self.pipeline.set_state(Gst.State.READY)
            pass
        #self.appsrc.set_state(Gst.State.PAUSED)

        if self.outdir:
            self.pipeline.set_state(Gst.State.PAUSED)
            self.filesink.set_state(Gst.State.NULL)
            self.filesink.set_property('location', "%s/%s.raw" % (self.outdir, id))
            self.filesink.set_state(Gst.State.PLAYING)

        #self.filesink.set_state(Gst.State.PLAYING)        
        #self.decodebin.set_state(Gst.State.PLAYING)
        self.pipeline.set_state(Gst.State.PLAYING)
        self.filesink.set_state(Gst.State.PLAYING)
        # push empty buffer (to avoid hang on client diconnect)
        #buf = Gst.Buffer.new_allocate(None, 0, None)
        #self.appsrc.emit("push-buffer", buf)

        # reset adaptation state
        self.set_adaptation_state("") 
Example #5
Source File: decoder.py    From kaldi-gstreamer-server with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def init_request(self, id, caps_str):
        self.request_id = id
        if caps_str and len(caps_str) > 0:
            logger.info("%s: Setting caps to %s" % (self.request_id, caps_str))
            caps = Gst.caps_from_string(caps_str)
            self.appsrc.set_property("caps", caps)
        else:
            #caps = Gst.caps_from_string(None)
            self.appsrc.set_property("caps", None)
            #self.pipeline.set_state(Gst.State.READY)
            pass
        #self.appsrc.set_state(Gst.State.PAUSED)

        if self.outdir:
            self.pipeline.set_state(Gst.State.PAUSED)
            self.filesink.set_state(Gst.State.NULL)
            self.filesink.set_property('location', "%s/%s.raw" % (self.outdir, id))
            self.filesink.set_state(Gst.State.PLAYING)

        #self.filesink.set_state(Gst.State.PLAYING)
        #self.decodebin.set_state(Gst.State.PLAYING)
        self.pipeline.set_state(Gst.State.PLAYING)
        self.filesink.set_state(Gst.State.PLAYING)
        # push empty buffer (to avoid hang on client diconnect)
        buf = Gst.Buffer.new_allocate(None, 0, None)
        self.appsrc.emit("push-buffer", buf)
        logger.info('%s: Pipeline initialized' % (self.request_id))