Changing (reducing) the quality of an ogg file?

5,127

Solution 1

There are two excellent choices here:

  1. Adjust your FFmpeg command line to produce a smaller Ogg Vorbis file
  2. Use FFmpeg to create a small file using libopus

Details of both are below:

1. Adjust your FFmpeg command line...

The key issue is that FFmpeg will not automagically change the audio sampling rate to appropriately match your selected bitrate. But then FFmpeg usually does not do a lot of hand holding I guess!

Bear in mind that an Audio CD will normally have a sampling rate of 44100 Hz while simple telephony would normally have a sampling rate of slightly greater than 8000 Hz. So you have a choice to make for the best sampling rate for your 32k Ogg Vorbis audio. The following are some guidelines:

  • 44100 Hz: Typical Audio CD sample rate. Rejected by FFmpeg for a 32k file.
  • 32000 Hz: Adequate for speech and also adequate for other audio files where a smaller file size is required with an expected small loss of quality. Rejected by FFmpeg for a 32k file.
  • 22050 Hz: Adequate for speech and usable for other audio with the expectation that there will be audio quality loss. Accepted by FFmpeg for a 32k file.
  • 11025 Hz: Very poor sound quality. Accepted by FFmpeg for a 32k file.
  • 8000 Hz: Slightly lower sampling rate than a modern telephony system, not recommended for most recording tasks. Accepted by FFmpeg for a 32k file.

With this in mind my own testing suggests that you would be best to use a sampling rate of 22050 Hz, note that this should be perfectly adequate for speech, and thus your command line should be:

ffmpeg -i filename.ogg -c:a libvorbis -ab 32k -ar 22050 new-filename.ogg

And this produced a quite reasonable outcome on my own setup...

2. Use FFmpeg to create a small file using libopus...

If you are perhaps not all that set on using Ogg Vorbis an excellent alternative is to use Opus, which in my tests shaved a reasonable number of kilobytes off each file in comparison to the Ogg Vorbis 32k encode. Try something like the following which has been tailored for your speech files:

ffmpeg -i filename.ogg \
-c:a libopus -b:a 16k -ar 16000 -ac 1 -application voip \
new-filename.ogg

You will be pleasantly surprised by both the resulting output file size and audio quality. I have included a link to a great HydrogenAudio resource in the 'References' which should guide to an even better command line for Opus...

References:

  • Sample Rates: A nice page from the Audacity developers that demonstrates the best settings for audio sample rates.
  • Speech encoding quality: The definitive HydrogenAudio page to guide Opus settings for speech.

  • 15.8 libopus: FFmpeg options for use with libopus encoding. Note the -application voip setting that I used above and which does not have an equivalent with opusenc (unlike the other settings).

Solution 2

This low bitrate is not supported with the default sampling rate of the file. You must specify a lower sampling rate before you can lower the bitrate. Add the option -ar 8000 for your option -b:a 32k to be accepted.

Share:
5,127

Related videos on Youtube

sunyata
Author by

sunyata

Interested in Buddhism and software development. If you're reading this and is also interested in these things please contact me at tord.dellsen (at) gmail (dot) com, and maybe we can work on an open source Buddhist software project together?

Updated on September 18, 2022

Comments

  • sunyata
    sunyata almost 2 years

    I have an .ogg file (containing speech) with 192kbps quality that i'd like to reduce to 32kbps (to save space)

    How can i do this?


    So far i've tried this:

    ffmpeg -i filename.ogg -ab 32k -f ogg new-filename.ogg
    

    But i get this error:

    [libvorbis @ 0x56157365ab60] encoder setup failed
    Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
    Conversion failed!
    

    Am i using the wrong command? Is there a better approach i can take to save space? Please note that i only have access to the 192kbps file (not the original)

    Grateful for help!

    • vanadium
      vanadium over 5 years
      The error message indicates you have the encoding parameters wrong.
  • sunyata
    sunyata over 5 years
    Thank you! I ended up using opus like this: ffmpeg -i filename.ogg -c:a libopus -ar 16k -ac 1 -b:a 16k -vbr on -compression_level 10 new_filename.ogg
  • llogan
    llogan over 5 years
    @sunyata -compression_level 10 is the default for this encoder so you can remove that.
  • cregox
    cregox about 3 years
    i independently got to the same conclusion with opus... bitrate 16k is amazingly good and small (10%)! but i got an issue with album art... any idea how to get same compression using opusenc? or any other ideas for the simplest library reduction with this 10% in mind? superuser.com/questions/1648830/…