As said above, it also works with start/stop:
#!/usr/bin/env python
import sys, os
import gi
gi.require_version('Gst', '1.0')
gi.require_version('Gtk', '3.0')
from gi.repository import Gst, GObject, Gtk
def verbose_deep_notify_cb(object, orig, pspec, component):
"""
A quick attempt to mimic gst-launch verbose mode.
"""
if pspec.value_type == Gst.Caps.__gtype__:
caps = orig.get_current_caps()
if caps != None:
print("%s/%s/%s: caps = \"%s\"" % (object.get_name(), orig.parent.get_name(), orig.get_name(), caps.to_string()))
class GTK_Main:
def __init__(self):
window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
window.set_title("CamRecorder")
window.set_default_size(100, 100)
window.connect("destroy", Gtk.main_quit, "WM destroy")
vbox = Gtk.VBox()
window.add(vbox)
hbox = Gtk.HBox()
vbox.pack_start(hbox, False, False, 0)
hbox.set_border_width(10)
hbox.pack_start(Gtk.Label(), False, False, 0)
self.button = Gtk.Button("Start")
self.button.connect("clicked", self.start_stop)
hbox.pack_start(self.button, False, False, 0)
self.button2 = Gtk.Button("Quit")
self.button2.connect("clicked", self.exit)
hbox.pack_start(self.button2, False, False, 0)
hbox.add(Gtk.Label())
window.show_all()
# Set up the gstreamer pipeline
#gst_str = "nvarguscamerasrc ! video/x-raw(memory:NVMM),format=(string)NV12,width=(int)640,height=(int)480, framerate=30/1 ! nvv4l2h264enc ! nvv4l2decoder enable-max-performance=1 ! nvvidconv ! xvimagesink sync=false"
gst_str = "v4l2src device=/dev/video1 ! video/x-raw,format=YUY2,width=2560,height=720, framerate=30/1 ! nvvidconv ! nvv4l2h264enc ! nvv4l2decoder enable-max-performance=1 ! nvvidconv ! xvimagesink sync=false"
self.player = Gst.parse_launch (gst_str)
self.player.connect('deep-notify', verbose_deep_notify_cb, self)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect("message", self.on_message)
def start_stop(self, w, data=None):
if self.button.get_label() == "Start":
print("Setting pipeline to READY ...")
self.player.set_state(Gst.State.READY)
print("Setting pipeline to PAUSED ...")
self.player.set_state(Gst.State.PAUSED)
print("Setting pipeline PLAYING...")
self.player.set_state(Gst.State.PLAYING)
self.button.set_label("Stop")
else:
print("Setting pipeline to NULL ...")
self.player.set_state(Gst.State.NULL)
self.button.set_label("Start")
def exit(self, w):
self.player.set_state(Gst.State.NULL)
Gtk.main_quit()
def on_message(self, bus, message):
t = message.type
if t == Gst.MessageType.EOS:
print('Received message type EOS')
self.player.set_state(Gst.State.NULL)
self.button.set_label("Start")
elif t == Gst.MessageType.ERROR:
err, debug = message.parse_error()
print "Error: %s" % err, debug
self.player.set_state(Gst.State.NULL)
self.button.set_label("Start")
Gst.debug_set_active(True)
Gst.debug_set_default_threshold(0)
GObject.threads_init()
Gst.init(None)
GTK_Main()
Gtk.main()
[EDIT: Further checked with gstd, I see no problem in my case (using Xavier-NX):
gstd
gst-client pipeline_create test videotestsrc ! nvvidconv ! nvv4l2h264enc ! nvv4l2decoder ! nvvidconv ! xvimagesink sync=false
gst-client pipeline_play test
...
gst-client pipeline_stop test
gst-client pipeline_play test
...
gst-client pipeline_stop test
It works and reports success.]