Skip to content

V4L2 Reference

Video4Linux (V4L for short) is a collection of device drivers and an API for supporting realtime video capture on Linux systems.[1]

Installation

The v4l2 drivers should have been integrated with the kernel in most recent Linux distributions. But you may need to install the utils separately.

$ sudo apt install v4l-utils

For this package you get "v4l2-ctl".

v4l2-ctl

  • Check v4l2 version
$ v4l2-ctl --version
  • List available v4l2 devices
$ v4l2-ctl --list-devices
  • List supported formats of a device
$ v4l2-ctl --list-formats
$ v4l2-ctl --list-formats-ext 
$ v4l2-ctl --list-formats-ext --device /dev/video0
  • Set format to a device
$ v4l2-ctl --device /dev/video0 --set-fmt-video=pixelformat=MJPG
  • List available controls of a device
$ v4l2-ctl --list-ctrls --device /dev/video0
  • Set control of a device
$ v4l2-ctl --device /dev/video0 --set-ctrl control_name=value

Typical Use Cases

  • Pull video stream from a v4l2 device with specified format and desired frame rate
$ gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=90/1 ! \
jpegdec ! videoconvert ! fpsdisplaysink text-overlay=true video-sink="autovideosink"

Reference

  • [1] https://en.wikipedia.org/wiki/Video4Linux
  • [2] https://medium.com/@deepeshdeepakdd2/v4l-a-complete-practical-tutorial-c520f097b590
  • [3] https://github.com/PhysicsX/Gstreamer-on-embedded-devices