Saving video from MIPI cam

Hi, I’m looking for a method to save video from an Allied Vision 1800 C-319 camera. It’s connected to an AGX Xavier via FPD link.

ls /dev/video0 shows:

/dev/video0

v4l2-ctl -d /dev/video0 --list-formats-ext shows:

ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'GREY'
	Name        : 8-bit Greyscale
		Size: Discrete 2064x1544
			Interval: Continuous 0.036s - 100000.000s (0.000-27.691 fps)

	Index       : 1
	Type        : Video Capture
	Pixel Format: 'RGGB'
	Name        : 8-bit Bayer RGRG/GBGB
		Size: Discrete 2064x1544
			Interval: Continuous 0.036s - 100000.000s (0.000-27.691 fps)

	Index       : 2
	Type        : Video Capture
	Pixel Format: 'JXY0'
	Name        : 10-bit/16-bit Greyscale
		Size: Discrete 2064x1544
			Interval: Continuous 0.036s - 100000.000s (0.000-27.691 fps)

	Index       : 3
	Type        : Video Capture
	Pixel Format: 'JXR0'
	Name        : 10-bit/16-bit Bayer RGRG/GBGB
		Size: Discrete 2064x1544
			Interval: Continuous 0.036s - 100000.000s (0.000-27.691 fps)

	Index       : 4
	Type        : Video Capture
	Pixel Format: 'JXY2'
	Name        : 12-bit/16-bit Greyscale
		Size: Discrete 2064x1544
			Interval: Continuous 0.036s - 100000.000s (0.000-27.691 fps)

	Index       : 5
	Type        : Video Capture
	Pixel Format: 'JXR2'
	Name        : 12-bit/16-bit Bayer RGRG/GBGB
		Size: Discrete 2064x1544
			Interval: Continuous 0.036s - 100000.000s (0.000-27.691 fps)

	Index       : 6
	Type        : Video Capture
	Pixel Format: 'BX24'
	Name        : 32-bit XRGB 8-8-8-8
		Size: Discrete 2064x1544
			Interval: Continuous 0.036s - 100000.000s (0.000-27.691 fps)

	Index       : 7
	Type        : Video Capture
	Pixel Format: 'XR24'
	Name        : 32-bit BGRX 8-8-8-8
		Size: Discrete 2064x1544
			Interval: Continuous 0.036s - 100000.000s (0.000-27.691 fps)

	Index       : 8
	Type        : Video Capture
	Pixel Format: 'VYUY'
	Name        : VYUY 4:2:2
		Size: Discrete 2064x1544
			Interval: Continuous 0.036s - 100000.000s (0.000-27.691 fps)

I can start live streaming using:

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw, width=2064, height=1544" ! videoconvert ! xvimagesink
  1. I’m unsure how to record video and save it to a file.

  2. Is it possible to get a lossless recording?

  3. Why is the “videoconvert” necessary in the above pipeline?

  4. From the format info from above, if I add “format=GREY” to the pipeline, it doesn’t work. Only “BGRx” works - which is strange 'cus that’s not included in the formats list.

Any help appriciated!

Hi @Aleks-CST

  1. To record to a file, you can use the filesink gstreamer element and set it’s location property:

gst-launch-1.0 v4l2src device=/dev/video0 ! “video/x-raw, width=2064, height=1544” ! filesink location=video.raw

  1. The way you are using it, you are not encoding the captured data at all, and the buffers will be saved complete so you won’t lose any information from them.

  2. The video convert is necessary in order to link the v4l2src element with the xvimagesink element, it will provide the conversion between the data types. You can check which data types support both of the elements by using

gst-inspect-1.0 v4l2src

and

gst-inspect-1.0 xvimagesink

If you only want to save the raw frames as the pipeline above, you see you don’t need it.

  1. You can use the “format=GREY8” in the pipeline to make it work I believe, you can check the inspection of the formats using the inspect of the element as well.

Regards,
Roberto Gutierrez,
Embedded SW Engineer at RidgeRun
Contact us: support@ridgerun.com
Developers wiki: https://developer.ridgerun.com/

Additional note: Indeed, saving raw video will preserve all information, but be aware that this results in huge disk usage very fast. I’d advise to save raw video on an external disk so that you won’t fill your linux rootfs.

Also note that for playing it back you will need to know resolution and format, so better fix format in caps after v4l2src and rename output file with resolution/framerate/format details.

Hi,
Please try format=GRAY8. This is supported in v4l2src plugin.

Hi Dave,

gst-inspect-1.0 v4l2src shows a bunch of formats under “video/x-raw”, GRAY8 one of them. I’ve tried some of the others, but GRAY8 and BGRx are the only ones that work it seems.

It’s not really hindering my project, just for my own understanding - why would the formats shown from v4l2 inspect not work in the pipeline?

Thanks for your help!

Thanks for that tip, Honey_Pat. I just learned it the hard way. Jetson stopped booting, so had to go on to a host machine and remove some recordings. I’m now saving files to an external drive instead!

Regarding playing back the videos, I definitely need to change some things… I’m not able to view the videos.

Alright, so far so good. I’ve saved a video file. Size jumps up to 1-2GB with only a few seconds of recording, so that seems correct.

  1. Do I need to record in a different format if I want a colleague to be able to view it on a Windows machine? VLC throws the dreaded codec error…

  2. Regarding “videoconvert”:

Maybe I misunderstood you, but if I remove the videoconvert in the above example, I get:
“Internal data stream error”

  1. Regarding GRAY8:

This worked!

  1. Something weird happening with output resolution:
    Something I noticed while playing around with the different pipelines - the camera output changed from 2064x1544 to 2048x1544. This goes back to 2064x1544 when I powercycle. Not super important at the moment but maybe you have some clues to what could cause this.

Thanks for your help!

Hi

  1. You can just put that raw video inside an AVI file:

gst-launch-1.0 v4l2src device=/dev/video0 ! “video/x-raw, width=2064, height=1544,format=GRAY8” ! avimux ! filesink location=video.avi

That is reproducible by VLC.

  1. If you remove the videoconvert and it fails that’s because xvimagesink can’t handle GRAY8, so you need to convert it to something it can handle. filesink will support almost anything you throw at in, because it just stores the data. If you do a gst-inspect-1.0 avimux, you can see this:

Pad Templates:
SINK template: ‘video_%u’
Availability: On request
Capabilities:
video/x-raw
format: { (string)YUY2, (string)I420, (string)BGR, (string)BGRx, (string)BGRA, (string)GRAY8, (string)UYVY }
width: [ 16, 4096 ]
height: [ 16, 4096 ]
framerate: [ 0/1, 2147483647/1 ]

That means avimux can handle properly the gray8, and no conversion is needed.

Hope this helps.

This is exactly what I needed, thanks a lot!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.