The video scaling and color format conversion sample video_convert
demonstrates how to use the NvBufSurface APIs defined in nvbufsurface.h
and nvbufsurftransform.h
for image color formatting and buffer layout conversion.
NVIDIA® Jetson® provides pitch linear and block linear memory format support. The block-linear memory format complies with Jetson hardware.
This sample creates one or more threads to do conversion, each thread reads frame data from local file and write converted frame data to local file. For a better parallel scheduling, each thread creates its own session when '-s' or '–create-session' option are speficied.
This sample can also been used for video convert performance benchmark. When '–perf' option is speficied, each thread do video conversion in a loop (3000 times) after reading frame data from local file. To reduce benchmark deviation from file IO, input file should be image data instead of video data.
Since this sample needs to read frame data from local file and write converted frame data to local file, pitch linear memory is used in this sample(CPU cannot access block linear buffer).
This sample does not require a camera.
$ cd jetson_multimedia_api/samples/07_video_convert $ make
$ ./video_convert <in-file> <in-width> <in-height> <in-format> <out-file-prefix> <out-width> <out-height> <out-format> [OPTIONS]
$ ./video_convert ../../data/Picture/nvidia-logo.yuv 1920 1080 YUV420 test.yuv 1920 1080 YUYV
video_convert
sample consumes a YUV file. If you do not already have a YUV file, you can use the jpeg_decode
sample to generate one. For example: $ cd jetson_multimedia_api/samples/06_jpeg_decode/ $ ./jpeg_decode num_files 1 ../../data/Picture/nvidia-logo.jpg ../../data/Picture/nvidia-logo.yuv
The following diagram shows the flow of data through the sample.
To convert the color by using the NvBufSurface APIs, the nvbufsurface.h
and nvbufsurftransform.h
file define the key structures and APIs
Structure | Description |
---|---|
NvBufSurfaceAllocateParams | Holds the input parameters for hardware buffer creation. |
NvBufSurfaceParams | Holds parameters for a hardware buffer. |
NvBufSurfTransformParams | Holds parameters for buffer transform functions. |
NvBufSurfTransformRect | Holds coordinates for a rectangle. |
Method | Description |
---|---|
NvBufSurfaceAllocate() | Allocates a hardware buffer. |
NvBufSurfaceDestroy() | Destroys a hardware buffer. |
NvBufSurfTransformSetSessionParams() | Sets the user-defined session parameters for the parallel scheduling of buffer transformations and compositions. |
NvBufSurfaceFromFd() | Gets the NvBufSurface from the DMABUF FD. |
NvBufSurfaceMap() | Gets the memory-mapped virtual address of the plane. |
NvBufSurfaceUnMap() | Unmaps the mapped virtual address of the plane. |
NvBufSurfaceSyncForDevice() | Syncs the hardware memory cache sync for the device. |
NvBufSurfaceSyncForCpu() | Syncs the hardware memory cache for the CPU. |
NvBufSurfTransform() | Transforms one DMA buffer to another DMA buffer. |