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.
$ cd jetson_multimedia_api/samples/11_video_osd $ make
$ ./video_osd <in-file> <in-width> <in-height> <in-format> <out-file-prefix> <process-format> [OPTIONS]
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
The following shows the flow of data through the sample.
To do OSD by using the nvosd APIs, the nvosd.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. |
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. |