Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High bitrate setting for aac codec #25

Open
yilun-zhangs opened this issue Jan 17, 2025 · 1 comment
Open

High bitrate setting for aac codec #25

yilun-zhangs opened this issue Jan 17, 2025 · 1 comment
Labels
bug Something isn't working enhancement New feature or request

Comments

@yilun-zhangs
Copy link

@jwcullen

  // Set bitrate based on the equation recommended by the documentation.
  RETURN_IF_NOT_OK(AacEncErrorToAbslStatus(
      aacEncoder_SetParam(
          encoder, AACENC_BITRATE,
          3 * num_channels * num_samples_per_frame * output_sample_rate / 2),
      "Failed to configure encoder bitrate."));

This is the bitrate setting reference from iamf-tools(aac_encoder.cc), the aac packet after encoding will contain more redundant data,
which will lead to larger packet size than ffmpeg's.

Following reference is from ffmpeg:

        if (avctx->bit_rate <= 0) {
            if (avctx->profile == AV_PROFILE_AAC_HE_V2) {
                sce = 1;
                cpe = 0;
            }
            avctx->bit_rate = (96*sce + 128*cpe) * avctx->sample_rate / 44;
            if (avctx->profile == AV_PROFILE_AAC_HE ||
                avctx->profile == AV_PROFILE_AAC_HE_V2 ||
                avctx->profile == AV_PROFILE_MPEG2_AAC_HE ||
                s->eld_sbr)
                avctx->bit_rate /= 2;

BWT, IAMF spec specify to use AAC-LC.

@jwcullen
Copy link
Collaborator

jwcullen commented Jan 17, 2025

Good point. Looks wrong. In current build you could try changing bitrate_mode. It matches FDK AAC's API here. So any mode 1-5 should trigger a variable bit rate modes. Which ignores the calculation above.

That default bit rate equation was supposed to come from the library documentation. I see 1.5 bits per frame for AAC-LC (§2.9.1 of doc). But it looks like the calculation is bad. I think it shouldn't have the factor of num_samples_per_frame.

And even so, we could expose per substream bit rate settings. Similar to #11, but also for AAC.

@jwcullen jwcullen added bug Something isn't working enhancement New feature or request labels Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants