Question about vpx_codec_decode in libvpx

Skip to first unread message


May 12, 2015, 2:25:16 PM5/12/15
to apps-devel, william

Hi experts,

This is Jim and I am using libvpx for a voip project. Now I am confused with the method of 


vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t    *ctx,

                                 const uint8_t      *data,

                                 unsigned int       data_sz,

                                 void               *user_priv,

                                 long               deadline);

How can I to get the previously decoded frame when I found something wrong with the current frame? According to the comment of 

   *\param[in] data         Pointer to this block of new coded data. If

   *                    NULL, a VPX_CODEC_CB_PUT_FRAME event is posted

   *                        for the previously decoded frame.

Can I just call vpx_codec_decode() to tell the decoder to use last frame by setting the data to NULL and the data_sz to 0?

Or the application should buffer the correct frame, and to implement a call back for event of VPX_CODEC_CB_PUT_FRAME? If so, how to get that?

Looking forwards to your answer! Your help will be appreciated!




May 14, 2015, 5:32:16 AM5/14/15
to apps-devel, jim

Hi vp8 experts,

Second try. Can anyone help?



 Original Message 
Sender: jim<>
Date: Tuesday, May 12, 2015 18:13
Subject: Question about vpx_codec_decode in libvpx

Jim Bankoski

May 14, 2015, 8:36:17 PM5/14/15
I'm not sure exactly what you are looking for. 

This will get you one of 3 prior reference frames :  


You can see an example of how to use it in the examples,  specifically vp8cx_set_ref.c 

There are also some examples for dealing with udp dropped packets in the udp_sample project.  Clone from here:

and the far more full featured webrtc code base, here: 

I hope that helps.  


May 14, 2015, 11:47:28 PM5/14/15
to Jim Bankoski, apps-devel, jim

Jim, thanks for your kindly help.

While in poor networks condition, the sreen becomes green. To improve the user experience, I think that we can let the screen freeze by using last successfully decoded frame to display,  when the result of vpx_codec_decode() indicate that the current frame is corrupt. 

So now my understand is :

step 1) Use  vpx_codec_decode(vpx_codec_ctx_t    *ctx,

                                   const uint8_t        *data,

                                   unsigned int            data_sz,

                                   void               *user_priv,

                                   long                deadline);

    to decode rtp package data, and if the result is OK, and then get into step 2)

step 2) Use vpx_codec_get_frame(vpx_codec_ctx_t  *ctx,

                                       vpx_codec_iter_t *iter)

            to get the decoded frame, here the application should maintain these frames(the return value for vpx_codec_get_frame() ) if we want to use them in the future, right ?  Another question here, we call vpx_codec_decode() one time, does it means that we can get one image in step 2), or some time we get more than one image ?

And in the case of the current frame to be decoded is a corrupt frame, in step 1) we get a result of VPX_CODEC_CORRUPT_FRAME. We can use the image we maintain in last step 2)  after last successfully decoded frame in last step 1) , right 

I also confused with the the comment of vpx_codec_decode() :

   *\param[in] data         Pointer to this block of new coded data. If

   *                      NULL, a VPX_CODEC_CB_PUT_FRAME event is posted

   *                        for the previously decoded frame.

Does it mean that when the current frame being decoded is corrupt and then I can call the vpx_codec_decode() to tell the decoder to use last frame by setting the parameter data to NULL and data_sz to 0 Doese it mean that the applicaiton need not maintain the last successfully decoded frame by itself

Looking forwards to your help!

Jim Wei

 Original Message 
Sender: Jim Bankoski<>
Recipient: apps-devel<>
Cc: jim<>
Date: Friday, May 15, 2015 08:36
Subject: Re: Question about vpx_codec_decode in libvpx

Jim Bankoski

May 15, 2015, 9:31:02 AM5/15/15
to jim, apps-devel
I'm afraid not - if a frame is corrupt you'll have to do some work more manually.  You want to set the reference frame the encoder uses to a frame that occurred before the corruption. If you don't have a frame before the corruption to use as a reference you have to request a keyframe.  

in the udp sample I suggested,  this rechnique is used and is called a recovery frame ( search for the term recovery)..

This array covers the 3 types of recovery you might need.  

unsigned int recovery_flags[] = {0,  //   NORMAL,
      VPX_EFLAG_FORCE_KF,  //   KEY,
          | VP8_EFLAG_NO_REF_ARF,  //   GOLD = 2,
          | VP8_EFLAG_NO_REF_GF  //   ALTREF = 3

The first requests a keyframe,  the second forces use of the golden frame as a reference by dissallowing the alt ref and last frame as reference,  the third does the same thing but with the alt ref frame.   

I hope this helps.   

Good Luck, 


Reply all
Reply to author
0 new messages