Ok, so it’s not really virtualisation related but I thought it needed writing down somewhere.

I have a QNAP NAS at home. I don’t really use it in my home lab for hosting VMs. I prefer to use EMC’s VSA for that. I do use it to store templates, ISO files and other software along with all of my digital media and documents etc.

One of the features that comes built in with most QNAP devices is a UPNP Media Server, which is actually a repackaged version of Twonky. When enabled it allows me to stream video content from the QNAP to my blu-ray player and watch it on a decent sized screen. It works well with DivX AVI files but it wasn’t happy with several other formats. I put it down to a lack of support from my blu-ray player but then I came up with a reason to dig deeper.

I received a video of a family event the other week and the file was in an MKV format (or container). Although it showed up when I pointed the blu-ray player at it, when I tried to play the file not a lot happened. At least not at first. After about 30 seconds a 2 second clip of the video played before pausing for another 30 seconds. This probably would have carried on the for the entire duration if I’d let it.

A few minutes later I became aware that the fan in the QNAP had started to run at its maximum speed. After a quick SSH connection was established I could see that the process “ffmpeg” was pegging the CPU of the NAS.

So, what was happening was that the Twonky Media server was trying to transcode on-the-fly into a format that it felt comfortable serving to my blu-ray player. The CPU in the NAS is just not up to that job!

That left me with two options. The first was to manually transcode the file on another computer into a format that would work. This would certainly do the job but would also mean a loss in quality and, in the event that I get lots more MKV files, be a pain to have to do over and over again.

The second option, the one I chose, the harder one, was to sort the problem out. This is what I did with my afternoon off on Tuesday!

First things first. Sony’s documentation for my blu-ray player (a BDP-S370).

There seems to be some fairly broad support for different video file formats. The important thing is that MKV is a container and not a codec. As long as the blu-ray player is capable of playing the contained video, it shouldn’t be too difficult working with the container format. However, DivXHD is apparently not supported using DLNA. I won’t let that stop me though. It plays normal DivX files perfectly well.

Next up, looking at the media server. There’s plenty of people who have bemoaned the lack of support for MKV files in Twonky it would seem. And while it’s easy enough to turn it off, I’d need to replace it with something.

I looked at MediaTomb and a couple of other efforts but there seemed to be a lot of compiling required for some of them and I didn’t want to clutter my NAS up with lots of compilers and libraries. It’s there to server files primarily, the rest is a bonus. It’s certainly not supposed to be a development platform.

Finally I discovered that a later version of Twonky (6.x) could be installed instead of the bundled version (5.x). Looking into this it was quite straight forward.

QNAPs have a plugin system called QPKG that allows some extra functionality to be added to the NAS. A selection of packages can be installed very simply using the web-based admin utility.

Simply navigate to “Application Servers > OPKG Plugins” in the QNAP admin GUI and click the “GET QPKG” button to be shown the list of available plugins.

After selecting, downloading and installing the correct package it can then simply be enabled. Doing so even automatically disables the built-in version of Twonky.

Sadly this didn’t fix things. You could even say that it made them worse. Before the MKV file had at least shown up, now it was nowhere to be seen by the blu-ray player.

A bit more googling found a solution for me though. It seems that if we change the MIME type of MKV files as far as Twonky is concerned, the blu-ray player will find the file and should be able to play it.

The first step in doing this is determining what user agent Twonky detects the blu-ray player as being. As you might have noticed, Twonky has a config GUI that runs on port 9000 by default. One of the views available shows connected Media Receivers.

The important value is the highlighted one. Effectively it matches a profile of sorts in Twonky’s configuration.

Via an SSH connection to the NAS, the configuration for the profile can be changed. To do this you need to edit the file /share/MD0_DATA/.qpkg/TwonkyMedia/resources/clients.db with vi or your favourite text editor.

Searching through the file I found the profile that matched the name above:

[plain]>>
NA:Sony Blu-Ray Player
HH:Blu-ray Disc Player
XM:DLNA15
TR:JPEGORG,JPEG160x160,JPEG640x480,JPEG1024x768,JPEG1920x1080
DB:AUTO[/plain]

To change the MIME type of MKV files simply add the following line to the end:

[plain]MT:mkv video/divx[/plain]

You should now have something like this:

[plain]>>
NA:Sony Blu-Ray Player
HH:Blu-ray Disc Player
XM:DLNA15
TR:JPEGORG,JPEG160x160,JPEG640x480,JPEG1024x768,JPEG1920x1080
DB:AUTO
MT:mkv video/divx

>>[/plain]

Save the changed file and restart Twonky by issuing the command:

[plain]/etc/init.d/twonkymedia6.sh restart[/plain]

Just like that my blu-ray player could play MKV files. It’s not perfect. Playback is smooth but seeking (fast forward or reverse playback) doesn’t work very well. It’ll do for my purposes though.

33 comments on “QNAP NAS and Twonky Media Server”

  1. bughead Reply

    I also had problems with playing .mkv files. But I discovered that restarting the twonky server resolved the problem…for one day or so. Then it returned (I got the unsported file format message). Strange, but true.

    But thanks to this post I discovered the command to restart the twonky server. So I’ve created a cron job that restarts the server every night at five o’clock. And that worked!
    It’s not the best solution, but I am happy with it for now.

    This is the cronjob command I added:

    0 5 * * * /etc/init.d/twonkymedia6.sh restart

    Thanks for your post Michael.

  2. Billy Reply

    Hi Micheal I have the Sony BDP-S390 player and cannot play any video file format from Twonky on my QNAP. I receive this error “The file is corrupt or unsupported”
    I can stream any file via Windows Media Player or via USB direct on the Sony. Photos & music work fine.
    Does your solution apply to the error I get? Thanks in advance.

    • vspecialist Reply

      Yes, I used to see that as well. I think I used to get it with MKV files before I applied the changes above.
      It’s worth pointing out that the version of Twonky in use now is different so there may be some changes required to the instructions. It’s been a while since I did this πŸ™‚

  3. Pingback: Twonky Media Server and MKV - The Dragonflame

  4. gulf917 Reply

    Hi, I am a newbie here and with QNAP NAS systems. I understand this thread is a little old now, however, any help would be very much appreciated and I thank you all in advance.
    The trouble I am experiencing is when trying to stream music, photos or even video to my PS3 or my Sony Bravia TV.
    Both units are just over a year old and I have a brand new QNAP 412 Turbo NAS.
    I am using Twonky Media and every time I try to access the file within any of my libraries, ( music, photo or video.), it recognises the file , however, nothing plays..? No sound and or no image..?
    Within my music library similar happens, it can see the file, but, once I ask for the music to play it comes up with a no file error message…!
    I am wondering if carrying out the above instructions that Michael posted will this help me view my files?
    If so, could someone please tell me where to find and how to access the “database file” , being a newbie and “idiots guide” approach would be very beneficial to me..!
    If not, does anyone know the fix..?
    I thank you in advance.
    Kind regards,
    D

    • vspecialist Reply

      It’s got to be worth a try. Sounds similar to the experience that I had and described above. However, your success will depend on how comfortable you are with UNIX based / command line changes as you’ll need to do those. It’s not really a newbie procedure. I don’t have a PS3 or Bravia TV so I can’t give you a blow-for-blow set of steps to follow. As such I can give you the high level steps.
      1. Disable the existing version of TwonkyMedia through the admin interface (look at “Application Servers” > “UPnP Media Server” (this is necessary because the clients.db file in the built in version gets overwritten automatically at boot time I believe) 2. Install Twonky through the “QPKG Center”, again it’s under the “Applications Servers” section in the admin interface. 3. Make sure to enable the plugin.
      4. Follow the instructions in the article above to view http://nasserver:9000 and work out what profile your Bravia and PS3 are connecting as. 5. Edit your clients.db file as described above to add any required MIME types. You’ll need to do this by connecting via SSH to the NAS. The clients.db file (on my NAS) is located at /share/MD0_DATA/.qpkg/TwonkyMedia/resources. I use “vi” to edit the file – it’s just a text file. If you’ve not used it before you’ll probably struggle. Like I said, this isn’t really a newbie procedure. 6. You’ll need to restart Twonky to have the chnages take effect (/etc/init.d/twonkymedia6.sh restart).
      Have you also tried searching the QNAP forum (forum.qnap.com) for issues specific to the Bravia and PS3?

    • vspecialist Reply

      Mine is at /share/MD0_DATA/.qpkg/TwonkyMedia/resources/clients.db

      I’m using TwonkyMedia installed through QPKG and not the built in version.
      Michael

  5. AtGnat8 Reply

    I have read through all of these comments and I am still unable to play mkv with my PS3. I added the “MT:mkv video/divx” line to the end of the PS3 section in clients.db and restarted the server with the Twonky app config gui interface.

    TS-419P II with latest firmware (3.6.1)
    TwonkyMedia 6.0.38

    Thanks for any help!

    • AtGnat8 Reply

      I now have it playing about a minute and a half of my mkv’s, but then stops and there is no audio.

      • Anonymous Reply

        That sounds like the PS3 doesn’t like MKV files perhaps. I don’t actually have one myself to try it out.

  6. Pingback: Script Installation

  7. Pingback: my pc login

  8. Anonymous Reply

    Thanks for this! Worked perfectly and my Sony S370 now sees and plays my MKVs. Having upgraded to the latest QNAP firmware, TonkyMedia 6 is now the standard install so need to install as a QPKG. That means that the clients.db file is in /mnt/ext/opt/twonkymedia/resources, and you can restart the TwonkyMedia once you have edited the file by disabling and reenabling it in the QNAP web interface.

    • Anonymous Reply

      Although I’ve updated my firmware recently, I hadn’t twigged that Twonky had been updated. Thanks for the info. I might have to try it out.

      Michael

      • Anonymous Reply

        I updated to the latest firmware again, and of course it overwrote the change the clients.db – minor hassle but irritating nonetheless. Has anyone tried going back to TwonkyMedia and getting them to fix the problem at source?

        • Anonymous Reply

          That’s annoying. I didn’t know about that. I might drop a message on QNAP’s forum and see what they say.

  9. Pingback: Bluray DVD Player

  10. thibs Reply

    I have a Bravia KDL-40EX501 TV and TMS 6.0.33.
    I am not able to see the AVI files. Since 1 month I search on google without success.
    I find your post and this is the first one I see about this clients.data … interesting. I will dig on this, but if you have any suggestion…

    • Michael Reply

      All I can suggest is that you try and do the same (or similar) to what I did. Look in the TMS web gui to find out what Twonky “sees” your Bravia as and then adjust the clients.db file accordingly. You might need to experiment a bit.
      Depending on how comfortable you are with SSH and command lines you may want to experiment a bit.

  11. Blakey Reply

    Bah! video/mpeg doesn’t work either. TV isn’t even seeing the files. PS3 sees them, knows they are video but says they are corrupt when I try to play them.

    Any ideas appreciated!

  12. Blakey Reply

    Hi,

    At home and tried it. Update was easy – thanks for the instructions. Editing the clients.db was easy (I’m a linux admin for work so very happy inside the QNAP).

    However, after making the changes and restarting the twonky service, still no luck playing the files on the PS3 or TV.

    If I use mkv2vob on them and repackage them as mpg files they play fine. So the content is recognisable to the PS3/TV. I’m now wondering if I should be using video/mpeg as my MIME type but it’s getting late…

    Deffo determined to get this to work though!

    Blakey

  13. Michael Reply

    No problem. I’m at work too πŸ™‚

    The video containers are very confusing. It took me quite a bit of digging in google to get anywhere near understanding what was going on. I’m still a bit lost really.

    My understanding (from a QNAP forum post I think) is that with the bundled TMS the clients.db file is overwritten at boot time.

    If you install the later version it drops into a different area that is not volatile.

    I tried renaming files too and that had exactly the same effect, they just disappeared.

    One thing that you have to do if you update TMS is set it up to start automatically as it doesn’t do this by default. I haven’t done this yet but that’s more through laziness πŸ˜‰ It’s simply a matter of linking the .sh script in /etc/rc.d or whatever the path is.

    Good luck. Hope it all works.

  14. Blakey Reply

    Thanks for the swift answer Michael. I’m at work now but aiming to try this tonight. I think I’ll update the TMS anyway – might as well have the later version running.

    Are you saying that a reboot will always clear the clients.db file out by the way? Meaning this change needs to be done on every reboot?

    Also, I read somewhere that maybe just renaming the .mkv files to .wmv (for example) would work. I tried it and the TV stopped seeing the files at all, so I’m not sure that is a starter.

    I have to admit all this video containers etc confuses me!! πŸ™‚

    Blakey

  15. Michael Reply

    Blakey,

    In fairness, updating to the latest TwonkyMedia was the first step in trying to work out what was going on. It’s possible that you could make the older version work.
    The catch though is that the bundled version of TwonkyMedia (or at least the clients.db file) lives in an area that I think gets refreshed each reboot meaning that you either lose your changes or you have to come up with a way to get around that.
    That said, the method for finding out what your PS3 or BRAVIA TV connect as should be more or less the same. The older version has a web gui too I think. Try the same MIME type and see if that works is all that I can suggest.
    Michael

  16. Blakey Reply

    Hi Michael,

    I’ve just come across this page – very informative. One question for you: do you think it’s required to upgrade to the latest Twonky Media to get this to work? I’m just trying to do the bare minimum here, so if I can just edit the clients.db file and be done with it then that would be easier…

    Also, any ideas what MIME type I’d need to use for the PS3 or for a BRAVIA Internet TV? I’m assuming that the same type would work but I’m not sure.

    Many thanks for any help you can give me!
    Blakey

  17. joriks Reply

    Just now tried to play some of my Blu-Ray movies that I had ripped/copied (~20GB). And everything wasn’t so nice πŸ™

    At first it took some time to open them but before the picture came on screen there was an error about the audio, that the audio isn’t supported and so on. Strange, but when the picture showed up the audio was there as well. And for 3 seconds I thought that everything will be ok. I was wrong! The picture started to freeze and after second it started to play again, but after 1-2 seconds it freeze again and it was like that all the time. When I pressed Pause and waited for couple seconds then the picture was playing smoothly but again only for couple seconds. For example, if I paused the movie for ~10sec then it would be played smoothly for ~3 sec. So I guess the problem is with decoding. But who is doing all the hard job? TwonkyMedia or Blu-Ray player (I have the same Sony BDP-S370 like you πŸ™‚ )? If the end machine is doing it then I’m really disappointed in my Xbox 360 and his lack of support for mkv files. 360 would be powerful enough to handle it.

    • Michael Reply

      Interesting…

      The intermittent playback is exactly what I got originally with the few MKVs that did show up. What you’ll see if you SSH to the NAS and run “top” is that the transcoding is being done by the NAS (and pegging the CPU at 100%) and it is most definitely *NOT* suited for it.

      I can assure you it does work. The biggest file I have is only 4.3Gb but that shouldn’t matter. I can only suggest running through the steps in the article again and checking for typos or something. I didn’t include things like “vi” editing commands or anything like that but I’m fairly sure I covered all of the steps. I’m no expert on video formats either so there could be an issue there. Have you got any other files you can try it with?

  18. Michael Reply


    joriks:

    I have only one user and that’s admin.
    After spending some time on thinking all the possible ways how to connect to NAS I finally did it! Found that db file, edited it and mkv files are showing up and playing beautifully. I’ve tried to play only small mkv files like music videos. I hope everything will be ok with larger 20+GB movie files too.
    Thank you for saving me money, because I was already starting to look for new NAS or media player with built in mkv support.

    Glad you got it sorted. I’ve had no issue with bigger mkv files (~2Gb) apart from with my Blu-Ray player, if I scan backwards through a file it tends to knock the audio sync out. That could be the fault of the Blu-Ray player though. It’s easy enough to avoid doing πŸ™‚

  19. joriks Reply

    I have only one user and that’s admin.
    After spending some time on thinking all the possible ways how to connect to NAS I finally did it! Found that db file, edited it and mkv files are showing up and playing beautifully. I’ve tried to play only small mkv files like music videos. I hope everything will be ok with larger 20+GB movie files too.
    Thank you for saving me money, because I was already starting to look for new NAS or media player with built in mkv support.

  20. joriks Reply

    I can’t access to the database file.. I’m all the time getting error “cannot access”. Do I have to do some magic to access to that file.

Leave A Reply

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