日本語

Fixing Unknown encoder ‘libfdk_aac’ in FFmpeg

​​FFmpeg​AAC,audio,command line,Troubleshooting

If you specify -c:a libfdk_aac in FFmpeg and get "Unknown encoder 'libfdk_aac'", the FFmpeg you are running was not built with libfdk_aac. Changing it to -c:a aac lets FFmpeg convert using its built-in AAC encoder, and the error goes away. This error appears when you run a command that specifies libfdk_aac, such as converting a video's audio to AAC or a WAV file to m4a, on an FFmpeg build that does not include it.

Note

The test environment was Ubuntu 24.04.5 with FFmpeg 6.1.1 (Ubuntu package 7:6.1.1-3ubuntu5). The only audio used was a 10-second stereo 44.1kHz WAV generated with FFmpeg's sine filter. I did not test building FFmpeg yourself with fdk-aac, FFmpeg builds from other distributions (such as Windows or macOS builds), or comparisons of how the converted audio sounds or its quality.

The command that fails and the error it prints

For testing, I used a WAV file with 440Hz and 660Hz tones on the left and right channels.

bash
ffmpeg -y -f lavfi -i "sine=frequency=440:duration=10:sample_rate=44100" -f lavfi -i "sine=frequency=660:duration=10:sample_rate=44100" -filter_complex "[0:a][1:a]join=inputs=2:channel_layout=stereo" -c:a pcm_s16le in.wav

Next, I try to convert this WAV to a 128kbps m4a using libfdk_aac.

bash
ffmpeg -hide_banner -i in.wav -c:a libfdk_aac -b:a 128k out_fdk.m4a

The conversion did not start. After the input information, the following was printed and the command stopped (the 0x... values change with each run).

text
[aost#0:0 @ 0x563341c8bf00] Unknown encoder 'libfdk_aac'
[aost#0:0 @ 0x563341c8bf00] Error selecting an encoder
Error opening output file out_fdk.m4a.
Error opening output files: Encoder not found

The exit code was 8, and out_fdk.m4a was not created.

Cause: this FFmpeg does not include libfdk_aac

You can check which AAC encoders are available with the -encoders list.

bash
ffmpeg -hide_banner -encoders | grep -i aac
text
 A....D aac                  AAC (Advanced Audio Coding)

Only aac appeared, and there was no line containing fdk. When I tried to show the help with ffmpeg -h encoder=libfdk_aac, it printed "Codec 'libfdk_aac' is not recognized by FFmpeg."

libfdk_aac is an encoder that uses libfdk-aac (fdk-aac), a library outside FFmpeg based on the Fraunhofer FDK AAC code. The libfdk_aac section of the FFmpeg codecs documentation says that building FFmpeg requires --enable-libfdk-aac, and that because the library is incompatible with the GPL, if you enable GPL you must add --enable-gpl --enable-nonfree --enable-libfdk-aac.

You can check how the FFmpeg in the test environment was built with -buildconf.

bash
ffmpeg -hide_banner -buildconf | grep -Ei 'fdk|nonfree|enable-gpl'
text
    --enable-gpl

--enable-gpl is present, but --enable-nonfree and --enable-libfdk-aac are not. In the configure script of FFmpeg 6.1.1, libfdk_aac is in the list of nonfree libraries. In a build with GPL enabled, specifying --enable-libfdk-aac without --enable-nonfree causes configure to stop with an error. Also, the LICENSE.md in the FFmpeg source states that a build with --enable-nonfree is unredistributable. In other words, an FFmpeg build that includes libfdk_aac cannot be redistributed.

Fix: switch to -c:a aac

Change libfdk_aac to aac, the encoder built into FFmpeg. The aac section of the documentation describes it as the default AAC encoder implemented natively in FFmpeg.

bash
ffmpeg -hide_banner -i in.wav -c:a aac -b:a 128k out_aac.m4a

This time the conversion finished with exit code 0, and the output contained no "Unknown encoder" line. The stream information shown was as follows.

text
  Stream #0:0 -> #0:0 (pcm_s16le (native) -> aac (native))
  Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s

I checked the output with ffprobe: it was AAC-LC, 44.1kHz, stereo, 10 seconds long, and the bitrate was about 128kbps (127710 b/s).

bash
ffprobe -v error -show_entries stream=codec_name,profile,sample_rate,channels,bit_rate:format=duration -of compact=p=0 out_aac.m4a
text
codec_name=aac|profile=LC|sample_rate=44100|channels=2|bit_rate=127710
duration=10.000000

When the output file is .m4a, aac was selected even without -c:a. Running ffmpeg -i in.wav -b:a 128k out_default.m4a also showed pcm_s16le (native) -> aac (native).

Options for libfdk_aac do not work with aac

When you rewrite the command to use -c:a aac, also review any options you added for libfdk_aac.

libfdk_aac uses -vbr 4 to specify quality. I kept this option as-is with -c:a aac and ran the conversion. It did not cause an error, and the exit code was 0, but the following warning was printed.

text
[out#0/ipod @ 0x5591e2c2e640] Codec AVOption vbr (Variable bit rate mode) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.

The bitrate of the resulting file was 127710 b/s, the same as without -vbr. The file sizes were also identical, 162,544 bytes each. -vbr was not used, and the conversion ran at the default 128kbps of aac (the aac section of the documentation also says the default is 128kbps when -b:a is not specified). In the test environment, only libopus has -vbr (confirmed with ffmpeg -h full), and aac does not have it, so it is ignored.

With aac, specify the bitrate with -b:a. To specify quality instead, use -q:a, which is described in the aac section of the documentation. In the test environment, -c:a aac -q:a 2 produced a bitrate of about 349kbps (348537 b/s).

Warning

I also tested -profile:a aac_he added to -c:a aac to request HE-AAC. The conversion finished with exit code 0 and printed no warning. The display showed aac (HE-AAC), but the resulting file could not be read by the same FFmpeg 6.1.1. Both ffprobe and decoding with ffmpeg printed "Audio object type SBR+21 is not implemented.", and decoding stopped with exit code 218. When I removed -profile:a aac_he and used only -b:a 64k, the result was an AAC-LC file that could be decoded.

The profile values listed in the aac section of the documentation are aac_low (the default), mpeg2_aac_low, and aac_ltp. aac_he is not among them (the FFmpeg 6.1.1 documentation also lists aac_main). The libfdk_aac section, on the other hand, says it supports the HE-AAC profiles. If you need HE-AAC, you will need an FFmpeg built with libfdk_aac, rather than replacing it with aac. The FFmpeg documentation on external libraries says you must install the Fraunhofer AAC library and build with --enable-libfdk-aac, and that GPL builds also require --enable-nonfree.

​Posted by 86