ADomi
May 19, 2017, 11:42am
1
Hello, I’m trying to run a simple python script with a gstreamer query on it.
#!/usr/bin/env python3
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
from gi.repository import GLib
GObject.threads_init()
Gst.init(None)
class Sender:
def __init__(self):
# Create GStreamer pipeline
self.pipeline = Gst.Pipeline()
# Create bus to get events from GStreamer pipeline
self.bus = self.pipeline.get_bus()
self.bus.add_signal_watch()
self.bus.connect('message::error', self.on_error)
# Create GStreamer elements
# Video source device
self.src = Gst.ElementFactory.make('nvcamerasrc', None)
# conversion pipeline
self.srccaps = Gst.Caps.from_string("video/x-raw, format=(string)I420")
self.nvoverlaysink = Gst.ElementFactory.make('nvoverlaysink', None)
# Add elements to the pipeline
self.pipeline.add(self.src)
self.pipeline.add(self.nvoverlaysink)
self.src.link_filtered(self.nvoverlaysink, self.srccaps)
# run the program
def run(self):
self.pipeline.set_state(Gst.State.PLAYING)
GLib.MainLoop().run()
def on_error(self, bus, msg):
print('on_error():', msg.parse_error())
## START EVERYTHING
if __name__ == '__main__':
sender = Sender()
sender.run()
which is equivalent to :
gst-launch-1.0 nvcamerasrc ! 'video/x-raw(memory:NVMM), format=(string)I420' ! nvoverlaysink
When I try to run the command in terminal it works without problems.
But when i try to run it through the python script it gives this error:
on_error(): (gerror=GLib.Error('Internal data flow error.', 'gst-stream-error-quark', 1), debug='gstbasesrc.c(2948): gst_base_src_loop (): /GstPipeline:pipeline0/GstNvCameraSrc:nvcamerasrc0:\nstreaming task paused, reason not-linked (-1)')
And cannot understand why.
Can someone help me on this topic?
I also must add that when I change the
nvcamerasrc
to
videotestsrc
it works without problem.
Thank you in advance for your help!
You could try changing:
self.srccaps = Gst.Caps.from_string("video/x-raw, format=(string)I420")
to
self.srccaps = Gst.Caps.from_string("video/x-raw(memory:NVMM), format=(string)I420")
.
Hey bud, I changed the code to as proposed above by Honey, and it works.
#!/usr/bin/env python3
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst, GLib
GObject.threads_init()
Gst.init(None)
class Sender:
def __init__(self):
# Create GStreamer pipeline
self.pipeline = Gst.Pipeline()
# Create bus to get events from GStreamer pipeline
self.bus = self.pipeline.get_bus()
self.bus.add_signal_watch()
self.bus.connect('message::error', self.on_error)
# Create GStreamer elements
# Video source device
self.src = Gst.ElementFactory.make('nvcamerasrc', None)
# conversion pipeline
self.srccaps = Gst.Caps.from_string("video/x-raw(memory:NVMM), format=(string)I420")
self.nvoverlaysink = Gst.ElementFactory.make('nvoverlaysink', None)
# Add elements to the pipeline
self.pipeline.add(self.src)
self.pipeline.add(self.nvoverlaysink)
self.src.link_filtered(self.nvoverlaysink, self.srccaps)
# run the program
def run(self):
self.pipeline.set_state(Gst.State.PLAYING)
GLib.MainLoop().run()
def on_error(self, bus, msg):
print('on_error():', msg.parse_error())
## START EVERYTHING
if __name__ == '__main__':
sender = Sender()
sender.run()
To be honest, Its actually quiet annoying with those () in the stream parameters with python, as you need to add ‘’ when launching the same command in gst-launcher.
What Im most annoyed is that the nvcamera-daemon dont stop when the gst-launcher process stops. I have to kill the process all the time.
also when my python script crashes, the nvcamera-daemon still runs, and has to be killed like this;
sudo killall nvcamera-daemon
sudo service nvcamera-daemon stop
sudo /usr/sbin/nvcamera-daemon &
I made a bash script and can call it from my udp control application to restart the camera daemon.
But it should be completely unnecessary.
NVIDIA… please read this
ADomi
May 22, 2017, 8:15pm
5
You could try changing:
self.srccaps = Gst.Caps.from_string("video/x-raw, format=(string)I420")
to
self.srccaps = Gst.Caps.from_string("video/x-raw(memory:NVMM), format=(string)I420")
.
Thank you! That actually solved it :)