[PATCH] Make theoraenc expose the new "Speed level" property

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Make theoraenc expose the new "Speed level" property

Benjamin Schwartz
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The attached patch exposes the Speed Level property, new in the Theora 1.0
series, in theoraenc as "speed-level".  This property, if set to a value
of 2, accelerates encoding by disabling motion vectors entirely.

The attached patch is tested to enable control of the speed-level property
in theoraenc.  This patch does not break backwards compatibility, nor does
it change default behaviors.  (The speed-level knob will simply have no
effect on old versions of libtheora.)

My motivation, which is entirely irrelevant, is to encode video in real
time on the XO, especially for video chat.  In my completely arbitrary
test, I observed an 18% speedup at fixed quality, at a cost of 25%
increased bitrate.  (Frankly, I was hoping for a much larger speedup, but
never mind.)

- --Ben
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkmbn9EACgkQUJT6e6HFtqRtbQCdGFzXNU2gC0Q3MqygrXlh3fVA
02YAn3x/zOGTUBBXXPDEfHHPONXaTGPW
=sii4
-----END PGP SIGNATURE-----

diff --git a/ext/theora/gsttheoraenc.h b/ext/theora/gsttheoraenc.h
index 1cc4308..cad5496 100644
--- a/ext/theora/gsttheoraenc.h
+++ b/ext/theora/gsttheoraenc.h
@@ -104,6 +104,8 @@ struct _GstTheoraEnc
   guint64 granulepos_offset;
   guint64 timestamp_offset;
   gint granule_shift;  
+
+  gint speed_level;
 };
 
 struct _GstTheoraEncClass
diff --git a/ext/theora/theoraenc.c b/ext/theora/theoraenc.c
index 21d9d76..689df98 100644
--- a/ext/theora/theoraenc.c
+++ b/ext/theora/theoraenc.c
@@ -119,6 +119,7 @@ _ilog (unsigned int v)
 #define THEORA_DEF_KEYFRAME_MINDISTANCE 8
 #define THEORA_DEF_NOISE_SENSITIVITY    1
 #define THEORA_DEF_SHARPNESS            0
+#define THEORA_DEF_SPEEDLEVEL           1
 enum
 {
   ARG_0,
@@ -134,6 +135,7 @@ enum
   ARG_KEYFRAME_MINDISTANCE,
   ARG_NOISE_SENSITIVITY,
   ARG_SHARPNESS,
+  ARG_SPEEDLEVEL,
   /* FILL ME */
 };
 
