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.

H.264 Ecoder Reconfiguration Issue.

Hello there:

I'm using H.264 Baseline Profile Encoder (v1.14) on DM648 and I'm trying to change the size of the video frame on the fly. When I go from a larger format to a shorter format no error is generated, however when I go from a shorter to a larger one, an error is generated.

I'm using the following piece of code to change the width and height of the frame:

   // Load parameters.
   params.size                = sizeof(VIDENC_DynamicParams);
   params.inputHeight         = height / factor;
   params.inputWidth          = width / factor;
   params.refFrameRate        = pCfg->frameRate;
   params.targetFrameRate     = pCfg->frameRate;
   params.targetBitRate       = pCfg->bitRate;
   params.intraFrameInterval  = pCfg->iFrmInterval;
   params.generateHeader      = XDM_ENCODE_AU;   
   params.captureWidth        = 0;     
   params.forceIFrame         = 0;

   // Set Dynamic Params for Encoder.
   status = VIDENC_control(vEncChInfo[chan], XDM_SETPARAMS, &params, &encStatus);

Should I use  VIDENC_delete(enc); before attempting to change the frame size?

Which parameters of the VIDENC_DynamicParams structure can be modified using VIDENC_control(vEncChInfo[chan], XDM_SETPARAMS, &params, &encStatus);?

Any thoughs would be appreciated.

