recording three streams from usb cameras with python wrapper
Andre1984
andrevolodin at gmail.com
Wed May 22 03:40:59 UTC 2019
Hi, guys,
Could you sort out a way to record with python usb camera streams
concurrently?
#!/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
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)
self.movie_window = Gtk.DrawingArea()
vbox.add(self.movie_window)
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
self.player = Gst.parse_launch ("v4l2src device=/dev/video1
num-buffers=300 ! video/x-h264,width=1920,height=1080,framerate=25/1 !
h264parse ! qtmux ! filesink location=camera1.mov v4l2src device=/dev/video3
num-buffers=300 ! video/x-h264,width=1920,height=1080,framerate=25/1 !
h264parse ! qtmux ! filesink location=camera3.mov v4l2src device=/dev/video5
num-buffers=300 ! video/x-h264,width=1920,height=1080,framerate=25/1 !
h264parse ! qtmux ! filesink location=camera5.mov")
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect("message", self.on_message)
bus.connect("sync-message::element", self.on_sync_message)
def start_stop(self, w):
if self.button.get_label() == "Start":
self.button.set_label("Stop")
self.player.set_state(Gst.State.PLAYING)
else:
self.player.send_event(Gst.Event.new_eos())
self.player.set_state(Gst.State.NULL)
self.button.set_label("Start")
def exit(self, widget, data=None):
Gtk.main_quit()
def on_message(self, bus, message):
t = message.type
if t == Gst.MessageType.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")
def on_sync_message(self, bus, message):
struct = message.get_structure()
if not struct:
return
message_name = struct.get_name()
if message_name == "prepare-xwindow-id":
# Assign the viewport
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
imagesink.set_xwindow_id(self.movie_window.window.xid)
Gst.init(None)
GTK_Main()
GObject.threads_init()
Gtk.main()
The error I am getting is:
python 3cam.py
Error: gst-resource-error-quark: Failed to allocate required memory. (13)
gstv4l2src.c(650): gst_v4l2src_decide_allocation ():
/GstPipeline:pipeline0/GstV4l2Src:v4l2src1:
Buffer pool activation failed
https://devtalk.nvidia.com/default/topic/1052226/jetson-agx-xavier/recording-concurrently-multiple-streams-from-usb-cameras-to-files-with-python/post/5341310/#5341310
<https://devtalk.nvidia.com/default/topic/1052226/jetson-agx-xavier/recording-concurrently-multiple-streams-from-usb-cameras-to-files-with-python/post/5341310/#5341310>
--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
More information about the gstreamer-devel
mailing list