[theora] Theora 1.1 rate controller

Thomas de Buman tdbuman at gmail.com
Tue Jul 14 01:13:47 PDT 2009


The above-mentioned bitrate values were measured using Theora 1.0 at VGA
(640x480) resolution.

Concerning the implementation of the Theora encoder into Ekiga, it is
accessed via the underlying Opal library. This library is the basis of any
call management in Ekiga and supports different encoders via plugin
integration. Below, you will find the major steps involved in adjusting the
encoder options in the Theora plugin. The whole Opal package can is
downloadable from https://sourceforge.net/projects/opalvoip/files/.

1) The initialisation of the parameters:

theoraEncoderContext::theoraEncoderContext()
{
  ogg_packet headerPacket, tablePacket;
  _frameCounter=0;

  _txTheoraFrame = new theoraFrame();
  _txTheoraFrame->SetMaxPayloadSize(THEORA_PAYLOAD_SIZE);

  theora_info_init( &_theoraInfo );
  _theoraInfo.frame_width        = 352;  // Must be multiple of 16
  _theoraInfo.frame_height       = 288; // Must be multiple of 16
  _theoraInfo.width              = _theoraInfo.frame_width;
  _theoraInfo.height             = _theoraInfo.frame_height;
  _theoraInfo.offset_x           = 0;
  _theoraInfo.offset_y           = 0;
  _theoraInfo.fps_numerator      = THEORA_FRAME_RATE;
  _theoraInfo.fps_denominator    = 1;
  _theoraInfo.aspect_numerator   = _theoraInfo.width;  // Aspect =
width/height
  _theoraInfo.aspect_denominator = _theoraInfo.height; //
  _theoraInfo.colorspace         = OC_CS_UNSPECIFIED;
  _theoraInfo.target_bitrate     = THEORA_BITRATE * 2 / 3; // Anywhere
between 45kbps and 2000kbps
  _theoraInfo.quality            = 16;
  _theoraInfo.dropframes_p                 = 0;
  _theoraInfo.quick_p                      = 1;
  _theoraInfo.keyframe_auto_p              = 1;
  _theoraInfo.keyframe_frequency = THEORA_KEY_FRAME_INTERVAL;
  _theoraInfo.keyframe_frequency_force     = _theoraInfo.keyframe_frequency;
  _theoraInfo.keyframe_data_target_bitrate = THEORA_BITRATE;
  _theoraInfo.keyframe_auto_threshold      = 80;
  _theoraInfo.keyframe_mindistance         = 8;
  _theoraInfo.noise_sensitivity            = 1;

  theora_encode_init( &_theoraState, &_theoraInfo );

  theora_encode_header( &_theoraState, &headerPacket );
  _txTheoraFrame->SetFromHeaderConfig(&headerPacket);

  theora_encode_tables( &_theoraState, &tablePacket );
  _txTheoraFrame->SetFromTableConfig(&tablePacket);
}

2) The only theoraInfo parameters that are updated "on-the-fly" during a RTP
video session are the "target_bitrate" and "keyframe_data_target_bitrate"
parameters:

void theoraEncoderContext::SetTargetBitrate(unsigned rate)
{
    _theoraInfo.target_bitrate     = rate * 2 / 3; // Anywhere between
45kbps and 2000kbps}
    _theoraInfo.keyframe_data_target_bitrate = rate;
}

3) The changes are then applied by calling:

void theoraEncoderContext::ApplyOptions()
{
  ogg_packet headerPacket, tablePacket;

  theora_clear( &_theoraState );
  theora_encode_init( &_theoraState, &_theoraInfo );

  theora_encode_header( &_theoraState, &headerPacket );
  _txTheoraFrame->SetFromHeaderConfig(&headerPacket);

  theora_encode_tables( &_theoraState, &tablePacket );
  _txTheoraFrame->SetFromTableConfig(&tablePacket);
}

4) The major function calls for encoding the frames are then:

theora_encode_YUVin( &_theoraState, &yuv );
followed by
theora_encode_packetout( &_theoraState, 0 /* not last Packet */,
&framePacket );

I hope this could help to find possible problems,
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/theora/attachments/20090714/04e7870d/attachment-0001.htm 


More information about the theora mailing list