5

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?

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.
  • :D I actually looked at the man page twice, but I didn't see this. Thanks! – Zelphir Kaltstahl Nov 11 '14 at 20:31
  • So it would be ? avconv -i (input file) -f flac -compression_level 2 (output file path) – userDepth Oct 14 '17 at 23:29
  • @userDepth Yep. – v010dya Oct 15 '17 at 19:12
10

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:

  • 1
    Man, that man page is long! Easier to find the compression_level info here! ffmpeg.org/ffmpeg-codecs.html – Ahi Tuna Oct 14 '17 at 21:07
  • 1
    @MisoSoup Good point, I have added these details into the answer as well as reorganised... – andrew.46 Oct 14 '17 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.