summaryrefslogtreecommitdiff
path: root/thumbnailer
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2015-04-03 13:15:00 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2015-04-03 13:15:00 +0200
commitbc53b714952ceb0afd02b591403cb2bc0cb1aab9 (patch)
tree8ff57ed1a1265b2c87f37e3c8fa19876faf80990 /thumbnailer
parentd4c476947425c12b1984fedea16f8a8c42a07ba3 (diff)
parentc43dfb815a4951b8248f4f0e98babe4f80204f03 (diff)
Merge tag 'upstream/0.22.0'
Upstream version 0.22.0
Diffstat (limited to 'thumbnailer')
-rw-r--r--thumbnailer/shotwell-video-thumbnailer.vala74
1 files changed, 16 insertions, 58 deletions
diff --git a/thumbnailer/shotwell-video-thumbnailer.vala b/thumbnailer/shotwell-video-thumbnailer.vala
index 93db2aa..e73dc79 100644
--- a/thumbnailer/shotwell-video-thumbnailer.vala
+++ b/thumbnailer/shotwell-video-thumbnailer.vala
@@ -1,4 +1,4 @@
-/* Copyright 2011-2014 Yorba Foundation
+/* Copyright 2011-2015 Yorba Foundation
*
* This is a Vala-rewrite of GStreamer snapshot example. Adapted from earlier
* work from Wim Taymans.
@@ -14,13 +14,11 @@ class ShotwellThumbnailer {
public static int main(string[] args) {
Gst.Element pipeline, sink;
- int width, height;
- Gst.Sample sample;
string descr;
Gdk.Pixbuf pixbuf;
+ uint8[]? pngdata;
int64 duration, position;
Gst.StateChangeReturn ret;
- bool res;
Gst.init(ref args);
@@ -30,7 +28,7 @@ class ShotwellThumbnailer {
}
descr = "filesrc location=\"%s\" ! decodebin ! videoconvert ! videoscale ! ".printf(args[1]) +
- "appsink name=sink caps=\"%s\"".printf(caps_string);
+ "%s ! gdkpixbufsink name=sink".printf(caps_string);
try {
// Create new pipeline.
@@ -59,7 +57,10 @@ class ShotwellThumbnailer {
}
/* get the duration */
- pipeline.query_duration (Gst.Format.TIME, out duration);
+ if (!pipeline.query_duration (Gst.Format.TIME, out duration)) {
+ stderr.printf("Failed to query file for duration\n");
+ return 3;
+ }
position = 1 * Gst.SECOND;
@@ -69,61 +70,18 @@ class ShotwellThumbnailer {
* seek a little more */
pipeline.seek_simple (Gst.Format.TIME, Gst.SeekFlags.KEY_UNIT | Gst.SeekFlags.FLUSH, position);
- /* get the preroll buffer from appsink, this block untils appsink really
- * prerolls */
- GLib.Signal.emit_by_name (sink, "pull-preroll", out sample, null);
+ ret = pipeline.get_state(null, null, 5 * Gst.SECOND);
+ if (ret == Gst.StateChangeReturn.FAILURE) {
+ stderr.printf("Failed to play the file: couldn't get state.\n");
+ return 3;
+ }
- // if we have a buffer now, convert it to a pixbuf. It's possible that we
- // don't have a buffer because we went EOS right away or had an error.
- if (sample != null) {
- Gst.Buffer buffer;
- Gst.Caps caps;
- unowned Gst.Structure s;
- Gst.MapInfo mapinfo;
- uint8[]? pngdata;
+ sink.get ("last-pixbuf", out pixbuf);
- // Get the snapshot buffer format now. We set the caps on the appsink so
- // that it can only be an rgb buffer. The only thing we have not specified
- // on the caps is the height, which is dependent on the pixel-aspect-ratio
- // of the source material.
- caps = sample.get_caps();
- if (caps == null) {
- stderr.printf("could not get snapshot format\n");
- return 5;
- }
-
- s = caps.get_structure(0);
-
- // We need to get the final caps on the buffer to get the size.
- res = s.get_int("width", out width);
- res |= s.get_int("height", out height);
- if (!res) {
- stderr.printf("Could not get snapshot dimension\n");
- return 6;
- }
+ // Save the pixbuf.
+ pixbuf.save_to_buffer(out pngdata, "png");
+ stdout.write(pngdata);
- buffer = sample.get_buffer();
- buffer.map(out mapinfo, Gst.MapFlags.READ);
-
- if (mapinfo.data == null || mapinfo.data.length == 0) {
- stderr.printf("Could not get snapshot data buffer\n");
- return 7;
- }
-
- // Create pixmap from buffer and save, gstreamer video buffers have a stride
- // that is rounded up to the nearest multiple of 4.
- pixbuf = new Gdk.Pixbuf.from_data(mapinfo.data, Gdk.Colorspace.RGB, false, 8,
- width, height, (((width * 3)+3)&~3), null);
-
- // Save the pixbuf.
- pixbuf.save_to_buffer(out pngdata, "png");
- stdout.write(pngdata);
- buffer.unmap(mapinfo);
- } else {
- stderr.printf("Could not make snapshot\n");
- return 10;
- }
-
// cleanup and exit.
pipeline.set_state(Gst.State.NULL);