This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DM365 Dynamic Image Size Change Problem

DM365 Dynamic Image Size Change Problem

E-Mail: ykjung@seyeon.co.kr

Name: YongKil JUNG

The test environment====

H/W : DM36X EVM REV-D

Video Input Source: NTSC

SDK Version: dvsdk_2_10_01_18

Application: Network Camera

Base code: dvsdk_2_10_01_18\dvsdk_demos_2_10_00_17\dm365\encode

Application Code Process: Capture 􀃆 [Video (H.264) & Image (JPEG)] Encode

Test Case 1

I create the Capture(Resizer) & Encoders for the size of 720x480

No dynamic change case:

The Result

No Problem: I can get the normal H.264 & JPEG image of the size 720x480

 

 

JPEG(720x480) H.264(720x480)

Test Case 2

I create the Capture(Resizer) & Encoders for the size of 352x240

No dynamic change case:

The Result

No Problem: I can get the normal H.264 & JPEG image of the size 352x240

 

 

JPEG(352x240) H.264(352x240)

 

 

Test Case 3

I create the Capture(Resizer) & Encoders for the size of 720x480

I try to dynamic change from 720x480 to 352x240 for the Capture(Resizer) & Encoders.

The Result

I got the abnormal JPEG & H.264 image of the size 352x240

I think the Y is normal but the color is not correct to image.

 

 

JPEG(352x240) H.264(352x240)

 

Test Case 4

I create the Capture(Resizer) & Encoders for the size of 720x480

I try to dynamic change from 720x480 to 352x240 for the Capture(Resizer) & Encoders.

I try to delete & create for JPEG & H.264 encoders when the image size is changed.

The Result

No Problem & Problem:

I can get the normal JPEG image of the size 352x240

But I can get the abnormal H.264 image of the size 352x240

I think the Y is normal but the color is not correct to image.

 

 

JPEG(352x240) H.264(352x240)

 

Test Case 5

Confirming the capture Data.

I try to the capture data( 4:2:0) save to file. After that, I transfer the the format to normal YUV 4:2:0

Using YUVviewer : YUVviewer-seasound79.exe

The transfer method is followed

 

YYYYYYYYYYYYY                                YYYYYYYYYYYYY

YYYYYYYYYYYYY       -->                     YYYYYYYYYYYYY

YYYYYYYYYYYYY                                YYYYYYYYYYYYY

YYYYYYYYYYYYY                                YYYYYYYYYYYYY

CbCrCbCr                                                   CbCbCbCb

CbCrCbCr                                                   CrCrCrCr

 

YYYYYYYY...      -->   YYYYYYYY...

CbCrCbCr....  -->  CbCb.....  CrCr......

 

The Result

No Problem: I can get the normal YUV image of the size 352x240.

I can see the data is correct with color.

 

 

YUV(352x240)

 

 

 

My opinion.

I think the dynamic change function for image size of JPEG & H.264 Encoder has some problem.

 

I have the test code for this which is modified from the project "dvsdk_2_10_01_18\dvsdk_demos_2_10_00_17\dm365\encode".

So If anyone can help me, I will send the project files.

 

 

The dynamic change code for the Capture(resizer) part.

hRszOutBufCh[portId] = BufTab_getBuf(hRsBufTab[portId], bufIdx);

gfxAttrsRs.dim.width = width;

gfxAttrsRs.dim.height = height;

gfxAttrsRs.dim.x = 0;

gfxAttrsRs.dim.y = 0;

BufferGfx_setDimensions(hRszOutBufCh[portId], &gfxAttrsRs.dim));

Resize_config_2channel( hResizer,

BufTab_getBuf(Capture_getBufTab(hCapture), 0),

hRszOutBufCh[0],hRszOutBufCh[1]);

The dynamic change code for the Video(H.264) part.

h264DynParams.videncDynamicParams.inputWidth = currDim.width;

h264DynParams.videncDynamicParams.inputHeight = currDim.height;

