duplicate webcam stream in a virtual device created with v4l2loopback - gstreamer

hello gods of videos streams
I'm trying to duplicate a webcam stream in order to send it and still be able to use it in a web browser for example
goal is to create a virtual video device with v4l2Loopback use gstreamer to get the source from real web cam make a tee stream it where i need (rtps server) and on the other tee branch use a v4l2sink to forward to the virtual device created with v4l2loopback
I'm testing under ubuntu 20.04 but planning to use it on raspian buster in the end
I've
sudo apt install v4l2loopback-dkms v4l2loopback-utils
and
sudo modprobe v4l2loopback video_nr=100
and it looks ok
$ v4l2-ctl --all -d /dev/video100
Driver Info:
Driver name : v4l2 loopback
Card type : Dummy video device (0x0000)
Bus info : platform:v4l2loopback-000
Driver version : 5.4.65
Capabilities : 0x85208003
Video Capture
Video Output
Video Memory-to-Memory
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x85208000
Video Memory-to-Memory
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Priority: 0
Video input : 0 (loopback: ok)
Video output: 0 (loopback in)
Format Video Output:
Width/Height : 1920/1080
Pixel Format : 'YU12' (Planar YUV 4:2:0)
Field : None
Bytes per Line : 1920
Size Image : 3110400
Colorspace : sRGB
Transfer Function : Default (maps to sRGB)
YCbCr/HSV Encoding: Default (maps to ITU-R 601)
Quantization : Default (maps to Limited Range)
Flags :
Streaming Parameters Video Capture:
Frames per second: 30.000 (30/1)
Read buffers : 8
Streaming Parameters Video Output:
Frames per second: 30.000 (30/1)
Write buffers : 8
User Controls
keep_format 0x0098f900 (bool) : default=0 value=0
sustain_framerate 0x0098f901 (bool) : default=0 value=0
timeout 0x0098f902 (int) : min=0 max=100000 step=1 default=0 value=0
timeout_image_io 0x0098f903 (bool) : default=0 value=0
here
before streaming my real webcam I just try to stream videotestsrc like explained in gstreamer v4l2sink doc
gst-launch-1.0 videotestsrc ! v4l2sink device=/dev/video100
strangely it says it's not an output device (GST-DEBUG=3)
$ gst-launch-1.0 videotestsrc ! v4l2sink device=/dev/video100
Setting pipeline to PAUSED ...
0:00:00.137162087 12355 0x5601d5516010 WARN v4l2 v4l2_calls.c:636:gst_v4l2_open:<v4l2sink0> error: Device '/dev/video100' is not a output device.
0:00:00.137209656 12355 0x5601d5516010 WARN v4l2 v4l2_calls.c:636:gst_v4l2_open:<v4l2sink0> error: Capabilities: 0x85208000
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0: Device '/dev/video100' is not a output device.
Additional debug info:
v4l2_calls.c(636): gst_v4l2_open (): /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0:
Capabilities: 0x85208000
Setting pipeline to NULL ...
Freeing pipeline ...
I' ve look to find other issue like mine but maybe I've not well searched I didnt find any relevant infos
If any one can help I will be so greatfull
thank's so mutch for reading until here and thank's so mutch more for any help info idea etc
edit :
I also tried on raspian buster raspberry pi 4
I got few issue with v4l2loopback at install but I followed that topic https://github.com/RPi-Distro/repo/issues/188 and be able to install it
i've do the same (modprobe and then gstream) and gstreamer v4l2Sink looks to work when using workaround to avoid not negociated-4 error
gst-launch-1.0 videotestsrc ! identity drop-allocation=1 ! v4l2sink device=/dev/video100
it look to work but I got lots of warnings :
$ gst-launch-1.0 -v videotestsrc ! identity drop-allocation=1 ! v4l2sink device=/dev/video100
Définition du pipeline à PAUSED...
Le pipeline est en phase de PREROLL…
0:00:00.128889803 11076 0xe230f0 FIXME default gstutils.c:3981:gst_pad_create_stream_id_internal:<videotestsrc0:src> Creating random stream-id, consider implementing a deterministic way of creating a stream-id
0:00:00.129497619 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at YUYV#48x32: 0
0:00:00.129647893 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at UYVY#48x32: 0
0:00:00.129766111 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at 422P#48x32: 0
0:00:00.129872201 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at YU12#48x32: 0
0:00:00.129975513 11076 0xe230f0 WARN v4l2 gstv4l2o$ gst-launch-1.0 -v videotestsrc ! identity drop-allocation=1 ! v4l2sink device=/dev/video100
Définition du pipeline à PAUSED...
Le pipeline est en phase de PREROLL…
0:00:00.128889803 11076 0xe230f0 FIXME default gstutils.c:3981:gst_pad_create_stream_id_internal:<videotestsrc0:src> Creating random stream-id, consider implementing a deterministic way of creating a stream-id
0:00:00.129497619 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at YUYV#48x32: 0
0:00:00.129647893 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at UYVY#48x32: 0
0:00:00.129766111 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at 422P#48x32: 0
0:00:00.129872201 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at YU12#48x32: 0
0:00:00.129975513 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at YV12#48x32: 0
0:00:00.130079232 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at 411P#48x32: 0
0:00:00.130190210 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at YVU9#48x32: 0
0:00:00.130291689 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at YUV9#48x32: 0
0:00:00.130395612 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at JPEG#48x32: 0
0:00:00.130483220 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at MJPG#48x32: 0
0:00:00.130570810 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at dvsd#48x32: 0
0:00:00.130658326 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at RGB4#48x32: 0
0:00:00.130753046 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at BGR4#48x32: 0
0:00:00.130847173 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at RGB3#48x32: 0
0:00:00.130959966 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at BGR3#48x32: 0
0:00:00.131055000 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at NV12#48x32: 0
0:00:00.131170441 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at RGBQ#48x32: 0
0:00:00.131266012 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at RGBP#48x32: 0
0:00:00.131359676 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at RGBO#48x32: 0
0:00:00.131454285 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at BA81#48x32: 0
0:00:00.131539338 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at GBRG#48x32: 0
0:00:00.131623317 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at GRBG#48x32: 0
0:00:00.131707907 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at RGGB#48x32: 0
0:00:00.131792701 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at GREY#48x32: 0
0:00:00.131889365 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at VP90#48x32: 0
0:00:00.131974881 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at VP80#48x32: 0
0:00:00.132062378 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at VC1L#48x32: 0
0:00:00.132151839 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at VC1G#48x32: 0
0:00:00.132250595 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at XVID#48x32: 0
0:00:00.132340129 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at MPG4#48x32: 0
0:00:00.132427053 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at MPG2#48x32: 0
0:00:00.132513495 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at MPG1#48x32: 0
0:00:00.132601677 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at H263#48x32: 0
0:00:00.132691304 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at AVC1#48x32: 0
0:00:00.132781080 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at H264#48x32: 0
0:00:00.132869910 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at Y16 #48x32: 0
0:00:00.132966408 11076 0xe230f0 WARN v4l2 gstv4l2object.c:2514:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0:sink> Unknown frame interval type at YVYU#48x32: 0
/GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0.GstPad:src: caps = video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1, multiview-mode=(string)mono, interlace-mode=(string)progressive, colorimetry=(string)2:4:7:1, pixel-aspect-ratio=(fraction)1/1
/GstPipeline:pipeline0/GstIdentity:identity0.GstPad:src: caps = video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1, multiview-mode=(string)mono, interlace-mode=(string)progressive, colorimetry=(string)2:4:7:1, pixel-aspect-ratio=(fraction)1/1
/GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0.GstPad:sink: caps = video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1, multiview-mode=(string)mono, interlace-mode=(string)progressive, colorimetry=(string)2:4:7:1, pixel-aspect-ratio=(fraction)1/1
/GstPipeline:pipeline0/GstIdentity:identity0.GstPad:sink: caps = video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1, multiview-mode=(string)mono, interlace-mode=(string)progressive, colorimetry=(string)2:4:7:1, pixel-aspect-ratio=(fraction)1/1
Le pipeline a terminé la phase PREROLL…
Passage du pipeline à la phase PLAYING…
New clock: GstSystemClock
and finaly when trying to get and image from this video device
$ ffmpeg -f video4linux2 -s 640x480 -i /dev/video100 -ss 0:0:2 -frames 1 /tmp/out2.jpg
ffmpeg version 4.1.6-1~deb10u1+rpt1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Raspbian 8.3.0-6+rpi1)
...[truncated because of stack overflow body size limit]...
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler # 0x136f230] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/tmp/out2.jpg':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Video: mjpeg, yuvj422p(pc), 320x240, q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc
Metadata:
encoder : Lavc58.35.100 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
[video4linux2,v4l2 # 0x1363200] Dequeued v4l2 buffer contains 155648 bytes, but 153600 were expected. Flags: 0x00000001.
/dev/video100: Invalid data found when processing input
frame= 0 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)

