How to specify flac compression level when converting with avconv?

14,448

Solution 1

There is a -compression_level attribute. Man page gives its format as

-compression_level[:stream_specifier] integer (output,audio,video)

You will likely not need to specify the stream, since you have only a single one in the file, so -compression_level 2 is your friend.

In the future you may want to check man page for the tools.

  1. Open the terminal.
  2. Type man (name of program). For example man avconv.
  3. To search the manual, press '/' and enter the string to search for. In this case i've done '/compression', this was the second thing that was found.

Solution 2

The option is -compression_level and can be set with either avconv or FFmpeg:

ffmpeg -i input.wav -c:a flac -compression_level 12 output.flac

Interestingly enough the commandline flac encoder offers compression levels of 0-8 but FFmpeg / avconv offers 0-12. The documentation can be seen in 3 places:

1. Source code:

The options for flac compression can be seen in flacenc.c:

/* set compression option defaults based on avctx->compression_level */
if (avctx->compression_level < 0)         <-------------
    s->options.compression_level = 5;     <-------------
else
    s->options.compression_level = avctx->compression_level;

level = s->options.compression_level;
if (level > 12) {                         <-------------
    av_log(avctx, AV_LOG_ERROR, "invalid compression level: %d\n",
           s->options.compression_level);
    return AVERROR(EINVAL);
}

I have 'arrowed' in the relevant sections!

2. Man pages:

The compression options can also be seen in man ffmpeg-all rather than man ffmpeg :). This man page shows:

compression_level
Sets the compression level, which chooses defaults for many other options
if they are not set explicitly. Valid values are from 0 to 12, 5 is the default.

A little confusing with multiple man pages now available for FFmpeg!

3. Online documentation:

As 'Miso Soup' pointed out there is also some documentation available online for the deeper options of flac encoding, including the compression options:

compression_level
Sets the compression level, which chooses defaults for many
other options if they are not set explicitly. Valid values
are from 0 to 12, 5 is the default.

Same as the man pages but perhaps a little easier for some to find and read!

References:

Share:
14,448

Related videos on Youtube

Zelphir Kaltstahl
Author by

Zelphir Kaltstahl

Full Stack Software Developer

Updated on September 18, 2022

Comments

  • Zelphir Kaltstahl
    Zelphir Kaltstahl almost 2 years

    I am trying to convert some aac files to flac files, because aac is not supported by another device I use. After some multiple attempts to find a solution, searching the Internet, I finally read that ffmpeg was replaced with avconv and that avconv is a fork of ffmpeg. So I searched for how to convert to flac using avconv and found this line:

    avconv -i (input file) -f flac (output file path)
    

    This works well, however, I don't see any flac compression level in that command and I need to have a compression level of 2 or lower, because of cpu resources on the target device. I checked the man-page for avconv, but it doesn't seem to mention flac compression levels at all.

    So my question is: How do I specify the flac compression level when converting from any input format to flac using avconv?

  • Zelphir Kaltstahl
    Zelphir Kaltstahl over 9 years
    :D I actually looked at the man page twice, but I didn't see this. Thanks!
  • Ahi Tuna
    Ahi Tuna over 6 years
    Man, that man page is long! Easier to find the compression_level info here! ffmpeg.org/ffmpeg-codecs.html
  • andrew.46
    andrew.46 over 6 years
    @MisoSoup Good point, I have added these details into the answer as well as reorganised...
  • userDepth
    userDepth over 6 years
    So it would be ? avconv -i (input file) -f flac -compression_level 2 (output file path)
  • v010dya
    v010dya over 6 years
    @userDepth Yep.