@@ -265,6 +267,10 @@ gst_theora_enc_class_init (GstTheoraEncClass * klass)
       g_param_spec_int ("sharpness", "Sharpness", "Sharpness", 0, 2,
           THEORA_DEF_SHARPNESS,
           (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (gobject_class, ARG_SPEEDLEVEL,
+      g_param_spec_int ("speed-level", "Speed level", "Speed level", 0, 2,
+          THEORA_DEF_SPEEDLEVEL,
+          (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   gstelement_class->change_state = theora_enc_change_state;
   GST_DEBUG_CATEGORY_INIT (theoraenc_debug, "theoraenc", 0, "Theora encoder");
@@ -307,6 +313,8 @@ gst_theora_enc_init (GstTheoraEnc * enc, GstTheoraEncClass * g_class)
       "keyframe_frequency_force is %d, granule shift is %d",
       enc->info.keyframe_frequency_force, enc->granule_shift);
   enc->expected_ts = GST_CLOCK_TIME_NONE;
+  
+  enc->speed_level = THEORA_DEF_SPEEDLEVEL;
 }
 
 static void
@@ -327,6 +335,7 @@ theora_enc_reset (GstTheoraEnc * enc)
 {
   theora_clear (&enc->state);
   theora_encode_init (&enc->state, &enc->info);
+  theora_control(&enc->state, TH_ENCCTL_SET_SPLEVEL, &enc->speed_level, sizeof(enc->speed_level));
 }
 
 static void
@@ -1101,6 +1110,9 @@ theora_enc_set_property (GObject * object, guint prop_id,
     case ARG_SHARPNESS:
       enc->sharpness = g_value_get_int (value);
       break;
+    case ARG_SPEEDLEVEL:
+      enc->speed_level = g_value_get_int (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1150,6 +1162,9 @@ theora_enc_get_property (GObject * object, guint prop_id,
     case ARG_SHARPNESS:
       g_value_set_int (value, enc->sharpness);
       break;
+    case ARG_SPEEDLEVEL:
+      g_value_set_int (value, enc->speed_level);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Make theoraenc expose the new "Speed level" property

Sebastian Dröge-7
Am Mittwoch, den 18.02.2009, 00:42 -0500 schrieb Benjamin M. Schwartz:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> The attached patch exposes the Speed Level property, new in the Theora 1.0
> series, in theoraenc as "speed-level".  This property, if set to a value
> of 2, accelerates encoding by disabling motion vectors entirely.
>
> The attached patch is tested to enable control of the speed-level property
> in theoraenc.  This patch does not break backwards compatibility, nor does
> it change default behaviors.  (The speed-level knob will simply have no
> effect on old versions of libtheora.)
>
> My motivation, which is entirely irrelevant, is to encode video in real
> time on the XO, especially for video chat.  In my completely arbitrary
> test, I observed an 18% speedup at fixed quality, at a cost of 25%
> increased bitrate.  (Frankly, I was hoping for a much larger speedup, but
> never mind.)
Please file a bug at bugzilla.gnome.org with this patch. To be accepted
the speed-level property needs to be enabled conditionally, depending on
the theora version that is used for compilation.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Make theoraenc expose the new "Speed level" property

Donny Viszneki
In reply to this post by Benjamin Schwartz
On Wed, Feb 18, 2009 at 12:42 AM, Benjamin M. Schwartz
<[hidden email]> wrote:
> The attached patch exposes the Speed Level property, new in the Theora 1.0
> series, in theoraenc as "speed-level".  This property, if set to a value
> of 2, accelerates encoding by disabling motion vectors entirely.
>
> My motivation, which is entirely irrelevant, is to encode video in real
> time on the XO, especially for video chat.  In my completely arbitrary
> test, I observed an 18% speedup at fixed quality, at a cost of 25%
> increased bitrate.  (Frankly, I was hoping for a much larger speedup, but
> never mind.)

Perhaps not /entirely/ irrelevant.

Do you think disabling motion vector calculation has a different
effect on performance depending on what the video is like?

--
http://codebad.com/

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Make theoraenc expose the new "Speed level" property

Benjamin Schwartz
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Donny Viszneki wrote:
> Do you think disabling motion vector calculation has a different
> effect on performance depending on what the video is like?

I'm no expert, but here are two ideas:

1. At fixed quality, removing the motion vectors makes the codec less
efficient if the scene has motion.  My test did (some youtube music
video), and so, at fixed nominal quality, the bitrate increased by 25%.
That increase in bitrate means more bits to push into memory, which slows
things down.  Non-moving scenes should not experience an increased
bitrate, and so potentially may be accelerated better.

2. The motion-vector search can be implemented many ways.  A naive search
(I hear libtheora-1.0 has a fairly naive implementation) takes a similar
amount of time regardless of the underlying scene.  A very advanced search
(I hear libtheora-1.1 will have a fancier motion search) might quickly
detect the lack of motion and stop searching.  In any case, with
speedlevel=2 no search will be performed, and the speed gain depends on
how much time that search would have taken.

- --Ben
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkmceWoACgkQUJT6e6HFtqR3EgCdFKEO7YL5B2e6POWIiI9eRAn2
SqQAn2a94W17KYyOskoiL8tY5Nh+vbVK
=1QEJ
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Make theoraenc expose the new "Speed level" property

Benjamin Schwartz
In reply to this post by Sebastian Dröge-7
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sebastian Dröge wrote:
> Please file a bug at bugzilla.gnome.org with this patch. To be accepted
> the speed-level property needs to be enabled conditionally, depending on
> the theora version that is used for compilation.

Done: http://bugzilla.gnome.org/show_bug.cgi?id=572275

- --Ben
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkmcebgACgkQUJT6e6HFtqRmLACfarPhVb9BOFby/yOd8gEjCh7M
DZwAn1HVSGMfGp8a7bQD+CHH99oWQqEd
=pXbO
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Make theoraenc expose the new "Speed level" property

Donny Viszneki
In reply to this post by Benjamin Schwartz
On Wed, Feb 18, 2009 at 4:11 PM, Benjamin M. Schwartz
<[hidden email]> wrote:

> 1. At fixed quality, removing the motion vectors makes the codec less
> efficient if the scene has motion.  My test did (some youtube music
> video), and so, at fixed nominal quality, the bitrate increased by 25%.
> That increase in bitrate means more bits to push into memory, which slows
> things down.  Non-moving scenes should not experience an increased
> bitrate, and so potentially may be accelerated better.
>
> 2. The motion-vector search can be implemented many ways.  A naive search
> (I hear libtheora-1.0 has a fairly naive implementation) takes a similar
> amount of time regardless of the underlying scene.  A very advanced search
> (I hear libtheora-1.1 will have a fancier motion search) might quickly
> detect the lack of motion and stop searching.  In any case, with
> speedlevel=2 no search will be performed, and the speed gain depends on
> how much time that search would have taken.

Instead of a music video, try something more typical of what a webcam
captures when people are sitting in front of their webcam: a
relatively static background, and someone in front of the camera
talking. I'd be very interested to see how this affects the results
with libtheora 1.1

--
http://codebad.com/

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel