[Libav-user] CodecContext Optimization to Decode H264

Carl Eugen Hoyos cehoyos at ag.or.at
Thu Feb 21 17:08:05 CET 2013

Jérôme SALAYET <jerome.salayet at ...> writes:

> I someone can tell me if I use the better ones to decode H264 :
> m_lpCodecCtx->skip_frame       =  AVDISCARD_NONREF;
> m_lpCodecCtx->skip_loop_filter =  AVDISCARD_ALL;

Do you know what these two are doing?
I consider them extremely useful but if 
you don't know what they exactly do, it 
is very bad to set them.

> m_lpCodecCtx->skip_idct        =  AVDISCARD_ALL;
> m_lpCodecCtx->idct_algo        =  1;

I suspect they have no effect on H264 decoding, 
generally I don't think you would use them if 
they would work.

> m_lpCodecCtx->has_b_frames     =  0;
> m_lpCodecCtx->refs             =  1;

Documentation says "decoding: Set by libavcodec", 
so you should definitely not set them.

> av_opt_set(m_lpCodecCtx->priv_data, "preset", "ultrafast", 0);
> av_opt_set(m_lpCodecCtx->priv_data, "tune", "zerolatency", 0);

I may absolutely miss something, but these look like 
encoding parameters.

> I also set the codec flags like this :
> if(m_lpCodec->capabilities&CODEC_CAP_TRUNCATED) 

>  m_lpCodecCtx->flags|= CODEC_FLAG_TRUNCATED;

I would expect that this has a performance hit, 
only use it if you know why.

> // Enable faster H264 decode.

> m_lpCodec->capabilities |= CODEC_CAP_FRAME_THREADS;

I don't think you can set codec capabilities.

> m_lpCodecCtx->flags     |= CODEC_FLAG_LOW_DELAY;

(I am not convinced you should always set this 
flag, but I probably don't know enough to really 
say this.)

> m_lpCodecCtx->flags2    |= CODEC_FLAG2_FAST;

This is the only dangerous flag, it means:
"I know that my input is 100% error free, I 
don't mind if libavcodec crashes on invalid 
(Depending on your use-case this may or may 
not be what you want, note that the performance 
impact is very, very small, so you probably 
don't want it.)

Carl Eugen

More information about the Libav-user mailing list