# How to padding image for bytes alignment issue

**URL:** <https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999>\
**Category:** Jetson Thor\
**Tags:** camera, mmapi\
**Created:** [November 3, 2025, 6:46am UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999 "2025-11-03T06:46:07Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ekeechg](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ekeechg](https://forums.developer.nvidia.com/u/ekeechg)\
**Post date:** [November 3, 2025, 6:46am UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/1 "2025-11-03T06:46:08Z")

</div>

Hi,Nvidia team:  
When I run jetson\_mutimedia\_api sample 12\_v4l2\_camera\_cuda. the image will be abnormal, it will be OK if I don’t use dmabuf.  
My cameara resolution is 1600X1300, it should be the bytes alignment issue.  
How can I padding the image to walk around this issue? Could you provide a demo?

 ![image](https://global.discourse-cdn.com/nvidia/original/4X/1/3/7/137008b744d555c8c8cd0723bd12a7cbf7bd5e3e.jpeg)

BR//

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [November 3, 2025, 7:03am UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/3 "2025-11-03T07:03:10Z")

</div>

Hi,  
Please apply this path and try again:  
[Jetson\_multimedia\_api/samples/12\_v4l2\_camera\_cuda displays garbled output on the monitor - #6 by DavidDDD](https://forums.developer.nvidia.com/t/345250/6)

---

<div class="post-metadata">

**Author:** ![ekeechg](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ekeechg](https://forums.developer.nvidia.com/u/ekeechg)\
**Post date:** [November 3, 2025, 10:54am UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/4 "2025-11-03T10:54:36Z")

</div>

Hi, DaneLLL  
Where can I find the documents about NvBufSurfaceMapEglImage, NvBufSurfaceFromFd…  
are these functions open source?

BR//

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [November 4, 2025, 3:21am UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/5 "2025-11-04T03:21:29Z")

</div>

Hi,  
Source code of NvBufSurface is private. Please check the document:  
[NVIDIA DeepStream SDK API Reference: Buffer Management API module | NVIDIA Docs](https://docs.nvidia.com/metropolis/deepstream/7.0/dev-guide/sdk-api/group __ds__ nvbuf__api.html)

And please check the related code in the samples:

> /usr/src/jetson\_multimedia\_api/samples/

---

<div class="post-metadata">

**Author:** ![ekeechg](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ekeechg](https://forums.developer.nvidia.com/u/ekeechg)\
**Post date:** [November 4, 2025, 3:49am UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/6 "2025-11-04T03:49:53Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![ekeechg](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ekeechg](https://forums.developer.nvidia.com/u/ekeechg)\
**Post date:** [November 5, 2025, 5:45am UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/7 "2025-11-05T05:45:23Z")

</div>

Hi,DaneLLL:  
I have port the code to my H265 encoder, it works.  
But after run a few minute, it will crash, and print following log.  
What is the problem?

 ![dfdfba1a-9d05-4213-9aa7-3a1d2e2ede2e](https://global.discourse-cdn.com/nvidia/original/4X/a/7/5/a75da94c9ec0aa97b20e05969456e41a853e9b2c.jpeg)

BR

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [November 5, 2025, 1:39pm UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/8 "2025-11-05T13:39:45Z")

</div>

Hi,  
You may be missing some map/unmap functions in the integration. Please check if any function calls are missing, or duplicated.

---

<div class="post-metadata">

**Author:** ![ekeechg](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ekeechg](https://forums.developer.nvidia.com/u/ekeechg)\
**Post date:** [November 11, 2025, 1:39pm UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/9 "2025-11-11T13:39:07Z")

</div>

Is the following code in the patch thread safe? can I call it in two thread??

"  
static bool  
cuda\_mapping(context\_t \* ctx, int index)  
{  
NvBufSurface \*srcSurf = NULL;  
NvBufSurface \*dstSurf = NULL;

```
/* Create EGLImage from dmabuf fd */
if (-1 == NvBufSurfaceFromFd(ctx->g_buff[index].dmabuff_fd, (void**)(&srcSurf)))
    ERROR_RETURN("Failed to get NvBufSurface from FD");

/* Create Render buffer */
if(ctx->remap_fd == -1)
{
    NvBufSurf::NvCommonAllocateParams params = {0};
    params.memType = NVBUF_MEM_SURFACE_ARRAY;
    params.width = srcSurf->surfaceList[0].width;
    params.height = srcSurf->surfaceList[0].height;
    params.layout = NVBUF_LAYOUT_PITCH;
    params.colorFormat = srcSurf->surfaceList[0].colorFormat;
    params.memtag = NvBufSurfaceTag_NONE;
    if (NvBufSurf::NvAllocate(&params, 1, &ctx->remap_fd))
        ERROR_RETURN("Failed to create NvBuffer");
}

if (-1 == NvBufSurfaceFromFd(ctx->remap_fd, (void**)(&dstSurf)))
    ERROR_RETURN("Failed to get NvBufSurface from FD");

if (-1 == NvBufSurfaceMapEglImage(srcSurf, 0))
    ERROR_RETURN("Failed to register the Egl");

if (-1 == NvBufSurfaceMapEglImage(dstSurf, 0))
    ERROR_RETURN("Failed to register the Egl");

HandleEGLImageMapping(srcSurf->surfaceList[0].mappedAddr.eglImage,
                      dstSurf->surfaceList[0].mappedAddr.eglImage,
                      srcSurf->surfaceList[0].width,
                      srcSurf->surfaceList[0].height,
                      srcSurf->surfaceList[0].planeParams.bytesPerPix[0]);

/* Destroy EGLImage */
NvBufSurfaceUnMapEglImage(srcSurf, 0);
NvBufSurfaceUnMapEglImage(dstSurf, 0);

return true;

```

}  
"

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [November 12, 2025, 2:08am UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/10 "2025-11-12T02:08:32Z")

</div>

Hi,  
If you would like to access the same NvBufSurface in multiple threads, we would suggest add mutex lock.

---

<div class="post-metadata">

**Author:** ![ekeechg](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ekeechg](https://forums.developer.nvidia.com/u/ekeechg)\
**Post date:** [November 13, 2025, 4:44am UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/11 "2025-11-13T04:44:44Z")

</div>

Hi,  
Is there anyway to crop the image without memcpy? I see the padding image way need memcpy.

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [November 13, 2025, 6:47am UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/12 "2025-11-13T06:47:21Z")

</div>

Hi,  
Data alignment is hardware constraint. You can check if your camera source can generate frame data to fit the alignment. If the camera source cannot be adapted, re-mapping data through GPU is required.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [December 2, 2025, 7:38am UTC](https://forums.developer.nvidia.com/t/how-to-padding-image-for-bytes-alignment-issue/349999/14 "2025-12-02T07:38:21Z")

</div>

Closed on December 2, 2025, 7:38am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
