Hi,
I am a beginner with Gstreamer. I connected my own camera with TX2 board and I have tried the following command to capture mkv video file.
$ gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw, format=(string)UYVY, width=(int)2304, height=(int)1296" ! nvvidconv ! "video/x-raw(memory:NVMM), format=(string)I420, width=(int)2304, height=(int)1296" ! omxh264enc ! matroskamux ! queue ! filesink location=/media/nvidia/Transcend/file.mkv
It works well. But the question is that, I want to capture raw data (huge file) instead of compressed format.
I followed command in this page https://devtalk.nvidia.com/default/topic/1012401/jetson-tx2/capturing-raw-video-using-gstreamer/
gst-launch-1.0 nvcamerasrc ! 'video/x-raw(memory:NVMM), width=1920, height=1080, format=I420, framerate=30/1' ! nvvidconv flip-method=6 ! 'video/x-raw, width=1920, height=1080, format=I420, framerate=30/1' ! filesink location=test.I420
But it does not work with my camera, should I do some modification? My camera is device=/dev/video0
Any help would be appreciated!
Be aware that storing raw I420 frames as you did may quickly fill your disk.
If you want to produce mkv from CSI camera capture, you should encode into h264:
gst-launch-1.0 -e nvcamerasrc ! 'video/x-raw(memory:NVMM), width=1920, height=1080, format=I420, framerate=30/1' ! omxh264enc ! matroskamux ! filesink location=/media/nvidia/Transcend/file.mkv
If you want to capture the raw frames, then just omit the omxh264enc and matroskamux from the pipeline, and save the raw video directly, like this:
$ gst-launch-1.0 v4l2src device=/dev/video0 \
! "video/x-raw, format=(string)UYVY, width=(int)2304, height=(int)1296" \
! nvvidconv \
! "video/x-raw(memory:NVMM), format=(string)I420, width=(int)2304, height=(int)1296" \
! queue \
! filesink location=/media/nvidia/Transcend/file.I420
Sorry I missed you wanted to store raw frames. Again, I’d advice to use an external disk for storage, so that your system disk keep available room. You may also give a given amount of frames with nvcamerasrc option num-buffers.
I’m a bit confused by your first command. It mentions /dev/video0 which should be the CSI onboard camera, having different format and sizes than your command’s option. I assume you have a different USB camera on /dev/video1.
For storing CSI capture to disk, you may use nvvidconv (not sure NVMM memory is supported by filesink/filesrc) :
gst-launch-1.0 -e nvcamerasrc ! 'video/x-raw(memory:NVMM), width=1920, height=1080, format=I420, framerate=30/1' ! nvvidconv ! 'video/x-raw, width=1920, height=1080, format=I420, framerate=30/1' ! filesink location=test.I420
And you would read later with something like:
gst-launch-1.0 filesrc location=test.I420 ! videoparse width=1920 height=1080 framerate=30/1 ! xvimagesink
Thanks @paulirino for quick answer. I tried your command, it seems working but the file saved in the disk was quite small which is unreasonable. I record one minute data which is only several MB. What is the problem?
Thanks @Honey_Patouceul for your quick answer!
Actually I removed the onboard camera from the TX2 board and plug my own CSI2 camera there. This is why /dev/video0 becomes my own camera.
But I tried your command, it is not working. I got the same error message, even though I reboot TX2 and tried again.
Setting pipeline to PAUSED ...
Socket read error. Camera Daemon stopped functioning.....
gst_nvcamera_open() failed ret=0
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstNvCameraSrc:nvcamerasrc0: GStreamer error: state change failed and some element failed to post a proper error message with the reason for the failure.
Additional debug info:
gstbasesrc.c(3354): gst_base_src_start (): /GstPipeline:pipeline0/GstNvCameraSrc:nvcamerasrc0:
Failed to start
Setting pipeline to NULL ...
Freeing pipeline ...
If your camera provides 8 bits format, you may use v4l2src plugin, as proposed by @paulirino.
No need to use NVMM memory. Does it work with:
gst-launch-1.0 -e v4l2src device=/dev/video1 ! 'video/x-raw, format=UYVY, width=2304, height=1296' ! filesink location=/media/nvidia/Transcend/file.UYVY
Hi Honey_Patouceul,
Thank you so much! This works well, creating large files shortly, which is what I want. But is it 30fps? as I don’t see this in the command.
And how to read the file? I tried this which does not work.
gst-launch-1.0 filesrc location=/media/nvidia/Transcend/file.UYVY ! videoparse width=2304 height=1296 framerate=30/1 ! xvimagesink
I420 is the default format for videoparse. As you are using UYVY instead, you have to set format in videoparse options (format=5 for UYVY):
gst-launch-1.0 filesrc location=/media/nvidia/Transcend/file.UYVY ! videoparse format=5 width=2304 height=1296 framerate=30/1 ! xvimagesink
Hi,
It does not work with reading the file.
Error message:
Setting pipeline to PAUSED ...
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0: Could not initialise Xv output
Additional debug info:
xvimagesink.c(1760): gst_xv_image_sink_open (): /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0:
Could not open display (null)
Setting pipeline to NULL ...
Freeing pipeline ...
Is it the problem with the framerate or something? In the capturing command there is no framerate.
Oh, sorry I found the problem. I need to run the command to connect HDMI
export DISPLAY=:0
Then the command opened the display but it was completely black, with a lot of warning message below
WARNING: from element /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0: A lot of buffers are being dropped.
Additional debug info:
gstbasesink.c(2854): gst_base_sink_is_too_late (): /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0:
There may be a timestamping problem, or this computer is too slow.
WARNING: from element /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0: A lot of buffers are being dropped.
Additional debug info:
gstbasesink.c(2854): gst_base_sink_is_too_late (): /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0:
There may be a timestamping problem, or this computer is too slow.
Looks surprizing…The error message is from xvimagesink. Are you logged locally with a monitor attached or remotely logged ? Have you changed environment variable DISPLAY ?
What gives:
gst-launch-1.0 videotestsrc ! 'video/x-raw, format=UYVY, width=2304, height=1296, framerate=30/1' ! xvimagesink
Of course, feel free to add framerate in the capture caps.
Hi,
I logged remotely with SSH. I didn’t change any variable. I only run export DISPLAY=:0 before reading file.
I also tried with locally logged-in monitor, and got the same error message.
gst-launch-1.0 videotestsrc ! 'video/x-raw, format=UYVY, width=2304, height=1296, framerate=30/1' ! xvimagesink
This command outputs a picture with bars in different colors.
Ok, so let’s first try to record and play with 10 seconds of videotestsrc:
gst-launch-1.0 videotestsrc num-buffers=300 ! 'video/x-raw, format=UYVY, width=2304, height=1296, framerate=30/1' ! filesink location=/media/nvidia/Transcend/videotest.UYVY
gst-launch-1.0 filesrc location=/media/nvidia/Transcend/videotest.UYVY ! videoparse format=5 width=2304 height=1296 framerate=30/1 ! xvimagesink
If it works, try again with your CSI camera:
gst-launch-1.0 -e v4l2src device=/dev/video1 num-buffers=300 ! 'video/x-raw, format=UYVY, width=2304, height=1296, framerate=30/1' ! filesink location=/media/nvidia/Transcend/capture0.UYVY
gst-launch-1.0 filesrc location=/media/nvidia/Transcend/capture0.UYVY ! videoparse format=5 width=2304 height=1296 framerate=30/1 ! xvimagesink
If you are remotely logged with ssh, you may try ssh -Y so that X stuff is forwarded to your host X server.
Just to be sure, what gives:
v4l2-ctl -d /dev/video0 --list-formats-ext
The first command to record 10 seconds of videotestsrc works. (Not sure if it works but no errors and I can see the display of several seconds of colorful bars)
Then I try again with my CSI camera,
I got error message when running the capture caps
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 flow error.
Additional debug info:
gstbasesrc.c(2948): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming task paused, reason not-negotiated (-4)
EOS on shutdown enabled -- waiting for EOS after Error
Waiting for EOS...
I tried ssh -Y as well, nothing changes.
Finally, This caps gives error message:
v4l2-ctl -d /dev/video0 --list-formats-ext
-bash: v4l2-ctl: command not found
Note this time the error comes from v4l2src, no longer from xvimagesink.
Be sure no other application or gstreamer pipeline is already using /dev/video0.
You may install v4l utils for v4l2-ctl:
sudo apt-get update
sudo apt-get install v4l-utils
After installing v4l utils, it gives
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'UYVY'
Name : UYVY 4:2:2
Size: Discrete 2304x1536
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 2304x1296
Interval: Discrete 0.022s (45.000 fps)
Size: Discrete 1920x1080
Interval: Discrete 0.017s (60.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.017s (60.000 fps)
Size: Discrete 640x480
Interval: Discrete 0.010s (100.000 fps)
No other application is using dev/video0, the error still exists even if I changed the camera to video0, video2 or video3.
I also reboot TX2, same error message. I also tried 1920*1080 resolution. Same error.
So for 2304x1296, your camera has framerate 45 fps, so you may try:
#Capture 10 seconds to file
gst-launch-1.0 -e v4l2src device=/dev/video1 num-buffers=450 ! 'video/x-raw, format=UYVY, width=2304, height=1296, framerate=45/1' ! filesink location=/media/nvidia/Transcend/capture0.UYVY
#Play back
gst-launch-1.0 filesrc location=/media/nvidia/Transcend/capture0.UYVY ! videoparse format=5 width=2304 height=1296 framerate=45/1 ! xvimagesink
Does it still fail ?
Hi,
The capture caps works. No error.
Buy the play back does not work. I can see a display window on the monitor but it was completely black and then it shuts down quickly in 2 seconds. I got this…
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Got EOS from element "pipeline0".
Execution ended after 0:00:01.400639548
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
Do you have enough space on eMMC for storing the 10s capture ?
Not sure it really improves, but I’d be curious to see if it changes.
You may also try to use 1080p resolution, not sure 45 fps is correctly handled everywhere.
Sorry I cannot give better advice, I don’t have such camera…I’ve just made a virtual v4l2 device with v4l2loopback, fed by a gstreamer pipeline capturing onboard camera and converting into similar format/resolution but with 30fps, storing 10s capture into home and it was working for playing it back…
Maybe someone with better knowledge may help further.