Index: src/backend/bacon-video-widget-xine.c
===================================================================
--- src/backend/bacon-video-widget-xine.c	(revision 5460)
+++ src/backend/bacon-video-widget-xine.c	(working copy)
@@ -4032,6 +4032,8 @@
 	case BVW_INFO_HAS_AUDIO:
 		bacon_video_widget_get_metadata_bool (bvw, type, value);
 		break;
+	case BVW_INFO_COVER:
+		break;
 	default:
 		g_assert_not_reached ();
 	}
Index: src/backend/bacon-video-widget.h
===================================================================
--- src/backend/bacon-video-widget.h	(revision 5460)
+++ src/backend/bacon-video-widget.h	(working copy)
@@ -199,6 +199,7 @@
 	BVW_INFO_ALBUM,
 	BVW_INFO_DURATION,
 	BVW_INFO_TRACK_NUMBER,
+	BVW_INFO_COVER,
 	/* Video */
 	BVW_INFO_HAS_VIDEO,
 	BVW_INFO_DIMENSION_X,
Index: src/backend/bacon-video-widget-gst-0.10.c
===================================================================
--- src/backend/bacon-video-widget-gst-0.10.c	(revision 5460)
+++ src/backend/bacon-video-widget-gst-0.10.c	(working copy)
@@ -4191,7 +4191,8 @@
   { BVW_INFO_AUDIO_BITRATE, "audio-bitrate" },
   { BVW_INFO_AUDIO_CODEC, "audio-codec" },
   { BVW_INFO_AUDIO_SAMPLE_RATE, "samplerate" },
-  { BVW_INFO_AUDIO_CHANNELS, "channels" }
+  { BVW_INFO_AUDIO_CHANNELS, "channels" },
+  { BVW_INFO_COVER, "image" }
 };
 
 static const gchar *
@@ -4568,6 +4569,30 @@
   gst_object_unref (bus);
 }
 
+static GdkPixbuf *
+bacon_video_widget_get_metadata_pixbuf (BaconVideoWidget * bvw,
+					GstBuffer *buffer)
+{
+	GdkPixbufLoader *loader;
+	GdkPixbuf *pixbuf;
+
+	loader = gdk_pixbuf_loader_new ();
+	if (!gdk_pixbuf_loader_write (loader, buffer->data, buffer->size, NULL)) {
+		g_object_unref (loader);
+		return NULL;
+	}
+	if (!gdk_pixbuf_loader_close (loader, NULL)) {
+		g_object_unref (loader);
+		return NULL;
+	}
+
+	pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+	if (pixbuf)
+		g_object_ref (pixbuf);
+	g_object_unref (loader);
+	return pixbuf;
+}
+
 void
 bacon_video_widget_get_metadata (BaconVideoWidget * bvw,
                                  BaconVideoWidgetMetadataType type,
@@ -4603,6 +4628,30 @@
     case BVW_INFO_HAS_AUDIO:
       bacon_video_widget_get_metadata_bool (bvw, type, value);
       break;
+    case BVW_INFO_COVER:
+      {
+        const GValue *cover_value;
+
+        if (bvw->priv->tagcache == NULL)
+          break;
+        cover_value = gst_tag_list_get_value_index (bvw->priv->tagcache,
+						    GST_TAG_IMAGE,
+						    0);
+	if (cover_value) {
+		GstBuffer *buffer;
+		GdkPixbuf *pixbuf;
+
+		buffer = gst_value_get_buffer (cover_value);
+		g_value_init (value, GDK_TYPE_PIXBUF);
+
+		pixbuf = bacon_video_widget_get_metadata_pixbuf (bvw, buffer);
+		if (pixbuf) {
+			g_message ("We have a pixbuf %p", pixbuf);
+			g_value_take_object (value, pixbuf);
+		}
+	}
+      }
+      break;
     default:
       g_return_if_reached ();
     }
Index: src/totem-video-thumbnailer.c
===================================================================
--- src/totem-video-thumbnailer.c	(revision 5460)
+++ src/totem-video-thumbnailer.c	(working copy)
@@ -57,6 +57,12 @@
 static gint64 second_index = -1;
 static char **filenames = NULL;
 
+typedef struct {
+	const char *output;
+	const char *input;
+	GdkPixbuf *pixbuf;
+} callback_data;
+
 #ifdef THUMB_DEBUG
 static void
 show_pixbuf (GdkPixbuf *pix)
@@ -326,7 +332,9 @@
 }
 
 static GdkPixbuf *
-capture_interesting_frame (BaconVideoWidget * bvw, char *input, char *output) 
+capture_interesting_frame (BaconVideoWidget *bvw,
+			   const char *input,
+			   const char *output) 
 {
 	GdkPixbuf* pixbuf;
 	guint current;
@@ -343,9 +351,9 @@
 	 * interesting frame */
 	for (current = 0; current < G_N_ELEMENTS(frame_locations); current++)
 	{
-		PROGRESS_DEBUG("About to seek to %f\n", frame_locations[current]);
+		PROGRESS_DEBUG("About to seek to %f", frame_locations[current]);
 		if (bacon_video_widget_seek (bvw, frame_locations[current], NULL) == FALSE) {
-			PROGRESS_DEBUG("Couldn't seek to %f\n", frame_locations[current]);
+			PROGRESS_DEBUG("Couldn't seek to %f", frame_locations[current]);
 			bacon_video_widget_play (bvw, NULL);
 		}
 
@@ -362,10 +370,10 @@
 		}
 
 		/* Pull the frame, if it's interesting we bail early */
-		PROGRESS_DEBUG("About to get frame for iter %d\n", current);
+		PROGRESS_DEBUG("About to get frame for iter %d", current);
 		pixbuf = bacon_video_widget_get_current_frame (bvw);
 		if (pixbuf != NULL && is_image_interesting (pixbuf) != FALSE) {
-			PROGRESS_DEBUG("Frame for iter %d is interesting\n", current);
+			PROGRESS_DEBUG("Frame for iter %d is interesting", current);
 			break;
 		}
 
@@ -377,13 +385,16 @@
 				pixbuf = NULL;
 			}
 		}
