summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorMatthieu Crapet <mcrapet@gmail.com>2015-09-23 10:01:32 +0200
committerTim-Philipp Müller <tim@centricular.com>2018-01-31 17:51:16 +0000
commitba86a1d99cabf331be5f1460289b013c5bea5aa8 (patch)
tree5f33c1c1ba8b9118843762e2ae14258ad4bb2904 /ext
parentcbb9c3122870208e355da0c76f73db3fb981e2fa (diff)
jpegenc: add snapshot property
Like pngenc, automatically send an EOS message. Example of bin: appsrc ! jpegenc snapshot=true ! filesink location=out.jpg This is especially useful for limited/slow hardware. Otherwise calling gst_video_convert_sample() is a better option (internally uses videoconvert and videoscale). https://bugzilla.gnome.org/show_bug.cgi?id=755453
Diffstat (limited to 'ext')
-rw-r--r--ext/jpeg/gstjpegenc.c25
-rw-r--r--ext/jpeg/gstjpegenc.h1
2 files changed, 24 insertions, 2 deletions
diff --git a/ext/jpeg/gstjpegenc.c b/ext/jpeg/gstjpegenc.c
index 7913a9764..3f4be0649 100644
--- a/ext/jpeg/gstjpegenc.c
+++ b/ext/jpeg/gstjpegenc.c
@@ -54,6 +54,7 @@ GST_DEBUG_CATEGORY_STATIC (jpegenc_debug);
#define JPEG_DEFAULT_QUALITY 85
#define JPEG_DEFAULT_SMOOTHING 0
#define JPEG_DEFAULT_IDCT_METHOD JDCT_FASTEST
+#define JPEG_DEFAULT_SNAPSHOT FALSE
/* JpegEnc signals and args */
enum
@@ -67,7 +68,8 @@ enum
PROP_0,
PROP_QUALITY,
PROP_SMOOTHING,
- PROP_IDCT_METHOD
+ PROP_IDCT_METHOD,
+ PROP_SNAPSHOT
};
static void gst_jpegenc_finalize (GObject * object);
@@ -150,11 +152,23 @@ gst_jpegenc_class_init (GstJpegEncClass * klass)
"The IDCT algorithm to use", GST_TYPE_IDCT_METHOD,
JPEG_DEFAULT_IDCT_METHOD,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ /**
+ * GstJpegEnc:snapshot:
+ *
+ * Send EOS after encoding a frame, useful for snapshots.
+ *
+ * Since: 1.14
+ */
+ g_object_class_install_property (gobject_class, PROP_SNAPSHOT,
+ g_param_spec_boolean ("snapshot", "Snapshot",
+ "Send EOS after encoding a frame, useful for snapshots",
+ JPEG_DEFAULT_SNAPSHOT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_add_static_pad_template (element_class,
&gst_jpegenc_sink_pad_template);
gst_element_class_add_static_pad_template (element_class,
&gst_jpegenc_src_pad_template);
+
gst_element_class_set_static_metadata (element_class, "JPEG image encoder",
"Codec/Encoder/Image", "Encode images in JPEG format",
"Wim Taymans <wim.taymans@tvd.be>");
@@ -303,6 +317,7 @@ gst_jpegenc_init (GstJpegEnc * jpegenc)
jpegenc->quality = JPEG_DEFAULT_QUALITY;
jpegenc->smoothing = JPEG_DEFAULT_SMOOTHING;
jpegenc->idct_method = JPEG_DEFAULT_IDCT_METHOD;
+ jpegenc->snapshot = JPEG_DEFAULT_SNAPSHOT;
}
static void
@@ -528,7 +543,7 @@ gst_jpegenc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame)
jpeg_finish_compress (&jpegenc->cinfo);
GST_LOG_OBJECT (jpegenc, "compressing done");
- return jpegenc->res;
+ return (jpegenc->snapshot) ? GST_FLOW_EOS : jpegenc->res;
invalid_frame:
{
@@ -566,6 +581,9 @@ gst_jpegenc_set_property (GObject * object, guint prop_id,
case PROP_IDCT_METHOD:
jpegenc->idct_method = g_value_get_enum (value);
break;
+ case PROP_SNAPSHOT:
+ jpegenc->snapshot = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -594,6 +612,9 @@ gst_jpegenc_get_property (GObject * object, guint prop_id, GValue * value,
case PROP_IDCT_METHOD:
g_value_set_enum (value, jpegenc->idct_method);
break;
+ case PROP_SNAPSHOT:
+ g_value_set_boolean (value, jpegenc->snapshot);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
diff --git a/ext/jpeg/gstjpegenc.h b/ext/jpeg/gstjpegenc.h
index 82b686810..df7529941 100644
--- a/ext/jpeg/gstjpegenc.h
+++ b/ext/jpeg/gstjpegenc.h
@@ -86,6 +86,7 @@ struct _GstJpegEnc
gint quality;
gint smoothing;
gint idct_method;
+ gboolean snapshot;
GstMemory *output_mem;
GstMapInfo output_map;