[FFmpeg-devel] [PATCH] libtheoraenc.c

j f gonzaz-z
Tue Jun 30 13:40:08 CEST 2009


Hello,

This patch enable quality bitrate management (VBR) in libtheora
(maped to the "qscale" option, arg value={0-10})
it also allows the end-user to tune some options of the Theora
codec like setting a :
-speed level, this option is maped to the "hurry_up" option, arg
value={0 | 1 | 2}
-threshold for the keyframe autodetection feature, maped to the
"sc_threshold" option, arg value={0-100}
-noise reduction level, maped to the "nr" option, arg value={0-6}


Index: libavcodec/libtheoraenc.c
===================================================================
--- libavcodec/libtheoraenc.c (revision 19285)
+++ libavcodec/libtheoraenc.c (working copy)
@@ -47,7 +47,7 @@
*/
static int concatenate_packet(unsigned int* offset,
AVCodecContext* avc_context, const ogg_packet* packet)
{
- char* message = NULL;
+ const char* message = NULL;
uint8_t* newdata = NULL;
int newsize = avc_context->extradata_size + 2 + packet->bytes;

@@ -83,6 +83,7 @@
theora_comment t_comment;
ogg_packet o_packet;
unsigned int offset;
+ int speed_level = av_clip (avc_context->hurry_up, 0, 2);
TheoraContext *h = avc_context->priv_data;

/* Set up the theora_info struct */
@@ -106,18 +107,47 @@
}
t_info.colorspace = OC_CS_UNSPECIFIED;
t_info.pixelformat = OC_PF_420;
- t_info.target_bitrate = avc_context->bit_rate;
+
+ if (avc_context->flags & CODEC_FLAG_QSCALE){ //enable VBR and disable
CBR
+
+ /*to be consitent with the libvorbis implementation, clip
global_quality to 0 - 10
+ Theora accepts a quality parameter p, which is:
+ * 0 <= p <=63
+ * an int value
+ */
+ t_info.quality = (int)(av_clip( (int)(
avc_context->global_quality / (float)FF_QP2LAMBDA ) ,0 ,10 ) * 6.3);
+ t_info.target_bitrate = 0;
+
+ } else {//enable CBR and disable VBR
+ t_info.target_bitrate = avc_context->bit_rate;
+ t_info.quality = 0;
+ }
+
t_info.keyframe_frequency = avc_context->gop_size;
t_info.keyframe_frequency_force = avc_context->gop_size;
t_info.keyframe_mindistance = avc_context->keyint_min;
- t_info.quality = 0;

t_info.quick_p = 1;
t_info.dropframes_p = 0;
- t_info.keyframe_auto_p = 1;
+
+ /* if sc_threshold != 0 then activate auto insertion of keyframe
+ and clip its value to 1 - 100, a small value forces Theora to
insert more keyframes
+ */
+ if (avc_context->scenechange_threshold) {
+ t_info.keyframe_auto_p = 1;
+ t_info.keyframe_auto_threshold = av_clip(
avc_context->scenechange_threshold, 1, 100);
+ } else {
+ //default values
+ t_info.keyframe_auto_p = 0;
+ t_info.keyframe_auto_threshold = 80;
+ }
+
t_info.keyframe_data_target_bitrate = t_info.target_bitrate * 1.5;
- t_info.keyframe_auto_threshold = 80;
- t_info.noise_sensitivity = 1;
+
+ if (avc_context->noise_reduction) {
+ t_info.noise_sensitivity =
av_clip(avc_context->noise_reduction, 0, 6);
+ }
+
t_info.sharpness = 0;

/* Now initialise libtheora */
@@ -126,6 +156,9 @@
return -1;
}

+ /* Additional encoder configuration, set speed_level according
to the value of hurry_up */
+ theora_control( &(h->t_state), TH_ENCCTL_SET_SPLEVEL,
&speed_level, sizeof(int));
+
/* Clear up theora_info struct */
theora_info_clear( &t_info );

--
j f

-- 
_______________________________________________
Surf the Web in a faster, safer and easier way:
Download Opera 9 at http://www.opera.com

Powered by Outblaze
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libtheoraenc.c.diff
Type: application/octet-stream
Size: 2929 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090630/cb43203a/attachment.obj>



More information about the ffmpeg-devel mailing list