From ee1a408f9b1d17f303b20f564cb02316365d7777 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sat, 25 Feb 2012 14:54:45 +0100 Subject: [PATCH] spark: fix TODO in cVideo::ShowPicture() rebuild the MPEG stillpicture if the source jpeg has changed additionally check for zero sized m2v from broken ffmpeg versions --- libspark/video.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libspark/video.cpp b/libspark/video.cpp index 20f1a3b..43f9110 100644 --- a/libspark/video.cpp +++ b/libspark/video.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -333,10 +334,14 @@ void cVideo::ShowPicture(const char * fname) char destname[512]; char cmd[512]; char *p; - unsigned char *data; int mfd; - struct stat st; + struct stat st, st2; strcpy(destname, "/var/cache"); + if (stat(fname, &st2)) + { + lt_info("%s: could not stat %s (%m)\n", __func__, fname); + return; + } mkdir(destname, 0755); /* the cache filename is (example for /share/tuxbox/neutrino/icons/radiomode.jpg): /var/cache/share.tuxbox.neutrino.icons.radiomode.jpg.m2v @@ -347,14 +352,17 @@ void cVideo::ShowPicture(const char * fname) while ((p = strchr(p, '/')) != NULL) *p = '.'; strcat(destname, ".m2v"); - /* ...then check if it exists already... - TODO: check if the cache file is older than the jpeg file... */ - if (access(destname, R_OK)) + /* ...then check if it exists already... */ + if (stat(destname, &st) || (st.st_mtime != st2.st_mtime) || (st.st_size == 0)) { - /* it does not exist, so call ffmpeg to create it... */ + struct utimbuf u; + u.actime = time(NULL); + u.modtime = st2.st_mtime; + /* it does not exist or has a different date, so call ffmpeg... */ sprintf(cmd, "ffmpeg -y -f mjpeg -i '%s' -s 1280x720 '%s'