This page is documenting a merged feature available from release 11.


AVResample is getting extended and some resamplers and mixers have additional parameters that can be user-tuned. In order to match AVScale an AVFrame-based API will be introduced, reducing the boilerplate code and providing an example for the developers not using AVFrame but their own abstraction.

API Design

The API extension includes

  • A new function, with slightly different semantics, to configure/reconfigure the resampling context passing extended options.
  • A set of AVFrame based function to have a simplified setup.

Additional options

The new avresample_open2() will match the similarly-named functions in AVCodec and AVFormat.

int avresample_open2(AVAudioResampleContext *avr, AVDictionary **opts);

The function is currently equivalent of using the AVOption api directly on the avr context and then call avresample_open.

AVFrame based API

The main focus had been to simplify the setup and make AVResample simpler to use.

int avresample_config(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in, AVDictionary **opts);

int avresample_convert_frame(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in);

The normal workflow would be quite simplified

 AVAudioResampleContext *avr = avresample_alloc();
 AVFrame *out = av_frame_alloc();
 AVFrame *in;

 out->format         = format;
 out->channel_layout = layout;
 out->sample_rate    = rate;

 while (fill_input(in)) {
    ret = avresample_convert_frame(avr, out, in);

    if (configuration_changed(ret))
        avresample_convert_frame(avr, out, NULL);
        avresample_config(avr, out, in);
        avresample_convert_frame(avr, out, in);

 ret = avresample_convert_frame(avr, out, NULL);


Albeit not checking for allocation errors to keep the code compact, the code above is all that's needed to adapt to changes to the input format and convert to a fixed output.

Architecture Design

The internals are quite straightforward and the two functions are leveraging the already public avresample and avformat functions (avresample_convert, avresample_open, avresample_close, allocators).

CategoryBlueprint CategoryBlueprintMerged