I just went thru this and will explain the big stumbling block with v4l2 video devices. The basic issue is real devices can only be accessed once, while loopback devices are not limited.
First start up your usb webcam. You should now have /dev/video0 and /dev/video1. I have no idea why video1 gets created, but ignore it.
Next start v4l2loopback with "modprobe v4l2loopback devices=4" Now you should have video0 thru video6.
Now comes the tricky part, if you try to duplicate /dev/video0 to /dev/video3, video3 will work, but video0 will now report "device or resource busy", so you are still stuck with 1 video output. This occurs because REAL devices can only be accessed by 1 program at a time because they have real v4l2 controls. You can't have 2 programs accessing the same controls.
The solution is to duplicate /dev/video0 twice, like this:
ffmpeg -f video4linux2 -i /dev/video0 -codec copy -f v4l2 /dev/video3 -codec copy -f v4l2 /dev/video4
Now, you can view the normal video0 with "ffplay -i /dev/video3"
and, you can do something else with /dev/video4, like this
gst-launch-1.0 -v v4l2src device=/dev/video4 ! autovideoconvert ! videoconvert ! video/x-raw, width=640, height=480, framerate=30/1 ! vertigotv ! v4l2sink device=/dev/video5
Now you can see the original video with "ffplay -i /dev/video3" and your manipulated video with "ffplay -i /dev/video5"
I hope it helps, it took me a few hours of googling to figure that out. :-)

