How to specify flac compression level when converting with avconv?
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?
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:
- FFmpeg git: flacenc.c
- FFmpeg codecs documentation: flac
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.
- Open the terminal.
- Type
man (name of program)
. For exampleman avconv
. - 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.