libvorbisenc documentation

libvorbisenc version 1.3.2 - 20101101

Libvorbisenc Setup Examples

VBR is always the recommended mode for Vorbis encoding when there's no need to impose bitrate constraints. True VBR encoding will always produce the most consistent quality output as well as the highest quality for a the bits used.

The following code examples prepare a vorbis_info structure for encoding use with libvorbis.

Example: encoding using a VBR quality mode

 
   vorbis_info_init(&vi);

  /*********************************************************************
   Encoding using a VBR quality mode.  The usable range is -.1
   (lowest quality, smallest file) to 1.0 (highest quality, largest file).
   Example quality mode .4: 44kHz stereo coupled, roughly 128kbps VBR 
   *********************************************************************/
  
   ret = vorbis_encode_init_vbr(&vi,2,44100,.4);

  /*********************************************************************
   do not continue if setup failed; this can happen if we ask for a
   mode that libVorbis does not support (eg, too low a quality mode, etc,
   will return 'OV_EIMPL')
   *********************************************************************/

   if(ret) exit(1);

Example: encoding using average bitrate (ABR)

 
   vorbis_info_init(&vi);

  /*********************************************************************
   Encoding using an average bitrate mode (ABR).
   example: 44kHz stereo coupled, average 128kbps ABR 
   *********************************************************************/
  
   ret = vorbis_encode_init(&vi,2,44100,-1,128000,-1);

  /*********************************************************************
   do not continue if setup failed; this can happen if we ask for a
   mode that libVorbis does not support (eg, too low a bitrate, etc,
   will return 'OV_EIMPL')
   *********************************************************************/

   if(ret) exit(1);

Example: encoding using constant bitrate (CBR)

 
   vorbis_info_init(&vi);

  /*********************************************************************
   Encoding using a constant bitrate mode (CBR).
   example: 44kHz stereo coupled, average 128kbps CBR 
   *********************************************************************/
  
   ret = vorbis_encode_init(&vi,2,44100,128000,128000,128000);

  /*********************************************************************
   do not continue if setup failed; this can happen if we ask for a
   mode that libVorbis does not support (eg, too low a bitrate, etc,
   will return 'OV_EIMPL')
   *********************************************************************/

   if(ret) exit(1);

Example: encoding using VBR selected by approximate bitrate

 
   vorbis_info_init(&vi);

  /*********************************************************************
   Encode using a quality mode, but select that quality mode by asking for
   an approximate bitrate.  This is not ABR, it is true VBR, but selected
   using the bitrate interface, and then turning bitrate management off:
   *********************************************************************/

   ret = ( vorbis_encode_setup_managed(&vi,2,44100,-1,128000,-1) ||
           vorbis_encode_ctl(&vi,OV_ECTL_RATEMANAGE2_SET,NULL) ||
           vorbis_encode_setup_init(&vi));

  /*********************************************************************
   do not continue if setup failed; this can happen if we ask for a
   mode that libVorbis does not support (eg, too low a bitrate, etc,
   will return 'OV_EIMPL')
   *********************************************************************/

   if(ret) exit(1);



copyright © 2000-2010 Xiph.Org

Ogg Vorbis

libvorbisenc documentation

libvorbisenc version 1.3.2 - 20101101