1From a7fabf2b02ae99611d2c06ab85fc0f0c6275a9bf Mon Sep 17 00:00:00 2001
2From: Jiajian Wu <jair.wu@rock-chips.com>
3Date: Tue, 11 Jul 2023 16:10:23 +0800
4Subject: [PATCH] camera: use H264 encoder and matroska muxer
5
6Signed-off-by: Jiajian Wu <jair.wu@rock-chips.com>
7---
8 libcheese/cheese-camera.c   | 25 ++++++++++++++++---------
9 libcheese/cheese-fileutil.h |  2 +-
10 2 files changed, 17 insertions(+), 10 deletions(-)
11
12diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
13index 2185892b..0201898a 100644
14--- a/libcheese/cheese-camera.c
15+++ b/libcheese/cheese-camera.c
16@@ -441,12 +441,12 @@ cheese_camera_set_video_recording (CheeseCamera *camera, GError **error)
17   const gchar *video_preset;
18   gboolean res;
19
20-  /* Check if we can use global preset for vp8enc. */
21-  video_enc = gst_element_factory_make ("mppvp8enc", "vp8enc");
22+  /* Check if we can use global preset for h264enc. */
23+  video_enc = gst_element_factory_make ("mpph264enc", "videnc");
24   video_preset = (gchar *) &CHEESE_VIDEO_ENC_PRESET;
25   res = gst_preset_load_preset (GST_PRESET (video_enc), video_preset);
26   if (res == FALSE) {
27-    g_warning("Can't find vp8enc preset: \"%s\", using alternate preset:"
28+    g_warning("Can't find h264enc preset: \"%s\", using alternate preset:"
29         " \"%s\". If you see this, make a bug report!",
30         video_preset, CHEESE_VIDEO_ENC_ALT_PRESET);
31
32@@ -456,7 +456,7 @@ cheese_camera_set_video_recording (CheeseCamera *camera, GError **error)
33     video_preset = (gchar *) &CHEESE_VIDEO_ENC_ALT_PRESET;
34     res = gst_preset_load_preset (GST_PRESET (video_enc), video_preset);
35     if (res == FALSE) {
36-      g_warning ("Can't find vp8enc preset: \"%s\", "
37+      g_warning ("Can't find h264enc preset: \"%s\", "
38           "creating new userspace preset.", video_preset);
39
40       /* Seems like we do first run and userspace preset do not exist.
41@@ -469,14 +469,14 @@ cheese_camera_set_video_recording (CheeseCamera *camera, GError **error)
42   }
43   gst_object_unref(video_enc);
44
45-  /* create profile for webm encoding */
46-  caps = gst_caps_from_string("video/webm");
47-  prof = gst_encoding_container_profile_new("WebM audio/video",
48-      "Standard WebM/VP8/Vorbis",
49+  /* create profile for matroska encoding */
50+  caps = gst_caps_from_string("video/x-matroska");
51+  prof = gst_encoding_container_profile_new("Matroska audio/video",
52+      "Standard Matroska/H264/Vorbis",
53       caps, NULL);
54   gst_caps_unref (caps);
55
56-  caps = gst_caps_from_string("video/x-vp8");
57+  caps = gst_caps_from_string("video/x-h264");
58   v_prof = gst_encoding_video_profile_new(caps, NULL, NULL, 0);
59   gst_encoding_video_profile_set_variableframerate(v_prof, TRUE);
60   gst_encoding_profile_set_preset((GstEncodingProfile*) v_prof, video_preset);
61@@ -772,6 +772,13 @@ cheese_camera_set_new_caps (CheeseCamera *camera)
62     g_object_set (priv->effects_capsfilter, "caps", caps, NULL);
63   }
64   gst_caps_unref (caps);
65+
66+  caps = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1,format=F32LE");
67+  if (caps)
68+  {
69+    g_object_set (priv->camerabin, "audio-capture-caps", caps, NULL);
70+    gst_caps_unref (caps);
71+  }
72 }
73
74 void
75diff --git a/libcheese/cheese-fileutil.h b/libcheese/cheese-fileutil.h
76index 87f827f6..0e420ef7 100644
77--- a/libcheese/cheese-fileutil.h
78+++ b/libcheese/cheese-fileutil.h
79@@ -36,7 +36,7 @@
80  *
81  * The filename suffix for videos saved by Cheese.
82  */
83-#define CHEESE_VIDEO_NAME_SUFFIX ".webm"
84+#define CHEESE_VIDEO_NAME_SUFFIX ".mkv"
85
86 G_BEGIN_DECLS
87
88--
892.25.1
90
91