Related

setting the video format in v4l2 for streaming with gstreamer

I want to use gstreamer (gst-launch-1.0) to stream a video signal from a camera connected to a raspberry pi (CM4) to a remote client over UDP. The gstreamer pipelines that I use always reverts to the uncompressed YUYV pixel format even after I set the format to MJPG with v4l2.
This is my pipeline:
pi#cm4:~ $ v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=MJPG
pi#cm4:~ $ gst-launch-1.0 -v v4l2src device=/dev/video0 ! "video/x-raw, width=1920, height=1080, pixelformat=MJPG" ! rndbuffersize max=65000 ! udpsink host=127.0.0.1 port=1234
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps = video/x-raw, width=(int)1920, height=(int)1080, pixelformat=(string)MJPG, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)5/1, colorimetry=(string)2:4:5:1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = video/x-raw, width=(int)1920, height=(int)1080, pixelformat=(string)MJPG, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)5/1, colorimetry=(string)2:4:5:1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstRndBufferSize:rndbuffersize0.GstPad:src: caps = video/x-raw, width=(int)1920, height=(int)1080, pixelformat=(string)MJPG, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)5/1, colorimetry=(string)2:4:5:1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink: caps = video/x-raw, width=(int)1920, height=(int)1080, pixelformat=(string)MJPG, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)5/1, colorimetry=(string)2:4:5:1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstRndBufferSize:rndbuffersize0.GstPad:sink: caps = video/x-raw, width=(int)1920, height=(int)1080, pixelformat=(string)MJPG, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)5/1, colorimetry=(string)2:4:5:1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = video/x-raw, width=(int)1920, height=(int)1080, pixelformat=(string)MJPG, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)5/1, colorimetry=(string)2:4:5:1, interlace-mode=(string)progressive
Even though the pipeline seems to accept the "pixelformat=(string)MJPG", the format is YUY2 and the maximum framerate is the 5fps. If I set the framerate to anything higher than 5/1, it fails with:
** (gst-launch-1.0:16205): CRITICAL **: 21:36:05.076: gst_adapter_take_buffer: assertion 'GST_IS_ADAPTER (adapter)' failed
** (gst-launch-1.0:16205): CRITICAL **: 21:36:05.076: gst_adapter_available: assertion 'GST_IS_ADAPTER (adapter)' failed
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
After execution of the gstreamer pipeline, v4l2-ctl confirms that the video format reverted to YUYV.
How can I force the gstreamer pipeline to use MJPG 1920x1080 and enable higher frame rates?
The camera is a Canon 5D iv that produces a clean HDMI output up to full HD at 60fps. The camera HDMI output is connected to an HDMI to USB video capture (mirabox) that supports 1920x1080 at 60fps. The video capture box is connected to the CM4 via a USB3-PCIe adapter.
This is the list of supported formats:
pi#cm4:~ $ v4l2-ctl -d 0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture
[0]: 'MJPG' (Motion-JPEG, compressed)
Size: Discrete 1920x1080
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.100s (10.000 fps)
[..... deleted lower resolution formats...]
[1]: 'YUYV' (YUYV 4:2:2)
Size: Discrete 1920x1080
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1600x1200
Interval: Discrete 0.200s (5.000 fps)
[..... deleted lower resolution formats...]
Setting the pixel format is actually incorrect here. MJPEG is not a pixel fornat for "raw" video.
Try
v4l2src device=/dev/video0 ! image/jpeg, width=1920, height=1080, framerate=30/1 ! ..
Note that the camera will return you jpeg image data, so you will need a jpeg decoder if you want to display the image.

