Twonky DLNA with video thumbnails

Update: download thumbnails and movie posters from the internet automatically using tw-video-scraper for Twonky.

For streaming videos to a DLNA compatible television, you can use TwonkyServer software. This is not the only DLNA software around, but I like it because you can run it on a lot of platforms, it is fast, and it runs on low-powered machines. The installation instructions for Twonky on Linux are not very complete. For thumbnails the instructions are completely missing. You will need some Linux knowledge to set everything up. Luckily, it is not that difficult.

First, download Twonky. If you visit the main web site, it is very easy to miss that Twonky is available for a lot of platforms. On the main web site, only Windows, OS X and Linux i386 are advertised. On the forum, you can find the NAS versions. If you want to run it on an ARM architecture machine, try the Kirkwood build. This is an ARM build, but unlike the other ARM bundles, it will run on newer Debian versions (due to library issues, the ARM bundles do not run on Debian).

Extract the zip file to the directory /usr/local/twonkymedia Next, set the correct permissions on files by running
chmod 700 twonkym* cgi-bin/* plugins/*
Now let’s make sure that Twonky starts when the system boots. A boot script is supplied, but it is not optimised for Debian. Open the file in a text editor and change the lines

# Default-Start:  3 5
# Default-Stop:   0 1 2 6


# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6

Then, make a symbolic link to this script in the /etc/init.d directory, and make sure that the script executed at boot time. This can be done with the following two commands

ln -s /usr/local/twonkymedia/ /etc/init.d/twonkymedia
update-rc.d twonkymedia defaults

That is it for the standard set-up of Twonky. Next, let’s enable thumbnail support. For this, some extra software is needed. This can be installed with
apt-get install dtach ffmpeg
Edit the file /usr/local/twonkymedia/cgi-bin/ffmpeg.location at replace its content with
Next, edit the file /usr/local/twonkymedia/cgi-bin/ffmpeg-video-thumb.desc at replace its content with

# generate video thumbs
#(c) 2010 by PacketVideo
exec: ffmpeg -itsoffset -30 -i $infile -vcodec mjpeg -vframes 1 -an -f rawvideo -s 284x160 $outfile
# capabilities

Finally, make some edits (again) to the file /usr/local/twonkymedia/ Find the line that says "$TWONKYSRV" -D and replace this with dtach -n /tmp/twonkymedia "$TWONKYSRV" Now you should be able to start Twonky with the command /etc/init.d/twonkymedia start

Open a web browser, and go the the URL http://nas-ip-address:9000/config Click on the Transcoding link, select JPEG, and click Save Changes.
Now you can add the folder you wish to make available via Twonky. Click on the Sharing link and add the folder that hold your media. Click Save Changes again, and Twonky will scan your folders for media. With the link Server Status, it is possible to see how far the scan has progressed. Notice that this is only the scanning of the files. The process of generating thumbnails is not covered on the status page. The only way to see this, is on the server itself, with the command dtach -a /tmp/twonkymedia Use the key Ctrl+\ to go back to the terminal. Thumbnail generating will continue in the background.

27 thoughts on “Twonky DLNA with video thumbnails

  1. hello, any solution for windows 7 and “twonky media server 6.0.39” ?
    Although I try your “how to” for windows 7 but at this time your instructions don’t work. Maybe a change is necessary in the ini file or another one…
    Sorry, I’m French.

    1. Could you tell what is not working? At what point do you run into trouble? The instructions are based on Windows 7, so they should work.

      1. Well the instructions posted seem to work to generate thumbs via ffmpeg and I have tried different paths to see if I could see any semblence of the script saving those thumbs and DB but it does not seem to under any path.

        Also the script never scrapes anything from the movie and tv sites it always makes one using ffmpeg.

        1. Thanks for trying my script. There might be some reasons why it does not work. On windows, the most likely cause is access rights. The script must download some files first, before the actual image can be downloaded. These are stored in the configured temp directory. If your current user account does not have any rights to write to this location, nothing can be downloaded. You could try testing this by running the script from the command line, e.g.

          python.exe Californication.S01E01.avi test.jpg

          This will write the image test.jpg to the current directory. If there is an error, you’ll see the output on the screen.

          1. Thanks Daniel thats kind of what I suspected was the issue with the scraping.

            I will try and see if I can get this to work by playing wit folder security permission in Win7 and report back.

            What do I need to do to have the script reparse through the library? Do I need to clear out the Twonky Cache or will rescanning the media automatically trigger the script?

          2. Ok running the script manually using the parameters you gave me it gives and error in line 50 Indentation error Expected indented block.
            I have the folders set to let everyone have full control but I don’t believe the script even got past Line 50.
            I would email you the script if you want I am wondering if somehow the script got munged when I edited it in IDLE

          3. An error when editing is the most likely problem. Line 50 is still the configuration part of the script. Either go over the script again and look for errors (if you can read Python), or download the script again, and make the changes, hoping that it goes okay now.

  2. through IDLE there is a invalid syntax here – ‘tmpdir’: – with the colon.
    Does my paths are valid ?

    #’database’: ‘/var/twonkymedia/twonkymedia/tw-video-scraper.db’,
    ‘database’: ‘C:\tmp\db.db’

    # Path where to download and extract the files
    # downloaded from TVDB. The script will check
    # if a file already exists, so it will not be
    # downloaded again.

    # ‘tmpdir’: ‘/tmp/tw-video-scraper/’,
    ‘tmpdir’: ‘C:\tmp’

    1. when did you download the source files. Try downloading them again. I fixed a bug for that on Thursday. If you use Windows style path names, the \t in c:\temp is seen as a tab. The newer version of the script fixes that, or you could use c:/temp (with forward slashes).
      Also, there should be a comma at the end of the line: ‘tmpdir’: ‘C:\tmp’,

      1. I’m very sorry i forget the comma… and i change the path on ‘C:\DBase’
        Tx for all !

  3. Hello,
    I have any problems with accents and punctuation marks. I made some changes like apikey matched to the french language and other…
    So I find this Python code :

    import unicodedata
    def cleanString(s):
    “””Removes all accents from the string”””
    if isinstance(s,str):
    s = unicode(s,”utf8″,”replace”)
    return s.encode(‘ascii’,’ignore’)

    But I don’t know where i must put it in your one for convert the name before the DBases searchs.

    Sorry I’m not very good in Python…

    1. I’ve made some small changes to the script. The two classes, Serie and Movie, now have a function called _cleanupFileName(name). This function is used to replace characters in the file name before any comparison or inserts in the database. You can use this function to add your own changes to the file name.
      The apostrophes is now replaced by a space. If you have any other modifications, either post the code here, or on GitHub, and I’ll include it in the release.

      1. Although, now that I did include the apostrophe, I’m curious why you want this? Could you give an example of a file name that fails with an apostrophe?
        For example, “python “The King’s Speech.2010.avi” test.jpg” is handled without problems, if the apostrophe is not replaced, but failed when it is.

  4. After leaving my last comment and do some further tests, I’m not so sur it is the apostrophe or the accents that are responsible for the failure.
    Example : “Si c’était vrai”.

    Thanks for new release, I will do my changes and some searchs for adapted the reg ex at my own files.

    Thanks so much for your responsiveness.

    1. Well, there was certainly a problem with the apostrophes, but the problem is not in the script, but in themoviedb api call. For the original movie name, it can search both with and without the apostrophe. E.g. compare:

      Both work. But in your example, the original name is “Just like heaven”. For some reason
      does not work, whilst

      This is now solved in the script, by replacing the apostrophe in both the file name and the movie name by a space. A bit weird but it seems to work.

      1. Hallo Daniel,war bei Saturn und habe mal ein paar Sender in die Favoritenliste gelegt.Dann mit Wippe auf und ab da bin ich nicht in der Favoritenliste geebelbin, bin gleich in die grosse Liste aller Sender zurfcckgekommen. (Sender war in normaler Liste die 10, wurde in Favoriten gelegt, dann Wippe hoch Sprung auf Sender 11 in der normalen Liste)Wenn ich Dich richtig verstehe man sagt dann also Favoritenliste ist die normale default Liste, dann springt man nicht in die grosse Liste mit allen Sendern zurfcck, sondern bleibt in den Favoriten?Man kf6nnte auch eine extra Liste anlegen nur ffcr Radiosender?Bei Saturn kann man halt nicht alles testen, andere wollen auch mal. . )Danke Dir,Uli

  5. Hello,
    I did a lot of research even if I am a beginner in Python, and I just finished this :

    def _cleanupFileName(name):
    name = re.sub(‘[%s]’ % re.escape(string.punctuation), ‘ ‘, name)
    name = unicode(name,”latin1″,”replace”)
    return unicodedata.normalize(‘NFKD’, name).encode(‘ascii’,’ignore’)

    This function replaces punctuation by spaces and removes the accents.

    My E.g. :

    It is the same as your example works with my own apikey (FRENCH). About the selection of the thumbnail, I changed to “backdrop” followed by “thumb” (16/9 better on my Samsung Plasma).

    C U

  6. def _cleanupFileName(name):
    name = name.lower()
    name = re.sub(‘[%s]’ % re.escape(string.punctuation), ‘ ‘, name)
    name = unicode(name,”latin1″,”replace”)
    return unicodedata.normalize(‘NFKD’, name).encode(‘ascii’,’ignore’)


    1. def _cleanupFileName(name):
      name = name.lower()
      name = re.sub(‘[%s]’ % re.escape(string.punctuation), ‘ ‘, name)
      name = unicode(name,”latin1″,”replace”)
      name = unicodedata.normalize(‘NFKD’, name).encode(‘ascii’,’ignore’)
      name = name.strip()
      return name

      Is better like this.

    2. Definitiv schickes Teil Ich hab den TV in 37 in meeinm Wohnzimmer stehen. Der USB-Anschluss wird in Verbindung mit meiner externen Festplatte recht oft genutzt. Aber ganz ehrlich: Den Lan-Anschluss habe ich zwar getestet aber wirklich nutzen tu ich ihn nicht, zumal ich auch fcber die XBOX streamen kann!

  7. hi, Daniel

    video scraper is not work witch this output:

    Error in making symbolic link folders
    Traceback (most recent call last):
    File “”, line 664, in
    File “”, line 136, in main
    movie = Movie(sys.argv[1])
    File “”, line 381, in __init__
    File “”, line 484, in _parseFileName
    if self._getMovieDBThumbnail(, self.year):
    File “”, line 414, in _getMovieDBThumbnail
    File “/usr/local/lib/python2.7/xml/etree/”, line 657, in parse
    self._root = parser.close()
    File “/usr/local/lib/python2.7/xml/etree/”, line 1655, in close
    File “/usr/local/lib/python2.7/xml/etree/”, line 1507, in _raiseerror
    raise err
    xml.etree.ElementTree.ParseError: no element found: line 1, column 0

    Please help.

    1. I’ve updated the script to use v3 of TheMovieDB API. The script should work again for movies. Please get the newest version from GitHub.

  8. Hi Daniel,

    Using instructions above I configured Twonky to use FFmpeg.
    How to configure it to automatically use tw-video-scraper instead of ffmpeg?

  9. Hi, need to understand what is going wrong. Trying to install over a QNAP TS-212. Where does scraper pur logs?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.