-		PROGRESS_DEBUG("Frame for iter %d was not interesting\n", current);
+		PROGRESS_DEBUG("Frame for iter %d was not interesting", current);
 	}
 	return pixbuf;
 }
 
 static GdkPixbuf *
-capture_frame_at_time(BaconVideoWidget *bvw, char *input, char *output,  gint64 seconds) 
+capture_frame_at_time(BaconVideoWidget *bvw,
+		      const char *input,
+		      const char *output,
+		      gint64 seconds) 
 {
 	GError *err = NULL;
 
@@ -412,6 +423,34 @@
 	return bacon_video_widget_get_current_frame (bvw);
 }
 
+static void
+on_got_metadata_event (BaconVideoWidget *bvw, callback_data *data)
+{
+	GValue value = { 0, };
+	GdkPixbuf *pixbuf;
+
+	PROGRESS_DEBUG("Got metadata, checking if we have a cover");
+	bacon_video_widget_get_metadata (bvw, BVW_INFO_COVER, &value);
+	if (!G_VALUE_HOLDS_OBJECT (&value)) {
+		g_value_unset (&value);
+		return;
+	}
+	pixbuf = g_value_get_object (&value);
+
+	if (pixbuf) {
+		PROGRESS_DEBUG("Saving cover image");
+
+		bacon_video_widget_close (bvw);
+		totem_resources_monitor_stop ();
+		gtk_widget_destroy (GTK_WIDGET (bvw));
+
+		save_pixbuf (pixbuf, data->output, data->input, output_size, TRUE);
+		g_object_unref (pixbuf);
+
+		exit (1);
+	}
+}
+
 static const GOptionEntry entries[] = {
 	{ "jpeg", 'j',  0, G_OPTION_ARG_NONE, &jpeg_output, "Output the thumbnail as a JPEG instead of PNG", NULL },
 	{ "size", 's', 0, G_OPTION_ARG_INT, &output_size, "Size of the thumbnail in pixels", NULL },
@@ -432,7 +471,8 @@
 	GError *err = NULL;
 	BaconVideoWidget *bvw;
 	GdkPixbuf *pixbuf;
-	char *input, *output;
+	const char *input, *output;
+	callback_data data;
 
 #ifdef G_OS_UNIX
 	nice (20);
@@ -456,7 +496,6 @@
 		return 1;
 	}
 
-#ifndef THUMB_DEBUG
 	if (g_fatal_warnings) {
 		GLogLevelFlags fatal_mask;
 
@@ -464,7 +503,6 @@
 		fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
 		g_log_set_always_fatal (fatal_mask);
 	}
-#endif /* THUMB_DEBUG */
 
 	if (filenames == NULL || g_strv_length (filenames) != 2) {
 		char *help;
@@ -476,7 +514,7 @@
 	input = filenames[0];
 	output = filenames[1];
 
-	PROGRESS_DEBUG("Initialised libraries, about to create video widget\n");
+	PROGRESS_DEBUG("Initialised libraries, about to create video widget");
 
 	bvw = BACON_VIDEO_WIDGET (bacon_video_widget_new (-1, -1, BVW_USE_TYPE_CAPTURE, &err));
 	if (err != NULL) {
@@ -485,13 +523,19 @@
 		g_error_free (err);
 		exit (1);
 	}
+	data.input = input;
+	data.output = output;
+	data.pixbuf = NULL;
+	g_signal_connect (G_OBJECT (bvw), "got-metadata",
+			  G_CALLBACK (on_got_metadata_event),
+			  &data);
 
-	PROGRESS_DEBUG("Video widget created\n");
+	PROGRESS_DEBUG("Video widget created");
 
 	if (time_limit != FALSE)
 		totem_resources_monitor_start (input, 0);
 
-	PROGRESS_DEBUG("About to open video file\n");
+	PROGRESS_DEBUG("About to open video file");
 
 	if (bacon_video_widget_open (bvw, input, &err) == FALSE) {
 		g_print ("totem-video-thumbnailer couldn't open file '%s'\n"
@@ -501,8 +545,8 @@
 		exit (1);
 	}
 
-	PROGRESS_DEBUG("Opened video file: '%s'\n", input);
-	PROGRESS_DEBUG("About to play file\n");
+	PROGRESS_DEBUG("Opened video file: '%s'", input);
+	PROGRESS_DEBUG("About to play file");
 
 	bacon_video_widget_play (bvw, &err);
 	if (err != NULL) {
@@ -511,9 +555,8 @@
 		g_error_free (err);
 		exit (1);
 	}
+	PROGRESS_DEBUG("Started playing file");
 
-	PROGRESS_DEBUG("Started playing file\n");
-
 	/* If the user has told us to use a frame at a specific second 
 	 * into the video, just use that frame no matter how boring it
 	 * is */
@@ -533,7 +576,7 @@
 		exit (1);
 	}
 
-	PROGRESS_DEBUG("Saving captured screenshot\n");
+	PROGRESS_DEBUG("Saving captured screenshot");
 	save_pixbuf (pixbuf, output, input, output_size, FALSE);
 	g_object_unref (pixbuf);
 
