本文整理汇总了Python中gi.repository.Gst.parse_launch方法的典型用法代码示例。如果您正苦于以下问题:Python Gst.parse_launch方法的具体用法?Python Gst.parse_launch怎么用?Python Gst.parse_launch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gst
的用法示例。
在下文中一共展示了Gst.parse_launch方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def __init__(self, pipeline, inf_callback, render_callback, src_size):
self.inf_callback = inf_callback
self.render_callback = render_callback
self.running = False
self.gstbuffer = None
self.output = None
self.sink_size = None
self.src_size = src_size
self.box = None
self.condition = threading.Condition()
self.pipeline = Gst.parse_launch(pipeline)
self.freezer = self.pipeline.get_by_name('freezer')
self.overlay = self.pipeline.get_by_name('overlay')
self.overlaysink = self.pipeline.get_by_name('overlaysink')
appsink = self.pipeline.get_by_name('appsink')
appsink.connect('new-sample', self.on_new_sample)
# Set up a pipeline bus watch to catch errors.
bus = self.pipeline.get_bus()
bus.add_signal_watch()
bus.connect('message', self.on_bus_message)
# Set up a full screen window on Coral, no-op otherwise.
self.setup_window()
示例2: get_player
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def get_player(self):
player = Gst.parse_launch('uridecodebin name=urisrc !\
audioconvert ! audioresample ! queue ! removesilence name=removesilence !\
audioconvert ! audioresample ! queue ! scaletempo !\
audioconvert ! audioresample ! volume name=volume !\
audioamplify name=amplification !\
equalizer-nbands name=equalizer num-bands=18 !\
autoaudiosink')
bus = player.get_bus()
bus.add_signal_watch()
bus.connect("message::eos", self.on_eos)
bus.connect('message::state-changed', self.on_state_changed)
bus.connect('message', self.on_player_message)
bus.connect("message::error", self.test)
bus.connect("message::application", self.test)
bus.connect('sync-message', self.test)
return player
示例3: gCamera
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def gCamera():
print "gstWebCam"
bridge = CvBridge()
video ="video4"
pub = rospy.Publisher('stream', Image, queue_size=10)
rospy.init_node('GstWebCam',anonymous=True)
Gst.init(None)
pipe = Gst.parse_launch("""v4l2src device=/dev/"""+video+""" ! video/x-raw, width=640, height=480,format=(string)BGR ! appsink sync=false max-buffers=2 drop=true name=sink emit-signals=true""")
sink = pipe.get_by_name('sink')
pipe.set_state(Gst.State.PLAYING)
while not rospy.is_shutdown():
sample = sink.emit('pull-sample')
img = gst_to_opencv(sample.get_buffer())
try:
pub.publish(bridge.cv2_to_imgmsg(img, "bgr8"))
except CvBridgeError as e:
print(e)
示例4: _launch_pipeline
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def _launch_pipeline(self):
self.pipeline = Gst.parse_launch("uridecodebin name=decode uri=" +
self._uri + " ! waveformbin name=wave"
" ! fakesink qos=false name=faked")
Gst.ElementFactory.make("uritranscodebin", None)
clock = GObject.new(GObject.type_from_name("GstCpuThrottlingClock"))
clock.props.cpu_usage = 90
self.pipeline.use_clock(clock)
faked = self.pipeline.get_by_name("faked")
faked.props.sync = True
self._wavebin = self.pipeline.get_by_name("wave")
self._wavebin.props.uri = self._asset.get_id()
self._wavebin.props.duration = self._asset.get_duration()
decode = self.pipeline.get_by_name("decode")
decode.connect("autoplug-select", self._autoplug_select_cb)
bus = self.pipeline.get_bus()
self.pipeline.set_state(Gst.State.PLAYING)
bus.add_signal_watch()
self.n_samples = self._asset.get_duration() / SAMPLE_DURATION
bus.connect("message::error", self.__on_bus_error)
bus.connect("message::eos", self.__on_bus_eos)
示例5: gain
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def gain(self):
pipe = 'uridecodebin uri="{0}" ! audioconvert ! rganalysis \
reference-level={1} ! fakesink'.format(self.uri, self.ref_level)
self.gain_pipe = Gst.parse_launch(pipe)
gain_bus = self.gain_pipe.get_bus()
gain_bus.add_signal_watch()
gain_bus.connect('message', self._on_message)
logging.info('REPLY-GAIN:: started ' + str(self.uri))
self.gain_pipe.set_state(Gst.State.PLAYING)
# Block here until EOS
self.__lock.acquire(False)
self.__lock.acquire()
# Reset the pipe
self.gain_pipe = None
# Return the computation result
return self.result
示例6: __init__
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def __init__(self, pipeline, user_function, src_size):
self.user_function = user_function
self.running = False
self.gstbuffer = None
self.sink_size = None
self.src_size = src_size
self.box = None
self.condition = threading.Condition()
self.pipeline = Gst.parse_launch(pipeline)
self.overlay = self.pipeline.get_by_name('overlay')
self.overlaysink = self.pipeline.get_by_name('overlaysink')
appsink = self.pipeline.get_by_name('appsink')
appsink.connect('new-sample', self.on_new_sample)
# Set up a pipeline bus watch to catch errors.
bus = self.pipeline.get_bus()
bus.add_signal_watch()
bus.connect('message', self.on_bus_message)
# Set up a full screen window on Coral, no-op otherwise.
self.setup_window()
示例7: create_pipeline_from_string
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def create_pipeline_from_string(self, pipeline_string):
try:
self.logger.debug('Creating with pipeline: ' + pipeline_string)
self.pipeline = Gst.parse_launch(pipeline_string)
setup_messaging(pipe=self.pipeline, parent_object=self)
except GLib.GError as e:
self.error_message = str(e)
self.logger.error('Failed to create pipeline [%s]: %s' % (pipeline_string, self.error_message))
raise brave.exceptions.PipelineFailure(self.error_message)
示例8: validate_config
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def validate_config(config):
template = config["template"]
pipeline = Gst.parse_launch(template)
appsink = pipeline.get_by_name("appsink")
metaconvert = pipeline.get_by_name("metaconvert")
metapublish = pipeline.get_by_name("destination")
if appsink is None:
logger.warning("Missing appsink element")
if metaconvert is None:
logger.warning("Missing metaconvert element")
if metapublish is None:
logger.warning("Missing metapublish element")
示例9: get_player
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def get_player(self):
player = Gst.parse_launch('uridecodebin name=urisrc !\
audioconvert ! audioresample ! queue ! removesilence name=removesilence !\
audioconvert ! audioresample ! queue ! scaletempo !\
audioconvert ! audioresample ! volume name=volume !\
equalizer-10bands name=equalizer ! autoaudiosink')
bus = player.get_bus()
bus.add_signal_watch()
bus.connect('message::state-changed', self.on_state_changed)
bus.connect('message', self.on_player_message)
return player
示例10: init_camera
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def init_camera(self):
# TODO: This doesn't work when camera resolution is resized at runtime.
# There must be some other way to release the camera?
if self._pipeline:
self._pipeline = None
video_src = self._video_src
if video_src == 'v4l2src':
video_src += ' device=/dev/video%d' % self._index
elif video_src == 'dc1394src':
video_src += ' camera-number=%d' % self._index
if Gst.version() < (1, 0, 0, 0):
caps = ('video/x-raw-rgb,red_mask=(int)0xff0000,'
'green_mask=(int)0x00ff00,blue_mask=(int)0x0000ff')
pl = ('{} ! decodebin name=decoder ! ffmpegcolorspace ! '
'appsink name=camerasink emit-signals=True caps={}')
else:
caps = 'video/x-raw,format=RGB'
pl = '{} ! decodebin name=decoder ! videoconvert ! appsink ' + \
'name=camerasink emit-signals=True caps={}'
self._pipeline = Gst.parse_launch(pl.format(video_src, caps))
self._camerasink = self._pipeline.get_by_name('camerasink')
self._camerasink.connect('new-sample', self._gst_new_sample)
self._decodebin = self._pipeline.get_by_name('decoder')
if self._camerasink and not self.stopped:
self.start()
示例11: __init__
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def __init__(self, tsm_description="audiotsm-wsola"):
super().__init__()
self._speed = 0
# Create the playbin, that will handle the decoding of the audio files
self.playbin = Gst.ElementFactory.make('playbin', 'playbin')
self.add(self.playbin)
# Create the audiotsm bin, that will handle the TSM
audiotsmbin = Gst.Bin('audiotsm')
# Create the elements of the audiotsm bin, add them, and link them
self.tsm = Gst.parse_launch(tsm_description)
converter = Gst.ElementFactory.make('audioconvert', 'converter')
encoder = Gst.ElementFactory.make('wavenc', 'encoder')
self.sink = Gst.ElementFactory.make('filesink', 'sink')
audiotsmbin.add(self.tsm)
audiotsmbin.add(converter)
audiotsmbin.add(encoder)
audiotsmbin.add(self.sink)
self.tsm.link(converter)
converter.link(encoder)
encoder.link(self.sink)
# Add the sink pad of the TSM plugin to the audiotsm bin.
self.tsm_sink_pad = Gst.GhostPad.new(
'sink', self.tsm.get_static_pad('sink'))
audiotsmbin.add_pad(self.tsm_sink_pad)
# And link it to the playbin
self.playbin.set_property("audio-sink", audiotsmbin)
bus = self.get_bus()
bus.add_signal_watch()
bus.connect("message::error", self._on_error)
bus.connect("message::eos", self._on_eos)
示例12: __init__
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def __init__(self, tsm_description="audiotsm-phase-vocoder"):
super().__init__()
self._speed = 1.0
self._speed_set = False
# Create the playbin, that will handle the decoding of the audio files
self.playbin = Gst.ElementFactory.make('playbin', 'playbin')
self.add(self.playbin)
# Create the audiotsm bin, that will handle the TSM
audiotsmbin = Gst.Bin('audiotsm')
# Create the elements of the audiotsm bin, add them, and link them
self.tsm = Gst.parse_launch(tsm_description)
converter = Gst.ElementFactory.make('audioconvert', 'converter')
sink = Gst.ElementFactory.make('autoaudiosink', 'sink')
audiotsmbin.add(self.tsm)
audiotsmbin.add(converter)
audiotsmbin.add(sink)
self.tsm.link(converter)
converter.link(sink)
# Add the sink pad of the TSM plugin to the audiotsm bin.
self.tsm_sink_pad = Gst.GhostPad.new(
'sink', self.tsm.get_static_pad('sink'))
audiotsmbin.add_pad(self.tsm_sink_pad)
# And link it to the playbin
self.playbin.set_property("audio-sink", audiotsmbin)
bus = self.get_bus()
bus.add_signal_watch()
bus.connect("message::error", self._on_error)
bus.connect("message::eos", self._on_eos)
bus.connect("message::state-changed", self._on_state_changed)
# The timer that will emit the position-changed signal
self.position_timer = None
示例13: start
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def start(self):
self.request["models"] = self.models
self._gst_launch_string = string.Formatter().vformat(
self.template, [], self.request)
with(self._create_delete_lock):
if (self.start_time is not None):
return
logger.debug("Starting Pipeline {id}".format(id=self.identifier))
logger.debug(self._gst_launch_string)
self.pipeline = Gst.parse_launch(self._gst_launch_string)
self._set_properties()
self._set_default_models()
self._cache_inference_elements()
sink = self.pipeline.get_by_name("appsink")
if sink is not None:
sink.set_property("emit-signals", True)
sink.set_property('sync', False)
sink.connect("new-sample", GStreamerPipeline.on_sample, self)
self.avg_fps = 0
src = self.pipeline.get_by_name("source")
if src and sink:
src_pad = src.get_static_pad("src")
if (src_pad):
src_pad.add_probe(Gst.PadProbeType.BUFFER,
GStreamerPipeline.source_probe_callback, self)
else:
src.connect(
"pad-added", GStreamerPipeline.source_pad_added_callback, self)
sink_pad = sink.get_static_pad("sink")
sink_pad.add_probe(Gst.PadProbeType.BUFFER,
GStreamerPipeline.appsink_probe_callback, self)
bus = self.pipeline.get_bus()
bus.add_signal_watch()
self._bus_connection_id = bus.connect("message", self.bus_call)
splitmuxsink = self.pipeline.get_by_name("splitmuxsink")
self._real_base = None
if (not splitmuxsink is None):
splitmuxsink.connect("format-location-full",
self.format_location_callback,
None)
self.pipeline.set_state(Gst.State.PLAYING)
self.start_time = time.time()
示例14: run_pipeline
# 需要导入模块: from gi.repository import Gst [as 别名]
# 或者: from gi.repository.Gst import parse_launch [as 别名]
def run_pipeline(user_function,
src_size=(640,480),
appsink_size=(320, 180)):
PIPELINE = 'v4l2src device=/dev/video0 ! {src_caps} ! {leaky_q} '
if detectCoralDevBoard():
SRC_CAPS = 'video/x-raw,format=YUY2,width={width},height={height},framerate=30/1'
PIPELINE += """ ! glupload ! tee name=t
t. ! {leaky_q} ! glfilterbin filter=glcolorscale
! {dl_caps} ! videoconvert ! {sink_caps} ! {sink_element}
t. ! {leaky_q} ! glfilterbin filter=glcolorscale
! rsvgoverlay name=overlay ! waylandsink
"""
else:
SRC_CAPS = 'video/x-raw,width={width},height={height},framerate=30/1'
PIPELINE += """ ! tee name=t
t. ! {leaky_q} ! videoconvert ! videoscale ! {sink_caps} ! {sink_element}
t. ! {leaky_q} ! videoconvert
! rsvgoverlay name=overlay ! videoconvert ! autovideosink
"""
SINK_ELEMENT = 'appsink name=appsink sync=false emit-signals=true max-buffers=1 drop=true'
DL_CAPS = 'video/x-raw,format=RGBA,width={width},height={height}'
SINK_CAPS = 'video/x-raw,format=RGB,width={width},height={height}'
LEAKY_Q = 'queue max-size-buffers=1 leaky=downstream'
src_caps = SRC_CAPS.format(width=src_size[0], height=src_size[1])
dl_caps = DL_CAPS.format(width=appsink_size[0], height=appsink_size[1])
sink_caps = SINK_CAPS.format(width=appsink_size[0], height=appsink_size[1])
pipeline = PIPELINE.format(leaky_q=LEAKY_Q,
src_caps=src_caps, dl_caps=dl_caps, sink_caps=sink_caps,
sink_element=SINK_ELEMENT)
print('Gstreamer pipeline: ', pipeline)
pipeline = Gst.parse_launch(pipeline)
overlay = pipeline.get_by_name('overlay')
appsink = pipeline.get_by_name('appsink')
appsink.connect('new-sample', partial(on_new_sample,
overlay=overlay, screen_size = src_size,
appsink_size=appsink_size, user_function=user_function))
loop = GObject.MainLoop()
# Set up a pipeline bus watch to catch errors.
bus = pipeline.get_bus()
bus.add_signal_watch()
bus.connect('message', on_bus_message, loop)
# Run pipeline.
pipeline.set_state(Gst.State.PLAYING)
try:
loop.run()
except:
pass
# Clean up.
pipeline.set_state(Gst.State.NULL)
while GLib.MainContext.default().iteration(False):
pass