NVJPEGEncoder not compress frame

Hi,

my setup JP4.6.1 AGX, imx264 2448x2048.

This code compress frame:

EGLStream::IImageJPEG * iJPEG{ Argus::interface_cast< EGLStream::IImageJPEG >( iFrame->getImage() ) };
                    if( iJPEG )
                    {
                        const auto file{ m_recordPath + "/" + std::to_string( cameraId ) + "/" + std::to_string( framesNum.at( cameraId ) ) + ".jpg" };
                        if( iJPEG->writeJPEG( file.c_str() ) != Argus::STATUS_OK )
                        {
                            std::cout << "Failed to write JPEG: " << file << std::endl;
                        }
                    }

This does not:


                    EGLStream::NV::IImageNativeBuffer * iNativeBuffer{ Argus::interface_cast< EGLStream::NV::IImageNativeBuffer >( iFrame->getImage()) };
                    if( not iNativeBuffer )
                        std::cout << "IImageNativeBuffer not supported by Image!" << std::endl;
                    else
                    {
                        if( m_dmaBuffers.at( cameraId ) == - 1 )
                        {
                            m_dmaBuffers.at( cameraId ) = iNativeBuffer->createNvBuffer( frameSize,
                                                                                         NvBufferColorFormat_YUV420,
                                                                                         NvBufferLayout_BlockLinear );
                        }

                        if( m_dmaBuffers.at( cameraId ) != - 1 )
                        {
                            if( iNativeBuffer->copyToNvBuffer( m_dmaBuffers.at( cameraId ) ) != Argus::STATUS_OK )
                            {
                                std::cout << "Failed to copy frame to NvBuffer!" << std::endl;
                            } else
                            {
                                const auto filename{ m_recordPath + "/" + std::to_string( cameraId ) + "/" + std::to_string( framesNum.at( cameraId ) ) + ".jpg" };
                                std::ofstream outputFile{ filename };
                                if( outputFile.is_open() )
                                {
                                    uint8_t * buffer = m_OutputBuffers.at( cameraId );
                                    unsigned long size{ bufferSize };
                                    m_JpegEncoders.at( cameraId )->encodeFromFd( m_dmaBuffers.at( cameraId ), JCS_YCbCr, & buffer, size );
                                    outputFile.write( ( char * ) buffer, bufferSize );
                                }
                            }
                        } else
                            std::cout << "Failed to create NvBuffer!" << std::endl;
                    }

First case file size about 200-400KB
Next one always 7.5MB as buffer size.

Please explain me that.

Best regards, Viktor.

Hi,
Please check and confirm if the fd is valid. For further investigation, please compare the code to the reference sample:

/usr/src/jetson_multimedia_api/samples/05_jpeg_encode
1 Like

Sorry, my mistake.

size should be rewritable.

m_JpegEncoders.at( cameraId )->encodeFromFd( m_dmaBuffers.at( cameraId ), JCS_YCbCr, & buffer, size );
outputFile.write( ( char * ) buffer, size );

1 Like

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