Page 1 of 2

[Suggestion] Cache Video/Picture Thumbnails

Posted: Mon Jun 03, 2013 7:56 am
by Zero3K
It would be nice if there was an option to cache the thumbnails of videos/pictures in order to speed up browsing.

Re: Cache Video/Picture Thumbnails

Posted: Mon Jun 03, 2013 8:16 pm
by SharkHunter
To some extent they are cached. For example all thumbs that are fetched from an url are normally saved on disc to speed up look up...

Re: Cache Video/Picture Thumbnails

Posted: Tue Jun 04, 2013 11:58 am
by SubJunk
I have been thinking about adding this feature for a while now, I agree. It's on my wishlist

Re: Cache Video/Picture Thumbnails

Posted: Thu Jun 06, 2013 6:16 pm
by SharkHunter
It looks like thumbs are cached

Code: Select all

if (getMedia().getThumb() != null && configuration.getUseCache() && inputFile.getFile() != null) {
PMS.get().getDatabase().updateThumbnail(inputFile.getFile().getAbsolutePath(), inputFile.getFile().lastModified(), getType(), getMedia());
}
But maybe that code dosn't work?
usecache has to be true but other than that?

Take a look at protected void checkThumbnail(InputFile inputFile)

Re: Cache Video/Picture Thumbnails

Posted: Sun Jun 09, 2013 10:55 am
by SubJunk
That's only if the file cache is enabled. The feature I want to add would cache the thumbnails even without the cache enabled. I think the ability to run without a file cache is one of the big things that makes us better than other programs and we can make that even faster by caching the thumbnails.

Re: Cache Video/Picture Thumbnails

Posted: Sun Jun 09, 2013 8:20 pm
by SharkHunter
Agree the non-file cache is a big +. I'm just wondering how this will affect the memory useage?

Re: Cache Video/Picture Thumbnails

Posted: Sun Jun 09, 2013 9:08 pm
by SubJunk
Well we already kindof do it with the way we allow users to have their own cover images, so we check for an image with the same name as the video. I guess all we need to do is to make UMS save the thumbnails it generates instead of storing them in memory (is that what we do now? I have no idea), and make a nice folder for them (programdata\UMS\thumbnails)
Each thumbnail is only about 320x180 and jpeg if memory serves, so even with thousands it shouldn't take up much space.

Re: Cache Video/Picture Thumbnails

Posted: Mon Jun 10, 2013 7:47 pm
by SharkHunter
Yep your correct. All the code is there but not used (in some obscure way).
Take a look at https://github.com/UniversalMediaServer ... aInfo.java
At the bottom (of parse) we do

Code: Select all

ByteArrayOutputStream out = new ByteArrayOutputStream();
								ImageIO.write(image, "jpeg", out);
								setThumb(out.toByteArray());
So (if I'm right thats one messy function) we should swap out to a file and then do some check to see if the file already exists and return early.

Re: Cache Video/Picture Thumbnails

Posted: Tue Jun 11, 2013 1:02 pm
by SubJunk
Yep I think you're right that's the way to do it

Re: Cache Video/Picture Thumbnails

Posted: Tue Jun 11, 2013 9:13 pm
by SharkHunter
With the risk of spamming the forum with boring details. Here we go:
The thumbs are cached in memory (the full binary data)

Code: Select all

setThumb(out.toByteArray());
. So the real question here is what is most efficient to extract the thumbs and store the data in memory or to extract it to a file and read from the file when needed? Of course you could extract to the file and then re-read the file back into memory.
In theory it should be most efficient to extract them once and read from file but I'm wondering if it is really that much more??