diff options
author | Bastien Nocera <hadess@hadess.net> | 2012-06-21 12:37:59 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2012-06-22 11:32:20 +0100 |
commit | 172fc2478b7f348f07beb348f6863b5766388a39 (patch) | |
tree | 943c8feb0e25ca6e57d275dc580ca54c96e34254 /src/totem-video-thumbnailer.c | |
parent | ae3e78b206ceb65e3d4820a9430bf04df4d79ec7 (diff) | |
download | totem-172fc2478b7f348f07beb348f6863b5766388a39.tar.gz |
thumbnailer: Thumbnail unseekable video files too
Rather than bail because we can't look for more interesting
frames somewhere else in the file.
Diffstat (limited to 'src/totem-video-thumbnailer.c')
-rw-r--r-- | src/totem-video-thumbnailer.c | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/src/totem-video-thumbnailer.c b/src/totem-video-thumbnailer.c index 16792d7c9..74a4086c2 100644 --- a/src/totem-video-thumbnailer.c +++ b/src/totem-video-thumbnailer.c @@ -258,9 +258,19 @@ thumb_app_set_duration (ThumbApp *app) app->duration = len / GST_MSECOND; return TRUE; } + app->duration = -1; return FALSE; } +static void +assert_duration (ThumbApp *app) +{ + if (app->duration != -1) + return; + g_print ("totem-video-thumbnailer couldn't get the duration of file '%s'\n", app->input); + exit (1); +} + static gboolean thumb_app_get_has_video (ThumbApp *app) { @@ -644,6 +654,16 @@ save_pixbuf (GdkPixbuf *pixbuf, const char *path, } static GdkPixbuf * +capture_frame_at_time (ThumbApp *app, + gint64 milliseconds) +{ + if (milliseconds != 0) + thumb_app_seek (app, milliseconds); + + return totem_gst_playbin_get_frame (app->play); +} + +static GdkPixbuf * capture_interesting_frame (ThumbApp *app) { GdkPixbuf* pixbuf; @@ -656,6 +676,11 @@ capture_interesting_frame (ThumbApp *app) 0.5 }; + if (app->duration == -1) { + PROGRESS_DEBUG("Video has no duration, so capture 1st frame"); + return capture_frame_at_time (app, 0); + } + /* Test at multiple points in the file to see if we can get an * interesting frame */ for (current = 0; current < G_N_ELEMENTS(frame_locations); current++) @@ -685,16 +710,6 @@ capture_interesting_frame (ThumbApp *app) } static GdkPixbuf * -capture_frame_at_time (ThumbApp *app, - gint64 milliseconds) -{ - if (milliseconds != 0) - thumb_app_seek (app, milliseconds); - - return totem_gst_playbin_get_frame (app->play); -} - -static GdkPixbuf * cairo_surface_to_pixbuf (cairo_surface_t *surface) { gint stride, width, height, x, y; @@ -1059,10 +1074,7 @@ int main (int argc, char *argv[]) PROGRESS_DEBUG ("totem-video-thumbnailer couldn't find a video track in '%s'\n", input); exit (1); } - if (thumb_app_set_duration (&app) == FALSE) { - g_print ("totem-video-thumbnailer couldn't get the duration of file '%s'\n", input); - exit (1); - } + thumb_app_set_duration (&app); PROGRESS_DEBUG("Opened video file: '%s'", input); PRINT_PROGRESS (10.0); @@ -1071,12 +1083,15 @@ int main (int argc, char *argv[]) /* 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 */ - if (second_index != -1) + if (second_index != -1) { + assert_duration (&app); pixbuf = capture_frame_at_time (&app, second_index * 1000); - else + } else { pixbuf = capture_interesting_frame (&app); + } PRINT_PROGRESS (90.0); } else { + assert_duration (&app); /* We're producing a gallery of screenshots from throughout the file */ pixbuf = create_gallery (&app); } |