Need to decode a RTSP stream to V4l2loopback with gstreamer

I am trying to decode an RTSP stream to a V4L2 device on a raspberry pi zero.
first i create a loopback device this way..
sudo modprobe v4l2loopback video_nr=25
Then i try to decode the RTSP stream to a virtual V4L2 device. I would prefer if i could sink it to YUYV format..
sudo gst-launch-1.0 rtspsrc location=rtsp://192.168.1.138:8554/unicast ! rtph264depay ! h264parse ! decodebin ! videoconvert ! video/x-raw,format=YUY2 ! tee ! v4l2sink device=/dev/video25
When i inspect the V4L2 device with this...
v4l2-ctl -d 25 --list-formats , i get this...
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture
When i try to play it back with VLC , nothing happens.
sudo cvlc --v4l2-dev=25 --v4l2-width=640 --v4l2-height=480 --v4l2-fps=30 --vout=mmal_vout v4l2:///dev/video25
I suspect the gstreamer pipeline is not correct. I am new to gstreamer and i am poking a little bit in the dark there.
Could anybody give me some tips on what i am doing wrong here ?

Stream webcam with GStreamer (RTSP)

I have Kodak PIXPRO SP360 4k camera connected to the Jetson Nano or TX2 via USB cable.
I want to be able to see that video over browser, either with RTSP stream, Webrtc or something else.
It doesn't matter how it works in terms of technology, as long as it works. So if you have any ideas or suggestions be free to share them.
I'm currently trying to run the basic setup.
./test-launch "nvarguscamerasrc ! video/x-raw(memory:NVMM), format=NV12, width=1920, height=1080, framerate=30/1 ! nvvidconv ! video/x-raw, width=640, height=480, format=NV12, framerate=30/1 ! omxh265enc ! rtph265pay name=pay0 pt=96 config-interval=1"
and
gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:8554/test ! queue ! decodebin ! videoconvert ! xvimagesink
and I'm getting the error saying
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://127.0.0.1:8554/test
Progress: (open) Retrieving server options
Progress: (open) Retrieving media info
ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Could not get/set settings from/on resource.
Additional debug info:
gstrtspsrc.c(6999): gst_rtspsrc_setup_streams_start (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0:
SDP contains no streams
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
(test-launch:22440): GLib-GObject-WARNING **: 11:36:46.018: invalid cast from 'GstRtpH265Pay' to 'GstBin'
(test-launch:22440): GStreamer-CRITICAL **: 11:36:46.018: gst_bin_get_by_name: assertion 'GST_IS_BIN (bin)' failed
(test-launch:22440): GLib-GObject-WARNING **: 11:36:46.018: invalid cast from 'GstRtpH265Pay' to 'GstBin'
(test-launch:22440): GStreamer-CRITICAL **: 11:36:46.018: gst_bin_get_by_name: assertion 'GST_IS_BIN (bin)' failed
(test-launch:22440): GLib-GObject-WARNING **: 11:36:46.018: invalid cast from 'GstRtpH265Pay' to 'GstBin'
(test-launch:22440): GStreamer-CRITICAL **: 11:36:46.018: gst_bin_get_by_name: assertion 'GST_IS_BIN (bin)' failed
I have also tried an option that worked for me on PC but I can't get it to work on Jetson. The setup goes as follows.
Download Streameye from https://github.com/ccrisan/streameye and run:
netcat -l 8700 | ./streameye -p 1337
To send the webcam stream I run:
gst-launch-1.0 v4l2src device=/dev/video0 ! decodebin ! videoconvert ! videoscale ! videorate ! jpegenc quality=30 ! tcpclientsink host=127.0.0.1 port=8700
After this I get:
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
Additional debug info:
gstbasesrc.c(3064): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-negotiated (-4)
Execution ended after 0:00:03.944998186
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
Output of this command for my camera is:
v4l2-ctl -d /dev/video1 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'MJPG' (compressed)
Name : Motion-JPEG
Size: Discrete 3840x2160
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 2880x2880
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 2048x2048
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1440x1440
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1920x1080
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 640x360
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.200s (5.000 fps)
run your pipe with -v like this and show me result:
gst-launch-1.0 v4l2src device=/dev/video0 ! decodebin ! videoconvert ! videoscale ! videorate ! jpegenc quality=30 ! tcpclientsink host=127.0.0.1 port=8700 -v
If you want to stream it, the simplest way will be to use gst-rtsp-launch which is part of GStreamer prebuild binaries:
gst-rtsp-launch '( v4l2src device=/dev/video0 ! videoconvert ! queue ! x264enc tune="zerolatency" byte-stream=true bitrate=10000 ! rtph264pay name=pay0 pt=96 )'
Later on you can tune codec, bitrate, but for me this is enough (playable in VLC - rtsp://127.0.0.1:8554/test)

How to invert video with v4l2loopback and gstreamer?

I am trying to vertically invert video but I get the following:
GST_DEBUG=2 gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! videoflip method=vertical-flip ! v4l2sink device=/dev/video1
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
0:00:00.404780204 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YUYV#48x32: 0
New clock: GstSystemClock
0:00:00.404881855 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YUYV#48x32: 0
0:00:00.404943395 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at UYVY#48x32: 0
0:00:00.405010945 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YU12#48x32: 0
0:00:00.405068424 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YV12#48x32: 0
0:00:00.405123299 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YVU9#48x32: 0
0:00:00.405179552 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YUV9#48x32: 0
0:00:00.405234361 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at RGB4#48x32: 0
0:00:00.405287186 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at BGR4#48x32: 0
0:00:00.405339302 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at RGB3#48x32: 0
0:00:00.405396859 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at BGR3#48x32: 0
0:00:00.405447885 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at GREY#48x32: 0
0:00:00.405497954 32410 0x23b1e30 WARN v4l2 gstv4l2object.c:2206:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YVYU#48x32: 0
0:00:00.595326610 32410 0x23b1e30 WARN v4l2bufferpool gstv4l2bufferpool.c:541:gst_v4l2_buffer_pool_set_config:<v4l2src0:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
0:00:00.821482196 32410 0x23b1e30 ERROR v4l2allocator gstv4l2allocator.c:1299:gst_v4l2_allocator_dqbuf:<v4l2sink0:pool:sink:allocator> buffer 1 was not queued, this indicate a driver bug.
0:00:00.821571739 32410 0x23b1e30 WARN basesrc gstbasesrc.c:2943:gst_base_src_loop:<v4l2src0> error: Internal data flow error.
0:00:00.821609647 32410 0x23b1e30 WARN basesrc gstbasesrc.c:2943:gst_base_src_loop:<v4l2src0> error: streaming task paused, reason error (-5)
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data flow error.
Additional debug info:
gstbasesrc.c(2943): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming task paused, reason error (-5)
Execution ended after 0:00:00.417011242
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
This works if I do not include the videoflip filter. I have tried it with a lot of different caps.
I think I need a more recent version of the v4l2loopback driver, but I am not sure.
It caused by v4l2loopback driver bug
and fixed in 0.10
ref:https://github.com/umlaeute/v4l2loopback/issues/116

v4l2sink works in gstreamer 0.10, but not in 1.0

This works:
$ GST_DEBUG="*:2" gst-launch-0.10 uridecodebin uri=file:///home/m132/Wideo/peespe.mp4 ! v4l2sink device=/dev/video1
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
0:00:00.046280176 3378 0x11d3850 WARN qtdemux qtdemux_types.c:191:qtdemux_type_get: unknown QuickTime node type avc1
0:00:00.046346724 3378 0x11d3850 WARN qtdemux qtdemux_types.c:191:qtdemux_type_get: unknown QuickTime node type avcC
0:00:00.046475793 3378 0x11d3850 WARN qtdemux qtdemux.c:7044:qtdemux_parse_trak:<qtdemux0> unknown version 00000000
0:00:00.062728530 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YUYV#48x32: 0
0:00:00.062827014 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YUYV#48x32: 0
0:00:00.062900935 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at UYVY#48x32: 0
0:00:00.062960596 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YU12#48x32: 0
0:00:00.063020699 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YV12#48x32: 0
0:00:00.063080026 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YVU9#48x32: 0
0:00:00.063136468 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YUV9#48x32: 0
0:00:00.063212572 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at RGB4#48x32: 0
0:00:00.063276755 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at BGR4#48x32: 0
0:00:00.063336345 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at RGB3#48x32: 0
0:00:00.063397002 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at BGR3#48x32: 0
0:00:00.063454343 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at GREY#48x32: 0
0:00:00.063514132 3378 0x11d5280 WARN v4l2 gstv4l2object.c:1771:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YVYU#48x32: 0
0:00:00.129788005 3378 0x11d5280 WARN v4l2 gstv4l2bufferpool.c:367:gst_v4l2_buffer_pool_new:<v4l2sink0> using 8 buffers instead
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
0:00:00.133604857 3378 0x123d440 WARN bin gstbin.c:2395:gst_bin_do_latency_func:<pipeline0> did not really configure latency of 0:00:00.000000000
New clock: GstSystemClock
Redistribute latency...
0:00:00.157448133 3378 0x123d440 WARN bin gstbin.c:2395:gst_bin_do_latency_func:<pipeline0> did not really configure latency of 0:00:00.000000000
Got EOS from element "pipeline0".
Execution ended after 21079905156 ns.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
However, this one fails immediately:
$ GST_DEBUG="*:2" gst-launch-1.0 uridecodebin uri=file:///home/m132/Wideo/peespe.mp4 ! v4l2sink device=/dev/video1
Setting pipeline to PAUSED ...
0:00:00.135221066 3504 0x1f94930 WARN basesrc gstbasesrc.c:3470:gst_base_src_start_complete:<source> pad not activated yet
0:00:00.135913536 3504 0x1f94930 WARN basesrc gstbasesrc.c:3470:gst_base_src_start_complete:<source> pad not activated yet
Pipeline is PREROLLING ...
Redistribute latency...
0:00:00.179098065 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YUYV#48x32: 0
0:00:00.179206928 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YUYV#48x32: 0
0:00:00.179273041 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at UYVY#48x32: 0
0:00:00.179318580 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YU12#48x32: 0
0:00:00.179361779 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YV12#48x32: 0
0:00:00.179405357 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YVU9#48x32: 0
0:00:00.179466247 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YUV9#48x32: 0
0:00:00.179508617 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at RGB4#48x32: 0
0:00:00.179549910 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at BGR4#48x32: 0
0:00:00.179591433 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at RGB3#48x32: 0
0:00:00.179633245 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at BGR3#48x32: 0
0:00:00.179675456 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at GREY#48x32: 0
0:00:00.179724725 3504 0x7f5354008590 WARN v4l2 gstv4l2object.c:1839:gst_v4l2_object_probe_caps_for_format_and_size:<v4l2sink0> Unknown frame interval type at YVYU#48x32: 0
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
0:00:00.249391995 3504 0x7f5354008590 ERROR v4l2 gstv4l2bufferpool.c:1133:gst_v4l2_buffer_pool_dqbuf:<v4l2sink0:pool:sink> No free buffer found in the pool at index 2.
0:00:00.249754249 3504 0x7f53600518f0 WARN qtdemux qtdemux.c:4434:gst_qtdemux_loop:<qtdemux0> error: streaming stopped, reason error
ERROR: from element /GstPipeline:pipeline0/GstURIDecodeBin:uridecodebin0/GstDecodeBin:decodebin0/GstQTDemux:qtdemux0: GStreamer encountered a general stream error.
Additional debug info:
qtdemux.c(4434): gst_qtdemux_loop (): /GstPipeline:pipeline0/GstURIDecodeBin:uridecodebin0/GstDecodeBin:decodebin0/GstQTDemux:qtdemux0:
streaming stopped, reason error
Execution ended after 0:00:00.009459057
0:00:00.250059271 3504 0x7f53600518f0 WARN multiqueue gstmultiqueue.c:1791:gst_multi_queue_sink_event:<multiqueue0> error: Internal data stream error.
0:00:00.250207990 3504 0x7f53600518f0 WARN multiqueue gstmultiqueue.c:1791:gst_multi_queue_sink_event:<multiqueue0> error: streaming stopped, reason error
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
(gst-launch-1.0:3504): GStreamer-CRITICAL **: gst_object_unref: assertion '((GObject *) object)->ref_count > 0' failed
Setting pipeline to NULL ...
Freeing pipeline ...
I'm using Fedora 21 and following versions of gstreamer:
$ gst-launch-0.10 --version
gst-launch-0.10 version 0.10.36
GStreamer 0.10.36
http://download.fedoraproject.org
$ gst-launch-1.0 --version
gst-launch-1.0 version 1.4.4
GStreamer 1.4.4
http://download.fedoraproject.org
/dev/video1 device being created by v4l2loopback. I have to use gstreamer 1.0, because it's the only version supported by gnome-shell's desktop capture interface.
Use
$ gst-inspect-1.0 v4l2sink
to check the format of video that v4l2sink that able to handle in gst-launch-1.0