add routine to save a thumbnail in the specified encoding

This commit is contained in:
Brandon Lewis 2010-07-15 19:49:28 +02:00 committed by Edward Hervey
parent 74c58d9cdf
commit bde192be3d
2 changed files with 60 additions and 3 deletions

View file

@ -28,6 +28,7 @@
*/ */
#include <gst/gst.h> #include <gst/gst.h>
#include <stdio.h>
#include "ges-internal.h" #include "ges-internal.h"
#include "ges-timeline-pipeline.h" #include "ges-timeline-pipeline.h"
#include "ges-screenshot.h" #include "ges-screenshot.h"
@ -713,7 +714,8 @@ ges_timeline_pipeline_set_mode (GESTimelinePipeline * pipeline,
*/ */
GstBuffer * GstBuffer *
ges_timeline_pipeline_get_thumbnail (GESTimelinePipeline * self, GstCaps * caps) ges_timeline_pipeline_get_thumbnail_buffer (GESTimelinePipeline * self,
GstCaps * caps)
{ {
GstElement *sink; GstElement *sink;
GstBuffer *buf; GstBuffer *buf;
@ -731,6 +733,57 @@ ges_timeline_pipeline_get_thumbnail (GESTimelinePipeline * self, GstCaps * caps)
return buf; return buf;
} }
/**
* ges_timeline_pipeline_save_thumbnail
* @self: a #GESTimelinePipeline 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
*
* A convenience method for ges_timeline_pipeline_get_thumbnail_raw which
* returns a buffer in 24-bit RGB, optionally scaled to the specified width
* and height. If -1 is specified for either dimension, it will be left at
* native size. You can retreive this information from the caps associated
* with the buffer.
*
* The caller is responsible for unreffing the returned buffer with
* #gst_buffer_unref.
*
* Returns: a #GstBuffer or %NULL
*/
gboolean
ges_timeline_pipeline_save_thumbnail (GESTimelinePipeline * self, int width, int
height, gchar * format, gchar * location)
{
GstBuffer *b;
FILE *fp;
GstCaps *caps;
caps = gst_caps_from_string (format);
if (width > 1)
gst_caps_set_simple (caps, "width", width, NULL);
if (height > 1)
gst_caps_set_simple (caps, "height", height, NULL);
if (!(b = ges_timeline_pipeline_get_thumbnail_buffer (self, caps))) {
gst_caps_unref (caps);
return FALSE;
}
fp = fopen (location, "w+");
fwrite (GST_BUFFER_DATA (b), GST_BUFFER_SIZE (b), 1, fp);
fclose (fp);
gst_caps_unref (caps);
gst_buffer_unref (b);
return TRUE;
}
/** /**
* ges_timeline_pipeline_get_thumbnail_rgb24 * ges_timeline_pipeline_get_thumbnail_rgb24
* @self: a #GESTimelinePipeline in %GST_STATE_PLAYING or %GST_STATE_PAUSED * @self: a #GESTimelinePipeline in %GST_STATE_PLAYING or %GST_STATE_PAUSED
@ -764,7 +817,7 @@ ges_timeline_pipeline_get_thumbnail_rgb24 (GESTimelinePipeline * self,
if (height != -1) if (height != -1)
gst_caps_set_simple (caps, "height", (gint) height, NULL); gst_caps_set_simple (caps, "height", (gint) height, NULL);
ret = ges_timeline_pipeline_get_thumbnail (self, caps); ret = ges_timeline_pipeline_get_thumbnail_buffer (self, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
return ret; return ret;
} }

View file

@ -109,12 +109,16 @@ gboolean ges_timeline_pipeline_set_mode (GESTimelinePipeline *pipeline,
GESPipelineFlags mode); GESPipelineFlags mode);
GstBuffer * GstBuffer *
ges_timeline_pipeline_get_thumbnail(GESTimelinePipeline *self, GstCaps *caps); ges_timeline_pipeline_get_thumbnail_buffer(GESTimelinePipeline *self, GstCaps *caps);
GstBuffer * GstBuffer *
ges_timeline_pipeline_get_thumbnail_rgb24(GESTimelinePipeline *self, ges_timeline_pipeline_get_thumbnail_rgb24(GESTimelinePipeline *self,
gint width, gint height); gint width, gint height);
gboolean
ges_timeline_pipeline_save_thumbnail(GESTimelinePipeline *self,
int width, int height, gchar *format, gchar *location);
G_END_DECLS G_END_DECLS
#endif /* _GES_TIMELINE_PIPELINE */ #endif /* _GES_TIMELINE_PIPELINE */