vp8enc patch for camerabin2



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


- -- 
Regards,
Alexey
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8pTdUACgkQw8E0jNwoJm+2NQCgt6AmLRKCDIfoCH87ff/D70j6
KzgAnA0azMhdOhjvnWJcCF0nDFydY/4g
=hOal
-----END PGP SIGNATURE-----
From 666bfa2f1e50f19e63e1bbcc03764e1de65f589b Mon Sep 17 00:00:00 2001
From: "Oleksij Rempel (Alexey Fisher)" <bug-track fisher-privat net>
Date: Fri, 23 Dec 2011 10:10:20 +0100
Subject: [PATCH] cheese(camerabin2): encode webm/vp8 instead of ogg/theora

create webm profile and use it with camereabin2. Also use presets for
vp8enc.

Signed-off-by: Oleksij Rempel (Alexey Fisher) <bug-track fisher-privat net>
---
 configure.ac                |    2 +-
 libcheese/cheese-camera.c   |   79 ++++++++++++++++++++++++++++++------------
 libcheese/cheese-fileutil.h |    2 +-
 3 files changed, 58 insertions(+), 25 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2af1ae4..6614e23 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,7 +65,7 @@ GDK_REQUIRED="gdk-3.0 >= 2.99.4"
 GDK_PIXBUF_REQUIRED="gdk-pixbuf-2.0"
 LIBGNOMEDESKTOP_REQUIRED="gnome-desktop-3.0 >= 2.91.6"
 GSTREAMER_VERSION=0.10.32
-GSTREAMER_REQUIRED="gstreamer-plugins-base-0.10 >= $GSTREAMER_VERSION gstreamer-0.10 >= $GSTREAMER_VERSION"
+GSTREAMER_REQUIRED="gstreamer-plugins-base-0.10 >= $GSTREAMER_VERSION gstreamer-0.10 >= $GSTREAMER_VERSION gstreamer-pbutils-0.10 >= $GSTREAMER_VERSION"
 GSTREAMER_PLUGINS_BAD_VERSION=0.10.22
 GSTREAMER_PLUGINS_BAD_REQUIRED="gstreamer-plugins-bad-0.10 >= $GSTREAMER_PLUGINS_BAD_VERSION"
 CAIRO_REQUIRED="cairo >= 1.10.0"
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index ca527a8..16b96ca 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -32,12 +32,17 @@
 #include <clutter-gst/clutter-gst.h>
 #include <gst/gst.h>
 #include <gst/basecamerabinsrc/gstcamerabin-enum.h>
+/* depends on gstreamer-pbutils-0.10 */
+#include <gst/pbutils/encoding-profile.h>
 #include <X11/Xlib.h>
 
 #include "cheese-camera.h"
 #include "cheese-camera-device.h"
 #include "cheese-camera-device-monitor.h"
 
