How to add OSD to frame which data in GPU ?


I want to add a logo in video stream. And I use EGL to get every frame, the frame data in GPU. Does there has any interface or library to do this quickly ?


Other users may share 3rdparty applications for this.

You can also refer to tegra_multimedia_api\samples\common\algorithm\cuda and implement it via CUDA.

Hi, DaneLLL

I have found /tegra_multimedia_api/include/nvosd.h . And now I want to put the text to image. But it’s param make me confuse: 1. If I need fill every param ? The NvOSD_FontParams font_name, dose it mean font type ? I can fill with what , the font size range from 0 to 100 ? there is not specific illustratation. If any demo show it? 2. the NvOSD_Mode support MODE_CPU and MODE_HW, and the CPU only support RGBA data, the DMAbuf seems not support RGBA.


And now I have an eglImage in GPU with RGBA . How can I acquire fd ?

AFAIK, if you don’t bind a Nvbuffer with eglImage first, you cannot get the fd from eglImage.

You need to create a NvBuffer and then use “NvEGLImageFromFd” to get the eglImage.

Also, MODE_HW does not support text osd.

1 Like

As WayneWWW says, please follow


I have just checked the NvBufferCreate , and I found the color format seems not support RGBA.

typedef enum
} NvBufferColorFormat;

should I convert RGBA to ABGR32 ?

Hi ClancyLian,
NvBufferColorFormat_ABGR32 is 32 bit in [8-bit R:8-bit G:8-bit B:8-bit A]. If your data is not in this order, you need to do format conversion.

Hi, DaneLLL
I have use this to get fd from EGLimage:

if (-1 == NvBufferCreate(&fdOSD, cameraWidth, cameraHeight, NvBufferLayout_Pitch, 
              NvBufferColorFormat_ABGR32)) {
        printf("Create nvbuffer failed.\n");
    display = EGLDisplayAccessor::getInstance();
    eglImageOSD = NvEGLImageFromFd(display, fdOSD);
    CUgraphicsResource resourceOSD;
    CUresult statusOSD;
    statusOSD = cuGraphicsEGLRegisterImage(&resourceOSD, eglImageOSD, CU_GRAPHICS_MAP_RESOURCE_FLAGS_WRITE_DISCARD);
    if (statusOSD != CUDA_SUCCESS) {
        printf("cuGraphicsEGLRegisterImage failed: %d.\n", statusOSD);

    statusOSD = cuGraphicsResourceGetMappedEglFrame(&frameOSD, resourceOSD, 0, 0);
    if (statusOSD != CUDA_SUCCESS) {
        printf("cuGraphicsResourceGetMappedEglFrame failed: %d.\n", statusOSD);

    context = nvosd_create_context();

And then:

frameOSD.frame.pPitch[0] = imgData; //imgData is the image data in GPU with format RGBA

    NvOSD_TextParams textParam;
    textParam.display_text = "HELLO";
    textParam.x_offset = 100;
    textParam.y_offset = 100;
    textParam.font_params.font_name = "Arial";
    textParam.font_params.font_size = 40; = 1.0; = 1.0; = 1.0;
    textParam.font_params.font_color.alpha = 0.5;

    int ret = nvosd_put_text(context, MODE_CPU, fdOSD, 1, &textParam);

The ret is success, but I can’t see any text in the image after I added OSD in it.

Please follow this thread.

Hi, WayneWWW

1.Does the OSD support Chinese font ?

2.this OSD are written to the image permanent ? Or temporary ? When I encode it. can I see it in the image?

No, it does not support Chinese font and it should directly put it on your frame so you could see it even after encoding.

@WayneWWW, would it be possible to get the source code for the NVOSD library? I want to see how it puts boxes and text on top of video frames. And I want to see if I can modify the library to draw lines or bitblip graphics.

Sorry, no source code here. If you need such resources, please contact nvidia sales.