h264DynParams.videncDynamicParams.captureWidth =

((h264DynParams.videncDynamicParams.inputWidth+31)/32)*32;

encStatus.data.buf = NULL;

encStatus.size=sizeof(VIDENC1_Status);

VIDENC1_control(hVe1->hEncode, XDM_RESET, &h264DynParams.videncDynamicParams, &encStatus);

VIDENC1_control(hVe1->hEncode, XDM_SETPARAMS, &h264DynParams.videncDynamicParams, &encStatus);

The dynamic change code for the Image(JPEG) part.

imageDynParams.inputWidth = currDim.width;

imageDynParams.inputHeight = currDim.height;

imageDynParams.captureWidth = ((imageDynParams.inputWidth+31)/32)*32;

encStatus.data.buf = NULL;

encStatus.size = sizeof(IMGENC1_Status);

IMGENC1_control(hIe1->hEncode, XDM_RESET, &imageDynParams, &encStatus);

IMGENC1_control(hIe1->hEncode, XDM_SETPARAMS, &imageDynParams, &encStatus);

END

 

 

///////////////////////////////////////////////////////////////////////////////////////////

// tiyuvconvert.c : This program is made for TI 4:2:0 YUV to normal 4:2:0 YUV

//

#include <stdio.h>

#include <stdlib.h>

#include <errno.h>

 

int main(int argc, char* argv[])

{

                  FILE *inputfp = NULL;

                  FILE *outputfp = NULL;

                  int              width;

                  int              height;

                  int              pixels;

                  int              idx;

                  unsigned char * pBuffer;

 

                  if (argc!=5)

                  {

                                   fprintf(stderr, "Usage : %s <input file name> <output file name> <width> <height>\n",argv[0]);

                                   return -1;

                  }

 

                  width = atoi(argv[3]);

                  height = atoi(argv[4]);

 

                  if(width <= 0 || height <= 0)

                  {

                                   fprintf(stderr, "parameter error [width = %d, height=%d]\n",width, height);

                                   return -1;

                  }

                 

                  inputfp = fopen(argv[1], "rb");

                  outputfp = fopen(argv[2], "wb");

 

                  if (!inputfp)

                  {

                                   fprintf(stderr, "fopen failed for input file[%s]\n",argv[1]);

                                   return -1;

                  }

                  if (!outputfp)

                  {

                                   fprintf(stderr, "fopen failed for output file[%s]\n",argv[2]);

                                   return -1;

                  }

                  pixels = width * height;

                  pBuffer = (unsigned char *)malloc(pixels);

 

                  // Read Y

                  fread (pBuffer, pixels, sizeof(unsigned char), inputfp);

                  // Write Y

                  fwrite(pBuffer, pixels, sizeof(unsigned char), outputfp);

 

                  // Read Cb Cr

                  fread (pBuffer, (pixels/2), sizeof(unsigned char), inputfp);

 

                  // Write Cb

                  for(idx = 0; idx <  (pixels/2); idx+=2)

                  {

                                   fwrite((pBuffer + idx), 1, sizeof(unsigned char), outputfp);

                  }

 

                  // Write Cr

                  for(idx = 1; idx <  (pixels/2); idx+=2)

                  {

                                   fwrite((pBuffer + idx), 1, sizeof(unsigned char), outputfp);

                  }

 

                  fclose(inputfp);

                  fclose(outputfp);

 

                  return 0;

}