Gabriel

 

 

  • Hi Gabriel,

    I have gone thru the h.264 encoder user guide and could not find any restrictions on changing sizes dynamicalle; which leads me to think this may be a potential bug which needs reporting.  Does this happen only when you start off with a small buffer, or does it also happen when you go from a large buffer to a small buffer and then back to a large buffer?

  • Hi Juan:

    Thanks for your response. I have double checked it and this happens in both scenarios, when you start with a small frame size and then you go to a larger frame size and when you start with a large and then go to small and then back to a large frame size.

    Another thing that I tried was to delete the codec instance using VIDENC_delete() and to close the engine using Engine_close(). With this there is no error after opeing the engine and creating the instance of the codec, however when you process the frame using VIDENC_process() the DSP goes into the woods and it does not return. Could this be related to the same issue?

  • I assume that along with the VIDENC_delete() and Engine_close(), you are doing a corresponding Engine_open() and VIDENC_create() call, correct?  If so, I would expect this to work all the time.  Are you finding otherwsie?

  • You are correct, after deleting the instance and closing the engine I open the engine and create an instance again.

    What I have seen is that some times it works when going from small frame size to a larger frame size and some times it doesn't work (Most of the time doesn't  work). The code get stuck in this loop:

    E40E0AC0          SYS_EXITFXN, UTL_halt:
    E40E0AC0 01BC54F7            STW.D2T2      B3,*SP--[2]
    E40E0AC4 1FFED812 ||         CALLP.S2      _HWI_disable (PC-2368 = 0xe40e0180),B3
    E40E0AC8          C$L1:
    E40E0AC8 0002A120            BNOP.S1       C$L1 (PC+8 = 0xe40e0ac8),5

  • you will have to do the DELETE and then CREATE again when going from lower to higher size. this is because all the memory allocation is done during CREATE.

     

    Arav

  • Hi Arav:

    As you can see above in this same post, I mentioned that I am actually  deleting and creating the encoder instance again, I'm using the following code:

    static Int createVencChan(Uint8 chan)
    {
       VIDENC_Params params = VENC_STATIC_PAR;
       String engineName    = "encdec";
       String encoderName   = "h264enc";

       // Delete codec instance and close code engine instance.
       if(vEncChInfo[chan] != NULL)
       {
          VIDENC_delete(vEncChInfo[chan]);
       }
       if(vEncEng[chan] != NULL)
       {
          Engine_close(vEncEng[chan]);
       }

       // Open Engine.
       if((vEncEng[chan] = Engine_open(engineName, NULL, NULL)) != NULL)
       {
          // Create encoder instance.
          vEncChInfo[chan] = VIDENC_create(vEncEng[chan], encoderName, &params);
       }

       return(vEncChInfo[chan] == NULL ? VENC_ERROR : VENC_SUCCESS);
    }

    However, this makes the code to jump here when the frame is being processed using VIDENC_process(), which it gets stuck for good.

    E40E0AC0          UTL_halt, SYS_EXITFXN:
    E40E0AC0 01BC54F7            STW.D2T2      B3,*SP--[2]
    E40E0AC4 1FFED812 ||         CALLP.S2      _HWI_disable (PC-2368 = 0xe40e0180),B3
    E40E0AC8          C$L1:
    E40E0AC8 0002A120            BNOP.S1       C$L1 (PC+8 = 0xe40e0ac8),5

    The other question is, why the max values of the frame size are in the VIDENC_Params and the working values of the frame size are in the VIDENC_DynamicParams if you can't change the values of the dynamic parameters using VIDENC_control()? In my personal opinion it would be better to specify the frame size in the static parameters only, this is because, firstable you can't change them using directly the dynamic parameters and secondly because you have to delete the instance anyways and create it again using VIDENC_Params. This is because there are two steps involved when you can do just one and make it more simple.

    Please let me know if there is something wrong in my code or even better if you have a sample code that can change frame sizes dynamically I would really appreciate it.

    Thanks;

    Gabriel

  • FWIW, I'm not sure why you're doing the Engine_close()/Engine_open() calls during this call.  You don't need to close/open the Engine just to delete/create a codec instance.

    I'm interested to understand if you think you need to call Engine_close/open... as well as whether you see the same behavior by removing the Engine_close/open cycle.

    Chris

  • Hi Chris:

    There is no particular reason to do Engine_close()/Engine_open(), I just wanted to make sure the encoder started fresh.

    I tried to create the instance without closing/opening the engine and I'm seeing the same result.

    Thanks;

    Gabriel

  • we  checked with release on DM648  - create using 176x144 (maxHeight, maxWidth =144,176, inputHeight, inputWidth =144,176) - encode 5 frames - delete - create using 640x480 (maxHeight, maxWidth =480,640, inputHeight, inputWidth =480,640) - encode This functioned properly.  can you try the same resolution change and see.

  • Hi Arav.

    I tried what you indicated but using QCIF(176X120) and then changing to 4CIF(704x480) - this is because these are the sizes that we are going to support.

    When it goes from QCIF to 4CIF (Even to 1CIF) it works fine, however if you go back to QCIF and then go back to 4CIF, then the same issue occurs.

    Thanks;

    Gabriel

  • HI Gabriel,

     

    I am facing a similar problem with H264 encoder on DM6467

    I start of with 4CIF encoder resolution and then delete this codec instance and create 2CIF instance , i dont see any errors when i do the new codec create and configuration.

    But the codec does not encode the video stream properly . (I captured the encoded stream and played it back with VLC ...saw that the codec is spitting out the same video frame again and gain - which also has some color problem)

    But when i delete this 2CIF codec instance and then create a 4CIF codec instance ...the video encoding is fine again.

     

    Were you able to solve the problem

    Is there any specific steps that i need to do when tearing down the encoder instance.

     

    -Thanks

    Ashok

     

     

     

  • here an update to the codec delete and create problem

     

    When i start with 2CIF configuration, iam able to delete and switch to any of these resolution (D1,4CIF, VGA) and back.

    But when i switch to CIF , the codec does not give out proper encoded frames ( the codec spits out the same frame again and again with has color artifacts )

    But when i switch back to 2CIF the video codec works fine.

     

    Any pointers to what could be going wrong

     

    Setup H264 encoder on DM6467

    -Ashok

    -

     

  • can you please let me know the version of the encoder being used (you can see from the release notes).  Arav

  • H264 codec version V1.01

     

    Regards

    Ashok