I am trying to use the camera feed on my Jetson Nano (running headless over SSH) in 2 different applications.
From the command line, I am able to run
gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=3280, height=2464, format=NV12, framerate=(fraction)21/1' ! nvvidconv ! xvimagesink
Which streams video from my camera (IMX219 connected to the Jetson Nano) to my desktop via an X11 Window.
What I would like to do is somehow use that same video stream in 2 different applications. My first application is a python program that runs some OpenCV stuff, the second application is a simple bash script which records video to an *.mp4 file.
Is such a thing possible? I have looked into using v4l2loopback
, but I'm unsure if that is really the simplest way to do this.
Well, I managed to figure it out thanks to both commentors, here is my solution on my Jetson Nano, but it can be tweaked for any Gstreamer application.
First, use v4l2loopback
to create 2 virtual devices like so:
sudo modprobe v4l2loopback video_nr=1,2
That will create /dev/video1
and /dev/video2
Then you use tee
to dump a Gstreamer stream into each of these virtual devices, here is my line:
gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=3280, height=2464, format=NV12, framerate=(fraction)21/1' ! nvvidconv ! tee name=t ! queue ! v4l2sink device=/dev/video1 t. ! queue ! v4l2sink device=/dev/video2
This is specifically for my Jetson Nano and my specific camera, but you can change the gstreamer pipeline to do what you wish