DREAMER

[VPI] GstSample -> VPIImage 변환 본문

프로그래밍/NVIDIA

[VPI] GstSample -> VPIImage 변환

연소민 2024. 10. 8. 15:20
728x90
반응형

GstSample -> VPIImage

 

    void pullImage(GstSample *sample)
    {
        GstBuffer *buffer = gst_sample_get_buffer(sample);
        GstMapInfo buffer_info;
        
        if(buffer != NULL) 
        {
            gst_buffer_map(buffer, &buffer_info, GST_MAP_READ);

            if (image == NULL)
            {
                memset(&imgData, 0, sizeof(imgData));
                imgData.bufferType                        = VPI_IMAGE_BUFFER_HOST_PITCH_LINEAR;
                imgData.buffer.pitch.format               = VPI_IMAGE_FORMAT_RGBA8;
                imgData.buffer.pitch.numPlanes            = 1;
                imgData.buffer.pitch.planes[0].width      = 1920;
                imgData.buffer.pitch.planes[0].height     = 1080;
                imgData.buffer.pitch.planes[0].pitchBytes = 1920*1080*4;
                imgData.buffer.pitch.planes[0].data       = buffer_info.data;

                auto ret = vpiImageCreateWrapper(&imgData, nullptr, VPI_BACKEND_CUDA, &(image));
                
                if (ret != VPI_SUCCESS) {
                    LOG("Failed to vpiImageCreateWrapper %d\n", ret);
                }
            }
            else
            {
                imgData.buffer.pitch.planes[0].data       = buffer_info.data;
                auto ret = vpiImageSetWrapper(image, &imgData);
                if (ret != VPI_SUCCESS) {
                    LOG("Failed to vpiImageSetWrapper %d\n", ret);
                }
            }
            
            CHECK_STATUS(vpiSubmitConvertImageFormat(stream, VPI_BACKEND_CUDA, image, imageNV12, NULL));
            CHECK_STATUS(vpiSubmitImageFlip(stream, backend, imageNV12, outputNV12, VPI_FLIP_BOTH));
            CHECK_STATUS(vpiSubmitConvertImageFormat(stream, VPI_BACKEND_CUDA, outputNV12, output, NULL));

            CHECK_STATUS(vpiStreamSync(stream));

            VPIImageData outData;
            CHECK_STATUS(vpiImageLockData(output, VPI_LOCK_READ, VPI_IMAGE_BUFFER_HOST_PITCH_LINEAR, &outData));

            // Parse Image, save image to file or ...
            
            CHECK_STATUS(vpiImageUnlock(output));
            gst_buffer_unmap(buffer, &buffer_info);
        }
    }

 

 

 

 

728x90
반응형

'프로그래밍 > NVIDIA' 카테고리의 다른 글

[VPI] VPI란? Basic Concepts  (0) 2024.11.07
[Yocto] meta-tegra initrd로 플래시  (0) 2024.04.25
[Jetson Nano] Boot Process  (0) 2024.02.21
[Orin NX] Compatible Carrier Board  (0) 2024.02.06
[L4T] Release Notes  (0) 2024.02.06
Comments