AVCodec provides a mean to offload to the hardware a large part of the decoding tasks. HWAccel had been initially conceived for slice-based hardware decoders and requires a large amount of implementation-specific setup and hook code.

The AVFrames produced by an hwaccel enabled decoder are to be considered opaque and the user has to render them by external means. They sport a specific AVPixelFormat.

HWAccel1 will be overhauled as explained in the HWAccel2 blueprint. This document aims at explaining the shortcomings of the current approach and shed some light on how it could be used.


The global context is expected to be setup by the user by using an allocator function provided and filling the fields with the underlying hardware acceleration interface structures.

Originally this approach was considered simpler since the variety of driver interfaces and that the interactions required to render the actual frame.

With hwaccel1.2 default setup function are provided, hwaccel2 would obsolete them hiding the calls in avcodec_open2.

# Apple VDA decoding
    if ((ret = avcodec_open2(avctx, codec, &opts)) < 0)
        goto fail;
    if ((ret = av_vda_default_init(avctx)) < 0) {
        av_log(avctx, loglevel, "Error creating VDA decoder.\n");
        goto fail;



The following function pointer has to be set in the AVCodecContext


It is used to check if the hwaccel supports the current codec configuration and allow a transparent fallback to software.


It is used to properly allocate/populate the AVFrame if needed.

hwaccel1.2 provides an internal callback to simplify the frame to simplify the allocation and reduce the amount of boilerplate code.

AVFrame rendering

The opaque, implementation-specific data is usually provided as the third pointer in the data field, with all the other data pointers set to NULL.

It is common to assert on the first element of the data field to avoid inconsistencies, it is suggested to check the first element of the buf field instead.

It is up to the integrator decide if the opaque has to be rendered to system memory, or, if the implementation is tied to a GPU, directly to the frame buffer.