Simplifying v4l2 workflows with Raviewer and pyrav4l2


Topics: Open source tools, Open machine vision, Open software libraries

Raviewer is an open source tool Antmicro has developed to facilitate image preview and debugging in various video-processing environments, wrapped in a nice and simple UI. Now, expanding Raviewer’s capabilities, we have published pyrav4l2, a Python library intended for use on target devices in various scenarios involving cameras on Linux. For an overview of Raviewer’s features, see the original blog note. The pyrav4l2 open source utility is available on Antmicro’s GitHub and the features it introduces are discussed more broadly below.

pyrav4l2 and Raviewer logotypes

Open source and ease of use

The initial reason behind developing Raviewer was to enable efficient debugging within video acquisition pipelines, e.g. for the purpose of writing camera sensor drivers for a new sensor or platforms such as Jetson AGX Orin, AMD/Xilinx Kria or Qualcomm Snapdragon. As a company often building machine vision solutions from scratch, Antmicro needs the ability to easily adjust and debug video pipelines with a visual interface.

Raviewer’s capabilities originally revolved around the ability to adjust presets based on a frame captured by the video source such as:

  • Color formats: RGB, YUV, BAYER and their variations (RGB24, YUY2, etc.)
  • Frame width and height
  • Data order manipulation

Pyrav4l2 connects Raviewer directly to the video source on the target device, providing a more streamlined development experience and control over the camera parameters, as described below.

Live preview, camera settings and more

The pyrav4l2 library extends Raviewer’s original feature set, eliminating the need for other low-level utilities (e.g. v4l-ctl for capturing the video frames). First of all, pyrav4l2 enables live preview streaming directly from the target v4l2 camera to Raviewer, greatly facilitating frame capture and selection, and also dropping the need for transferring captured frames between the host PC running Rawiever and the embedded device generating the video in order to perform an analysis.
What is also worth mentioning, pyrav4l2 grants direct access to camera controls, allowing the user to adjust such parameters as brightness, contrast, white balance, exposure, crop, etc., depending on the target device’s available settings.

Camera settings view in Raviewer

Generally speaking, pyrav4l2 greatly simplifies tasks such as camera bring-up for demo applications workflows by removing the need to download, transfer and import the captured frames between devices.

pyrav4l2 workflow improvement

Generic tool for v4l2 devices

Even though pyrav4l2 was developed to work with Raviewer and complement its original feature set, it is a generic Python library that can be used in other scenarios involving cameras on Linux, both in a simple console script or a more complex program with a GUI.

Below is an example of a script that uses pyrav4l2 to enumerate all possible color formats and frame sizes available for a given camera and prompt the user to choose one of each:

from pyrav4l2 import Device

dev = Device("/dev/video0")
available_formats = dev.available_formats

formats_dict = {}
print("Available formats and frame sizes:")
for i, color_format in enumerate(available_formats.keys()):
    formats_dict[i] = color_format
    print(f"[{i}]: {color_format}:")
    for j, frame_size in enumerate(available_formats[color_format]):
        print(f"    [{j}]: {frame_size}")

max_format_idx = len(formats_dict.keys()) - 1
format_idx = int(input(f"Choose color format [0 - {max_format_idx}]: "))
format_idx = min(max(format_idx, 0), max_format_idx)
selected_format = formats_dict[format_idx]

max_frame_size_idx = len(available_formats[selected_format]) - 1
frame_size_idx = int(input(f"Choose frame size [0 - {max_frame_size_idx}]: "))
frame_size_idx = min(max(frame_size_idx, 0), max_frame_size_idx)
selected_frame_size = available_formats[selected_format][frame_size_idx]

dev.set_format(selected_format, selected_frame_size)

Improve your workflows with pyrav4l2 and Raviewer

The example above is just one of many ways pyrav4l2 can simplify workflows involving v4l2 cameras. As a Python library, pyrav4l2 allows for scripting, which often saves time by eliminating the need to write custom C or C++ applications for controlling v4l2 API features directly. This is very useful for camera demos, rapid prototyping and product development.

If you are dealing with video-related projects and looking for ways to improve your workflows with an open source, software-first approach towards your FPGA, SoC or embedded GPU platforms, do not hesitate to contact us at

See Also: