Page 1 of 1

perfect Video Thumbnails with Twonky 8.x and ffmpeg on WD MyBook Live

Posted: Sat Oct 10, 2015 3:25 pm
by Buchi1000
Hello everyone
English is not my native language, so please excuse my spelling and grammar mistakes.

I am running a Twonky media server on WD my book live for 3 or 4 years.

So far, the video thumbnails never have really worked. I spent a lot of time to search in the WEB, but nothing of the found corresponded to my needs.
That's why I sat down to the computer and developed my own solution.
Hereby I would like to make the result available for other users.

How does it works?
If you display your video list on a TV via DLNA connection to your Twonky Mediaserver or via Twonky Web GUI on a PC with Internet Explorer Twonky triggers a command for each visible video in the list.
My solution captures this event and looks for a JPG file in the folder of the video named as same as the video and ending with .jpg. If this JPEG file exists it will be used for the thumbnail picture. If not, a temporary file will be stored with some information about the video and the needed thumbnail.
Every minute a launcher looks for existing temp files, read them and call ffmpeg to generate a meaningful scene picture taken from the video.
On the displayed thumbnail, you can see whether a DVD label is available, or a thumbnail from the video needs to be created.
Is there a DVD label available, it will be displayed immediately, otherwise a film tape will be displayed – meaning the thumbnail generation is in progress in between the next few minutes.
When you go out from and come back into this folder a few minutes later, a thumbnail will be created. If ffmpeg cannot extract a meaningful thumbnail from your video, you can see a film reel.

Where come the sources from?
The solution is based on some scripts I found in the web. I picked up all of the useable script-snippets and developed a total solution for WD My Book Live 3TB. May be it works on other NAS too, but I have not tested it!

The first problem of the original Twonky thumbnail solution as is in the original download package, is the not-tailored function for the WD NAS to generate thumbnails synchronous on demand.
The NAS is just too slow, to provide the thumbnails requested fast enough. So the thumb-generation mostly crashes and brings only a few of thumbs on the screen.
It is therefore necessary to intercept the request of the thumbnails and to redirect in asynchronous processing.

The second problem of the original solution by Twonky is that it is not possible to display DVD covers as a thumbnail. With my solution this feature is now available.
To use this feature you only have to store your desired DVD cover in format JPEG in the same folder where the video file is stored and with the same name as the video file, added with extension “.jpg”.
i.E. the video is stored as “96 hours – taken III.mkv” in the folder “videos\crime and action” on your NAS, so the DVD cover must be stored as “96 hours – taken III.mkv.jpg” in the same folder.
The recommended resolution of the JPEG picture is “320 to 320” or “320 to X” or “X to 320” pixels. You can also use higher resolutions, but it is not necessary.

Note: The following solution is tested on WD My Book Live 3TB with firmware 02.43.10-048. May be it runs also on previous firmware versions or on other NAS devices, but this is not tested by me.
I exclude all liability for damage or malfunction. All manipulations on your NAS device be done at your own risk. If you do a mistake, you can brick your NAS device!

What do you need for this thumbnail solution?
SSH must be enabled on your NAS to get connection with PuTTY.
A fully functional Twonky 8.x installation on the WD NAS in directory /usr/local/twonky.
Ffmpeg binary and its encoding libraries installed on the WD NAS.
Original WD built-in DLNA Server of WD My Book Live must be disabled.

Now let us install the needed components for my Twonky thumbnail solution.

Enable SSH on your WD device:
Open Internet Explorer and login into WD Dashboard as usual. Change the web address to http://NameOfYourMybooklive/UI/ssh and enable the SSH option.

Download PuTTY from ... /putty.exe and store it in a folder on your PC.
Start PuTTY.exe and connect via SSH to root@IPaddressOfYourNAS with password welc0me.

Make sure that Twonky Mediaserver is stopped:
/etc/init.d/twonky stop

Change active directory with typing:
cd /

Now a new version of ffmpeg binary and libraries must be installed on your device. To do this, follow this steps:

Run this command to remove the claims the MBL puts on some system files:
rm -f /var/lib/dpkg/info/wd-nas.*