///////////////////////////////////////////////////////////////////////////////////////////

 

 

  • Dear YK Jung,

    I am thinking that the buffer address set for Chroma data for both JPEG and H.264 encoder is wrong. How do you calculate the address for the chroma data for JPEG and H.264? Can you check that the difference between Y data address and UV data address is 352x240 after you change the resolution using dynamic switching?

    Also, we need the exact values of parameters you set for H.264 encoder dynamic params and also the addresses and size you set for the VIDENC1_process inArgs.

     

    Regards,

    Anshuman

  • Dear Anshuman,

    First of all thanks soooooo much.

    I think it is correct clue.

    I am using “dmai" library. So I call only the function "Venc1_process()" in Venc1.c and call the function "Ienc1_process()" in Ienc1.c.

    The files is located in "dvsdk_2_10_01_18\dmai_1_21_00_10\packages\ti\sdo\dmai\ce\".

    I just think the “dmia” library will be running well and  Now I don't understanding how can I calculate the address for the chroma data for JPEG and H.264.

    But I try to find out the problem in the functions "Venc1_process()" and "Ienc1_process()" as you mention that.

    If you can check the problem in the functions, please let me know.

  • Dear YK Jung,

    I assume you have the following code in the Venc1.c file inside DMAI.

     

    if (BufferGfx_getColorSpace(hInBuf) == ColorSpace_YUV420PSEMI) {
            inBufDesc.bufDesc[0].bufSize    = hVe->minInBufSize[0];
            inBufDesc.bufDesc[1].bufSize    = hVe->minInBufSize[1];

            inBufDesc.bufDesc[0].buf        = inPtr;
            inBufDesc.bufDesc[1].buf        = inPtr + Buffer_getSize(hInBuf) * 2/3;
            inBufDesc.numBufs               = 2;
        }

    Can you please print the values of inBufDesc.bufDesc[0].buf  and inBufDesc.bufDesc[1].buf, just after this if condition routine. I am suspecintg that Buffer_getSize might cause an issue in dynamic switching case. Also, as per my last suggestion, try changing the addresses of these two buffers (Y and UV) in the above code sucha that inBufDesc.bufDesc[0].buf = inPtr;

    and

    inBufDesc.bufDesc[1].buf = inPtr + (352*240);

    or

    inBufDesc.bufDesc[1].buf = inPtr + (736*480);

    Regards,

    Anshuman

  • Dear Anshuman,
    Your comment is perfect!!!!!!!!
    I confirm this problem.
    Thanks so much again.

    Sincerely yours,
    YK-Jung(YongKil JUNG).

  • i think this whole thread fits better underneath the forum category "codecs".

  • This is more of a DMAI code issue which is calling the codec APIs. So i think it is still ok to be in Linux forum, instead of codecs category.

    Regards,

    Anshuman

  • Dear Anshuman,

    Our family and I held a funeral ceremony for my mother.
    So I cannot read your message for resent week.

    I also think this whole thread fits better underneath the forum category "codecs".
    But how can I change the category to "codecs"?

    Sincerely yours,

    YK-Jung(YongKil JUNG).

  • Dear Anshuman,

    Our family and I held a funeral ceremony for my mother.
    So I cannot read your message for resent week.

    I also think this whole thread fits better underneath the forum category "codecs".
    But how can I change the category to "codecs"?

    Sincerely yours,

    YK-Jung(YongKil JUNG).

  • Hi,

    I confirm the problem with DMAI, I've had a similar problem in the past. This is how I've fixed it:

    inBufDesc.bufDesc[1].buf        = inPtr + dim.height * dim.lineLength;

    This should not depend on the actual image size since dim is previously calculated.

     

  • Hi Marco,

    I have a Dm368 setup,

    Resizer output is 736X480

    Codec is configured to 720x480

    If i set hInBuf wxh as 736x480, with line length/pitch as 736 - i get video encode process error with 0x8006 as error code.

    If i set hInBuf wxh as 720x480, with line length/pitch as 736 - i see the video is all messed up.

    i have made the same change in DMAI, to get the correct offset to Crb - dat pointer.

    Any thoughts would be helpful.

    -Ashok

  • hi yongking,

    why do you have this calculation for captureWidth ??

    h264DynParams.videncDynamicParams.captureWidth =

    ((h264DynParams.videncDynamicParams.inputWidth+31)/32)*32;

    -thanks 

    Ashok