Search code examples
ffmpegh.264libavcodec

Effect of AV_CODEC_FLAG2_FAST in decoding H.264


Does anyone know what is the effect of AV_CODEC_FLAG2_FAST flag in libavcodec library (ffmpeg 4.0.2) when is set on AVCodecContext?

AVCodecContext* avCodecContext;
AVCodec* avCodec;

...
avCodec = ...;
avCodecContext = avcodec_alloc_context3(avCodec);
avCodecContext->flags2 |= AV_CODEC_FLAG2_FAST;
...
// start receiving stream and parsing and decoding frames
...

As I have tested on an AXIS camera, I cannot see any difference in decoding performance when this flag is set, compared to not using this flag.

Any idea, any information appreciated.


Solution

  • Based on a quick glance at the code, in multi-threaded decoding, the h264 decodes normally macroblocks in parallel, skipping the in-loop filter. Once the whole frame has been decoded, deblocking filter is applied serially, which can occur across slice boundaries.

    With the flag set, the deblocking is no longer postponed. The tradeoff is that deblocking does not cross slice boundaries, so there may be discontinuities/artifacts at slice edges.

    I would guess any relative speed-up would be prominent when decoding uses many threads.