We are using Jetson Orin Nano with Jetpack 5.1.2-b104.
We were trying to NvJpegEncoder to encode image from camera to jpg. And then decode the jpg with NvJpegDecoder. The result has periodical green images from the decoding.
Then we tested with a standalone c code
#include <iostream>
using namespace std;
#include <NvJpegDecoder.h>
int main(int argc, char** argv) {
//load decodedImage0.jpg into memory
FILE *file = fopen("decodedImage0.jpg", "rb");
if (file == NULL) {
cout << "Error: File not found" << endl;
return 1;
}
fseek(file, 0, SEEK_END);
long fileSize = ftell(file);
fseek(file, 0, SEEK_SET);
unsigned char *bufferJpg = new unsigned char[fileSize];
fread(bufferJpg, fileSize, 1, file);
fclose(file);
NvJPEGDecoder* jpegdecoder;
jpegdecoder = NvJPEGDecoder::createJPEGDecoder("jpegdec");
NvBuffer *buffer;
NvBuffer *bufferTest[100];
uint32_t width, height, pixfmt;
struct timeval start, end;
for (int i=0;i<100;i++){
gettimeofday(&start, NULL);
jpegdecoder->decodeToBuffer(&buffer, bufferJpg, fileSize, &pixfmt, &width, &height); //12ms
gettimeofday(&end, NULL);
int diff = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
printf("Time taken to decode: %d\n", diff);
unsigned char firstPixel = buffer->planes[0].data[0];
printf("On round %d First pixel: %d\n", i, firstPixel);
free(buffer);
}
return 0;
}
Here is the output of 1st pixel.
Time taken to decode: 63767
On round 0 First pixel: 24
Time taken to decode: 15380
On round 1 First pixel: 24
Time taken to decode: 12644
On round 2 First pixel: 24
Time taken to decode: 12460
On round 3 First pixel: 24
Time taken to decode: 12425
On round 4 First pixel: 0
Time taken to decode: 10173
On round 5 First pixel: 24
Time taken to decode: 9956
On round 6 First pixel: 24
Time taken to decode: 9933
On round 7 First pixel: 24
Time taken to decode: 9924
On round 8 First pixel: 0
Time taken to decode: 9965
On round 9 First pixel: 24
Time taken to decode: 9917
On round 10 First pixel: 24
The same issue can also be triggered in “samples/06_jpeg_decode” without any modification. Both in decode-buffer and decode-fd has the issue.
./jpeg_decode num_files 5 decodedImage0.jpg out1.raw decodedImage0.jpg out2.raw decodedImage0.jpg out3.raw decodedImage0.jpg out4.raw decodedImage0.jpg out5.raw --decode-buffer
./jpeg_decode num_files 5 decodedImage0.jpg out1.raw decodedImage0.jpg out2.raw decodedImage0.jpg out3.raw decodedImage0.jpg out4.raw decodedImage0.jpg out5.raw --decode-fd
The 5th image is all 0.
Here I’ve attached the image we used.