Jetson Linux API Reference

35.4.1 Release
11_video_osd (video osd)

Overview

The video OSD sample video_osd demonstrates how to do OSD on video frame with nvosd.

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 OSD, each thread reads frame data from local file and write the frame data to local file. The input video frame will be converted to process frame. The process frame format can be RGGA/NV12 . User also can use '–bl' to use NV12 block linear format. nvosd can support CPU or VIC backend which only can draw shapes on RGBA video frame. nvosd also can support GPU backend which can draw shapes on RGBA/NV12 PL/NV12 BL format.

This sample can also been used for video OSD performance benchmark. When '–perf' option is speficied, each thread do video OSD in a loop (3000 times) after reading frame data from local file.

This sample does not require a camera.


Building and Running

Prerequisites

To build:

  • Enter:
     $ cd jetson_multimedia_api/samples/11_video_osd
     $ make
    

To run

  • Enter:
     $ ./video_osd <in-file> <in-width> <in-height> <in-format> <out-file-prefix> <process-format> [OPTIONS]
    

Example

   Generate source video:
   $ gst-launch-1.0 videotestsrc num-buffers=1 ! video/x-raw,width=1920,height=1080,format=RGBA ! filesink location=src_1920_1080.rgba
   CPU process mode:
   $ ./video_osd ./src_1920_1080.rgba 1920 1080 RGBA out.rgba RGBA -m 0
   VIC process mode:
   $ ./video_osd ./src_1920_1080.rgba 1920 1080 RGBA out.rgba RGBA -m 2
   GPU process mode:
   $ ./video_osd ./src_1920_1080.rgba 1920 1080 RGBA out.rgba RGBA -m 1
   $ ./video_osd ./src_1920_1080.rgba 1920 1080 RGBA out.rgba NV12 -m 1
   $ ./video_osd ./src_1920_1080.rgba 1920 1080 RGBA out.rgba NV12 -m 1 --bl
   Check output:
   $ gst-launch-1.0 filesrc location=out.rgba0 ! videoparse format=11 width=1920 height=1080 ! imagefreeze ! glimagesink

Flow

The following shows the flow of data through the sample.

  1. Reads input video frame from file (<in-file>).
  2. Converts input video frame to process format based on (<process-format>). Video frame will be converted to RGBA/NV12 PL/NV12 BL.
  3. Conducts OSD on converted video frame with CPU mode (-m 0), GPU mode (-m 1) or VIC mode (-m 2).
  4. Converts the format of processed video frame (RGBA/NV12 PL/NV12 BL) to the format of input video frame.
  5. Writes input video frame with in-place added OSDs into output file (<out-file-prefix>). Output file name will be appended thread number.


Key Structure and API

To do OSD by using the nvosd APIs, the nvosd.h file define the key structures and APIs

Structure

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.

API

Method Description
NvBufSurfaceAllocate() Allocates a hardware buffer.
NvBufSurfaceDestroy() Destroys a hardware buffer.
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.
[nvosd_create_context()] Creates nvosd context.
[nvosd_destroy_context()] Destroys nvosd context.
[nvosd_gpu_apply()] Draws shapes onto video frame by GPU.
[nvosd_draw_rectangles()] Draws rectangles onto video frame in CPU/VIC process mode or add rectangles into context in GPU process mode.
[nvosd_put_text()] Draws texts onto video frame in CPU/VIC process mode or add texts into context in GPU process mode.
[nvosd_draw_arrows()] Draws arrows onto video frame in CPU/VIC process mode or add arrows into context in GPU process mode.
[nvosd_draw_circles()] Draws circles onto video frame in CPU/VIC process mode or add circles into context in GPU process mode.
[nvosd_draw_lines()] Draws lines onto video frame in CPU/VIC process mode or add lines into context in GPU process mode.