I am trying to use ffmpeg on a .mkv video to change soundtrack quality. I would like to lower the bitrate of the audio part (to 16 kbps) without any modification of the video. Nevertheless when I use the ffmpeg command

ffmpeg -i input.mkv -b:a 16k output.mkv

the sound is not changed and the video is compressed. I tried

ffmpeg -i input.mkv -ab 16k output.mkv

and had same problem. When I tried

ffmpeg -i input.mkv -ab 16k -acodec aac -strict experimental output.mkv

I got the error:

oggvorbis_encode_init: init_encoder failed

Any idea to solve the problem?

migrated from stackoverflow.com Jun 19 '13 at 1:37

This question came from our site for professional and enthusiast programmers.

  • Try extracting the audio stream with mkvextract first and working with it seperately. You can remux the new audio track and the original MKV file with mkvmerge. – Breakthrough Jun 19 '13 at 20:45

By default ffmpeg will re-encode any streams that have not been explicitly selected for stream copy mode, and the default video encoding bitrate (depending on the encoder) may be too low to provide an adequate output quality. Instead of re-encoding you can copy the video with -codec:v copy as an output option.

For such a low audio bitrate I recommend using an AAC encoder that supports HE-AAC. This example is adapted from the FFmpeg and AAC Encoding Guide and will use approximately 16kb/s per channel for a stereo output:

ffmpeg -i input.mkv -codec:v copy -codec:a libfdk_aac -profile:a aac_he_v2 -b:a 32k output.mkv

Depending on what the content of your input audio is such a low bitrate will probably not sound that great even with this encoder. Note that HE-AACv2 may not be supported by your targeted decoder(s), and you will probably have to compile ffmpeg for libfdk_aac support.

Opus audio would be another good format, but last time I checked the specifications for Opus in Matroska container have not yet been finalized; although through hearsay I think progress is being made.

  • fdk_aac is about as good as you're going to get (opus might get better results, but as LordNeckbeard noted there are currently MKV compatibility issues), but note that this will still give pretty poor quality -- listenable (especially if it's just recorded speech, like a lecture), but I wouldn't want to sit through an entire movie with this quality of sound. – evilsoup Jun 19 '13 at 6:59
  • @evilsoup Good to mention. I added a note to the answer. – llogan Jun 19 '13 at 20:37
  • Thanks for answering but when I launch the proposed CLI, I get the following error: [matroska @ 0x26f8380] Application provided invalid, non monotonically increasing dts to muxer in stream 0: -80 >= -80 av_interleaved_write_frame(): Invalid argument If I try to work with .mp4 files, the error doesn't occur, but I would like to work only with .mkv files. Any ideas to solve it? – MarAja Jun 26 '13 at 8:16
  • @MarAja use the most recent build available, or compile ffmpeg, and try again. If it still occurs please post a question on Super User (make sure to include your ffmpeg command and the complete console output if you do post a question). See the FFmpeg Download page for builds for Linux, Windows, and OS X, or refer to a ffmpeg compile guide. – llogan Jun 28 '13 at 22:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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