static gboolean thumbnail_cb (gpointer user) { GstSample *b = NULL; GstCaps *caps; GESPipeline *p; p = GES_PIPELINE (user); caps = gst_caps_from_string ("image/jpeg"); GST_INFO ("getting thumbnails"); /* check raw rgb use-case with scaling */ b = ges_pipeline_get_thumbnail_rgb24 (p, 320, 240); g_assert (b); gst_sample_unref (b); /* check encoding use-case from caps */ b = NULL; b = ges_pipeline_get_thumbnail (p, caps); g_assert (b); gst_sample_unref (b); g_assert (ges_pipeline_save_thumbnail (p, -1, -1, (gchar *) "image/jpeg", (gchar *) TEST_PATH, NULL)); g_assert (g_file_test (TEST_PATH, G_FILE_TEST_EXISTS)); g_unlink (TEST_PATH); gst_caps_unref (caps); return FALSE; }
/** * ges_pipeline_save_thumbnail: * @self: a #GESPipeline in %GST_STATE_PLAYING or %GST_STATE_PAUSED * @width: the requested width or -1 for native size * @height: the requested height or -1 for native size * @format: a string specifying the desired mime type (for example, * image/jpeg) * @location: the path to save the thumbnail * @error: (out) (allow-none) (transfer full): An error to be set in case * something wrong happens or %NULL * * Saves the current frame to the specified @location. * * Returns: %TRUE if the thumbnail was properly save, else %FALSE. */ gboolean ges_pipeline_save_thumbnail (GESPipeline * self, int width, int height, const gchar * format, const gchar * location, GError ** error) { GstMapInfo map_info; GstBuffer *b; GstSample *sample; GstCaps *caps; gboolean res = TRUE; g_return_val_if_fail (GES_IS_PIPELINE (self), FALSE); caps = gst_caps_from_string (format); if (width > 1) gst_caps_set_simple (caps, "width", G_TYPE_INT, width, NULL); if (height > 1) gst_caps_set_simple (caps, "height", G_TYPE_INT, height, NULL); if (!(sample = ges_pipeline_get_thumbnail (self, caps))) { gst_caps_unref (caps); return FALSE; } b = gst_sample_get_buffer (sample); if (gst_buffer_map (b, &map_info, GST_MAP_READ)) { if (!g_file_set_contents (location, (const char *) map_info.data, map_info.size, error)) { GST_WARNING ("Could not save thumbnail: %s", error ? (*error)->message : ""); res = FALSE; } } gst_caps_unref (caps); gst_buffer_unmap (b, &map_info); gst_buffer_unref (b); gst_sample_unref (sample); return res; }
GstSample * ges_pipeline_get_thumbnail_rgb24 (GESPipeline * self, gint width, gint height) { GstSample *ret; GstCaps *caps; g_return_val_if_fail (GES_IS_PIPELINE (self), FALSE); caps = gst_caps_new_simple ("video/x-raw", "format", G_TYPE_STRING, "RGB", NULL); if (width != -1) gst_caps_set_simple (caps, "width", G_TYPE_INT, (gint) width, NULL); if (height != -1) gst_caps_set_simple (caps, "height", G_TYPE_INT, (gint) height, NULL); ret = ges_pipeline_get_thumbnail (self, caps); gst_caps_unref (caps); return ret; }