+#define CHEESE_VIDEO_ENC_PRESET "Profile Realtime"
+#define CHEESE_VIDEO_ENC_ALT_PRESET "Cheese Realtime"
+
 /**
  * SECTION:cheese-camera
  * @short_description: A representation of the video capture device inside
@@ -473,35 +478,63 @@ cheese_camera_set_error_element_not_found (GError **error, const gchar *factoryn
  * cheese_camera_set_video_recording:
  * @camera: a #CheeseCamera
  * @error: a return location for errors, or %NULL
- *
- * Sets up the video encoder explicitly, in order to be able to control
- * properties such as encoding quality.
  */
 static void
 cheese_camera_set_video_recording (CheeseCamera *camera, GError **error)
 {
-  GstElement          *video_enc;
-  GstElement          *mux;
-
-  if ((video_enc = gst_element_factory_make ("theoraenc", "theoraenc")) == NULL)
-  {
-    cheese_camera_set_error_element_not_found (error, "theoraenc");
-    return;
+  CheeseCameraPrivate *priv   = CHEESE_CAMERA_GET_PRIVATE (camera);
+  GstEncodingContainerProfile *prof;
+  GstEncodingVideoProfile *v_prof;
+  GstCaps *caps;
+  GstElement *video_enc;
+  const gchar *video_preset;
+  gboolean res;
+
+  /* Check if we can use global preset for vp8enc. */
+  video_enc = gst_element_factory_make ("vp8enc", "vp8enc");
+  video_preset = (gchar *) &CHEESE_VIDEO_ENC_PRESET;
+  res = gst_preset_load_preset (GST_PRESET (video_enc), video_preset);
+  if (res == FALSE) {
+    g_warning("Can't find vp8enc preset: \"%s\", using alternate preset:"
+        " \"%s\". If you see this, make a bug report!",
+        video_preset, CHEESE_VIDEO_ENC_ALT_PRESET);
+
+    /* If global preset not found, then probably we use wrong preset name,
+     * or old gstreamer version. In any case, we should try to control
+     * keep poker face and not fail. DON'T FORGET TO MAKE A BUG REPORT!*/
+    video_preset = (gchar *) &CHEESE_VIDEO_ENC_ALT_PRESET;
+    res = gst_preset_load_preset (GST_PRESET (video_enc), video_preset);
+    if (res == FALSE) {
+      g_warning ("Can't find vp8enc preset: \"%s\", "
+          "creating new userspace preset.", video_preset);
+
+      /* Seems like we do first run and userspace preset do not exist.
+       * Let us create a new one. It will be probably located some where here:
+       * ~/.gstreamer-0.10/presets/GstVP8Enc.prs */
+      g_object_set (G_OBJECT (video_enc), "speed", 2, NULL);
+      g_object_set (G_OBJECT (video_enc), "max-latency", 1, NULL);
+      gst_preset_save_preset (GST_PRESET (video_enc), video_preset);
+    }
   }
-  //raluca:TODO: camerabin2 does not have 'video-encoder'
-  //g_object_set (priv->camerabin, "video-encoder", video_enc, NULL);
-  g_object_set (G_OBJECT (video_enc), "speed-level", 2, NULL);
+  gst_object_unref(video_enc);
 
-  if ((mux = gst_element_factory_make ("oggmux", "oggmux")) == NULL)
-  {
-    cheese_camera_set_error_element_not_found (error, "oggmux");
-    return;
-  }
-  //raluca:TODO: camerabin2 does not have 'video-muxer'
-  //g_object_set (priv->camerabin, "video-muxer", mux, NULL);
-  g_object_set (G_OBJECT (mux),
-                "max-delay", (guint64) 10000000,
-                "max-page-delay", (guint64) 10000000, NULL);
+  /* create profile for webm encoding */
+  caps = gst_caps_from_string("video/webm");
+  prof = gst_encoding_container_profile_new("WebM audio/video",
+      "Standard WebM/VP8/Vorbis",
+      caps, NULL);
+
+  caps = gst_caps_from_string("video/x-vp8");
+  v_prof = gst_encoding_video_profile_new(caps, NULL, NULL, 0);
+  gst_encoding_video_profile_set_variableframerate(v_prof, TRUE);
+  gst_encoding_profile_set_preset((GstEncodingProfile*) v_prof, video_preset);
+  gst_encoding_container_profile_add_profile(prof, (GstEncodingProfile*) v_prof);
+
+  caps = gst_caps_from_string("audio/x-vorbis");
+  gst_encoding_container_profile_add_profile(prof,
+      (GstEncodingProfile*) gst_encoding_audio_profile_new(caps, NULL, NULL, 0));
+
+  g_object_set (priv->camerabin, "video-profile", prof, NULL);
 }
 
 /*
diff --git a/libcheese/cheese-fileutil.h b/libcheese/cheese-fileutil.h
index 21b9eec..a470427 100644
--- a/libcheese/cheese-fileutil.h
+++ b/libcheese/cheese-fileutil.h
@@ -36,7 +36,7 @@
  *
  * The filename suffix for videos saved by Cheese.
  */
-#define CHEESE_VIDEO_NAME_SUFFIX ".ogv"
+#define CHEESE_VIDEO_NAME_SUFFIX ".webm"
 
 G_BEGIN_DECLS
 
-- 
1.7.5.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]