How to Skip Film Grain Decoding in libaom?

This article provides a technical guide on how to configure the libaom AV1 reference decoder to disable film grain synthesis during the decoding process. We will look at the specific library flags, command-line arguments, and code-level configurations required to bypass this feature, which is often done to reduce CPU overhead or for video debugging purposes.


Understanding AV1 Film Grain Synthesis

The AV1 video codec uses an advanced tool called Film Grain Synthesis. Instead of compressing and encoding the actual random noise (grain) present in a video—which is highly inefficient and consumes massive amounts of bitrate—the encoder analyzes the grain, removes it, and sends the grain parameters as metadata in the bitstream. The decoder is then responsible for regenerating and applying this grain back onto the decoded frames.

While this saves significant bandwidth, the process of synthesizing film grain can be computationally expensive during playback, especially on lower-end hardware.


Disabling Film Grain in the aomdec CLI

If you are using the compiled aomdec command-line tool to decode AV1 streams, you can explicitly instruct the decoder to ignore the film grain metadata.

By default, libaom applies film grain if it is present in the sequence headers. To skip it, you must use the --skip-film-grain flag.

aomdec input.ivf --skip-film-grain -o output.y4m

When this flag is passed, the decoder entirely bypasses the grain synthesis stage, outputting the “clean” or smoothed underlying video frames.


Disabling Film Grain in Code (C/C++ API)

If you are integrating libaom directly into a media player, transcoder, or custom application, you must use the aom_codec_control API to pass the configuration to the decoding context.

The control ID responsible for toggling film grain application is AOMD_SET_SKIP_FILM_GRAIN.

Implementation Steps

  1. Initialize the decoder context as you normally would using aom_codec_dec_init.
  2. Call the codec control function, passing the decoder context, the control ID, and an integer value of 1 to enable the skip functionality.

Here is a brief C code example:

#include <aom/aom_decoder.h>
#include <aom/aomdx.h>

// Assuming 'codec' is your initialized aom_codec_ctx_t
int skip_grain = 1;
aom_codec_err_t res = aom_codec_control(&codec, AOMD_SET_SKIP_FILM_GRAIN, skip_grain);

if (res != AOM_CODEC_OK) {
    // Handle error: the control could not be set
    printf("Failed to disable film grain synthesis: %s\n", aom_codec_error_detail(&codec));
}

Setting skip_grain to 1 forces the decoder to skip the application process. Setting it back to 0 (the default behavior) allows the decoder to apply film grain whenever the bitstream demands it.


Performance Implications

Bypassing film grain application significantly alters both the performance profile and the visual output of the decode pipeline: