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

VBR Mode for AAC #348

Closed
arjunmehta opened this issue Dec 17, 2014 · 4 comments

Comments

@arjunmehta
Copy link

commented Dec 17, 2014

It seems as though different encoders have different command line flags for their VBR options.
For example, libmp3lame uses the -aq flag, but the libfdk_aac encoder, uses the -vbr flag.

When using the libfdk_aac codec to output an AAC encoded audio file, using the audioQuality() method doesn't seem to properly affect the VBR mode of the output.

function transcode(qualityLevel){
  command.clone()
      .audioCodec('libfdk_aac')
      .audioQuality(qualityLevel)
      .save('VBRoutput-' + qualityLevel + '.m4a')
      .on('progress', function(progress) {
        console.log(' Processing:', progress.percent, '% done');
      })
      .on('end', function() {
        console.log('Transcoding succeeded!');
      })
      .on('error', function(err) {
        console.log('Transcoding ERROR:', err.message);
      });
}

for (var quality = 0; quality < 6; quality++){
  transcode(quality);
}

Oddly, only when passing 0 to .audioQuality() (ie. .audioQuality(0)) DOES seem to do something with the audio quality, and the output file size, but everything else between 1 and 5 (as the spec says to use), doesn't seem to do anything.

See more here: https://trac.ffmpeg.org/wiki/Encode/AAC#fdk_vbr

@arjunmehta

This comment has been minimized.

Copy link
Author

commented Dec 17, 2014

Looking at the source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/lib/options/audio.js#L109-L113

  proto.withAudioQuality =
  proto.audioQuality = function(quality) {
    this._currentOutput.audio('-aq', quality);
    return this;
  };

Ideally you'd be able to test which encoder is being used? Something like:

  proto.withAudioCodec =
  proto.audioCodec = function(codec) {
    this._currentOutput.audio('-acodec', codec);
    this._currentOutput.acodec = codec;
    return this;
  };
  proto.withAudioQuality =
  proto.audioQuality = function(quality) {
    if(this._currentOutput.acodec === "libfdk_aac"){
      this._currentOutput.audio('-vbr', quality);
    }
    else{
      this._currentOutput.audio('-aq', quality);
    }    
    return this;
  };

But this might not work universally, because the way the API is set up, someone may set the encoder after the audioQuality is set, yeah?

I can submit a pull request if needed.

@arjunmehta

This comment has been minimized.

Copy link
Author

commented Dec 17, 2014

Sorry, I just realized that this is very specific, and there seems to be no consistency in how audio quality flags are implemented across various codecs!

Can use .outputOptions()!!

But I suppose it's important to note that -aq isn't a universal flag.

@arjunmehta arjunmehta closed this Dec 17, 2014

@arjunmehta arjunmehta reopened this Dec 17, 2014

@arjunmehta

This comment has been minimized.

Copy link
Author

commented Dec 17, 2014

Leaving this open for discussion. Feel free to close if it's not relevant. :)

@madcampos

This comment has been minimized.

Copy link

commented Dec 28, 2014

With a lack of better solution for now, you can check if the vbr flag is set and then change it if needed on the withAudioCodec function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.