Jetson Linux API Reference

32.6.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
v4l2cuda (CUDA format conversion)

Overview

This sample uses V4L2 image capturing with NVIDIA® CUDA® format conversion.

Building and Running

Prerequisites

  • You have followed Steps 1-3 in Building and Running.
  • You have installed:
    • CUDA Toolkit
  • A USB camera suppporting YUYV output format is plugged into your target.

To build

  • Enter:
       $ cd v4l2cuda
       $ make
    

To clean up all generated files

  • Enter

    make clean

To run

  • Enter:
    $ ./capture-cuda [options]
    

To view supported options

  • Enter:
    $ ./capture-cuda --help
    


Flow

This is the overall process flow of capture-cuda:

            V4L2                          CUDA
USB camera ------> captured image (YUYV) ------> converted image (RGB)

As shown in the following diagrams, the buffer flow differs depending on V4L2 capturing modes and CUDA memory management.

V4L2 memory-mapped buffers (V4L2_MEMORY_MMAP) are allocated in kernel space. The application maps them in user space and copies them to the CUDA device allocated memory for CUDA processing.

The application allocates V4L2 user-space buffers (V4L2_MEMORY_USERPTR). In this situation, the driver directly fills in the user-space memory. When you allocate CUDA-mappable memory (with cudaHostAlloc), the CUDA device can access the V4L2 captured buffer without memory copy.

Using Memory-Mapped Buffers (-m option)

$ ./capture-cuda -d /dev/video0 -m

   _                       _              _           _
  | |  mmap        copy   | |  convert   | |  copy   | |  write
  |_| ------> ptr ------> |_| =========> |_| ------> |_| -------> file
        |
kernel  |  user

Using Memory-Mapped Buffers and Zero-Copy CUDA Memory (-m and -z options)

$ ./capture-cuda -d /dev/video0 -m -z

   _                       _              _
  | |  mmap        copy   | |  convert   | |  write
  |_| ------> ptr ------> |_| =========> |_| -------> file
        |
kernel  |  user

Using Application-Allocated Buffers (-u option)

$ ./capture-cuda -d /dev/video0 -u

               _           _              _           _
    userptr   | |  copy   | |  convert   | |  copy   | |  write
   ---------> |_| ------> |_| =========> |_| ------> |_| -------> file
        |
kernel  |  user

Using Application-Allocated Buffers and Zero-Copy CUDA Memory (-u and -z options)

$ ./capture-cuda -d /dev/video0 -u -z

               _              _
    userptr   | |  convert   | |  write
   ---------> |_| =========> |_| -------> file
        |
kernel  |  user