Now we want to rename our sources.list and create a new one with nano text editor:
mv /etc/apt/sources.list /etc/apt/sources.list.bak
nano /etc/apt/sources.list

Now copy and paste the following sources into the blank nano editor window (Copy with Strg+C and paste with right click mouse button into nano editor window. Make sure that the cursor is at the position you want to paste!):
deb wheezy main
deb wheezy main non-free

Save the file and exit nano editor window:
Hit control and o
Hit enter
Hit control and x

Now we need to change permissions on the file to make it executable:
chmod 755 /etc/apt/sources.list

Now let us update our sources and install ffmpeg (If asked type y to install without verification and also type y if asked to continue):
apt-get update
apt-get install deb-multimedia-keyring
apt-get update
apt-get install ffmpeg

Ffmpeg is now installed!

In the following let us install the thumbnail solution scripts.
Download the attachment of this article and copy it to your WD NAS Public share base directory.
i.E. \\netstorage\Public\

Go back to PuTTY window and make sure to be in root directory.
If not, type in “cd /” and press Enter (without quotation marks)

Let us back up some existing files to can go back to previous settings:
cp /etc/init.d/twonky /etc/init.d/twonky.bak
cp /etc/priority.conf /etc/priority.conf.bak
cp -a /usr/local/twonky/cgi-bin /usr/local/twonky/cgi-bin.bak

Now we copy the zip file from the Public share to the root directory, unzip it and set permissions:
cp /shares/Public/ /
unzip / (If you will be asked to overwrite input A and press Enter)
chmod 755 /etc/init.d/twonky
cd /usr/local/twonky/cgi-bin
chmod 755 cgi-jpegscale convert-jpeg.desc ffmpeg.location ffmpeg-video-thumb.desc jpeg-scale.desc thumb thumbnail-candidate thumbnail-generate thumbnail-ini thumbnail-launcher

At last make the twonky control script part of system autostart sequence:
cd /etc/init.d
update-rc.d twonky defaults

Congratulation, all steps are finished.
Start Twonky Mediaserver with typing
/etc/init.d/twonky start

Now you can start your TV with DLNA or your Twonky WEB GUI on a PC and view your video lists.
On the Public share of your NAS you can find two log files.
twonky-thumbnail.log contains massages from the asynchronous thumbnail generation function.
twonky-thumbnail-inf.log contains massages from the cached twonky thumbnail event.

I hope, all downloaders enjoy my Twonky thumbnail solution.

Best regards and an error-free digital life :lol: .
Your Buchi1000.

Re: perfect Video Thumbnails with Twonky 8.x and ffmpeg on WD MyBook Live

Posted: Sun Oct 25, 2015 8:42 pm
by wkearney99
[quote="Buchi1000"]Every minute a launcher looks for existing temp files, read them and call ffmpeg to generate a meaningful scene picture taken from the video.[/quote]

First off, nice work!

Are you saying your add-on leaves a task running that scans every minute? How is it detecting how long it should be waiting?

I ask this because lots of times scripts like this end up wasting CPU cycles and electricity. As in, they don't allow an otherwise idle machine to execute it's normal low power and sleep modes.

Just a thought...

(not sure why it didn't parse my use of bbcode quote blocks)

Re: perfect Video Thumbnails with Twonky 8.x and ffmpeg on WD MyBook Live

Posted: Sun Nov 01, 2015 2:37 pm
by Buchi1000
@wkearney99, thanks for your Feedback.
I understand your thoughts. You're right, of course.
I use the Linux sleep command to wait for the next read cycle.
It is the only way I know to make a script waiting processor gently.
Anyway, I've noticed that with installed Twonky, the NAS only rarely goes into the sleep mode.
The reason may be that Twonky itself also regularly scans the drive to find new media files.
But you can increase the time between the read cycles of my script. To do this, there is a value in the thumbnail-ini. Perhaps the drive then goes more often in the idle state.
# set delay seconds for delay between searches for thumb inf files
the default is seconds, but you can also use the spelling 60m (meaning 60 minutes) or 12h (meaning 12 hours)

I would be glad to know whether my work has paid off also by other users.