GrabDuck

TwonkyServer or Twonky using UPnP, DLNA and DTCP-IP

:

Universal Plug and Play (UPnP) is a set of networking protocols that permits networked devices, such as personal computers, printers, Internet gateways, Wi-Fi access points and mobile devices. The Digital Living Network Alliance (DLNA) uses UPnP for media management, discovery and control and it defines interoperability guidelines to enable sharing of digital media between multimedia devices. In other words, UPnP defines the type of device like "server", "renderer" and "controller" that DLNA supports and the mechanisms for accessing media over a network.

A UPnP AV media server like Twonky is a UPnP-server that provides media library information and streams media-data (like audio/video/picture/files) to UPnP clients on the network that could be a TV, Internet Radio or an mobile phone. The TwonkyMedia server is a DLNA-compliant UPnP AV server software and meets DTLA (Digital Transmission License Administrator). It supports DRM (Digital Rights Management) and DTCP-IP (Digital Transmission Content Protection over IP) to download protected media and runs on Linux, Mac OS X and Windows as well as Android, iOS, and other mobile platforms.

Twonky is able to share media files to any UPnP client on your local-network. The UPnP client can then play those media files if it supports those codecs/container formats. If this is not the case, TwonkyServer is able to transcode the format, which fits the clients codecs (e.g. mp3 to wav). Furthermore, twonky server supports DLNA protected streaming, where DTCP-IP is mandatory for protected media, that has to be implemented in your DLNA client. In this article, I want to show how you can easily install Twonky Server under Ubuntu. I prepared an Twonky Server Installer for Ubuntu and uploaded it on the Ubuntu Launchpad PPA. Furthermore, I want to use this page to publicate my experience with Twonky Server.

Tools Overview

Twonky has a really, really, really, really bad end customer support. X years ago they had a great customer support but since it is bought by PacketVideo (PV) you can forget it completely. No answers on emails, the forum is dieing because of missing moderator's and other plattforms rather than x86 (32bit) are not supported officialy. The focus lies on OEM (NAS etc.) and end customer are lost at PV. They have no documentation for all these tools and functions but on the other side it is still the best UPnP-Media-Server on the market and it is still under development. For example, a Twonky 8 Webcast is already online, where PV shows the latest features of the cloud-enabled Twonky SDK for OEMs. In 2014, I found a PDF where some functions are described:

Twonky tuner integration enables customers to control, schedule, record, and play broadcast video, unifying access to and control of premium and user content (I don't know how, but the service exists).

Twonky SSDP uses the Simple Service Discovery Protocol (SSDP), which is a network protocol based on the Internet Protocol Suite for advertisement and discovery of network services and presence information.

Twonky WebDAV syncs content to mobile devices. It uses the Web Distributed Authoring and Versioning (WebDAV) protocol which is an extension of the Hypertext Transfer Protocol (HTTP) that facilitates collaboration between users in editing and managing documents and files stored on servers.

In 2010, PacketVideo became a wholly owned subsidiary of NTT DoCoMo, which sold their North American and European Twonky operations to Lynx Technology in May 2015. Lynx Technology continues the development of the Twonky software platform for its customers around the world, including North America, Europe and Asia. In 2015, Lynx Technology stopped the development/sell of Windows based Twonky Manager, which is not a real issue as Ubuntu user ;-). Today, they are optimizing Twonky and releasing some robust versions, which gives the community a good feeling.

Interfaces

HTML

For configuration in your local network:

http://[SERVER]:9000/webbrowse

For remote HTTP over Internet:

http://[SERVER]:9100

Flash

http://[SERVER]:9000

RSS Feed

http://[SERVER]:9000/nmc/rss

JSON Feed

http://[SERVER]:9000/nmc/rss?fmt=json

TwonkyServer from PPA

The TwonkyServer Personal Package Archive (PPA) at launchpad, is a collection of Twonky Tools and Installer that isn't included in Ubuntu by default as well as on the Twonky Homepage.

You can activate this PPA by typing the following command into your shell:

  1. sudo add-apt-repository ppa:moonmaker /twonkyserver

Installation of PPA twonky in Debian

If you are using Debian, you need to install the software-properties-common package for Jessie or python-software-properties package for Wheezy in order to use add-apt-repository at first:

Debian Wheezy and earlier

  1. sudo apt-get install python-software-properties

Debian Jessie and later

  1. sudo apt-get install software-properties-common

Now you are able to insert the following lines in /etc/apt/sources.list with sudo nano etc/apt/sources.list:

  1. deb http://ppa.launchpad.net/moonmaker/twonkyserver/ubuntu wily main

  2. deb-src http://ppa.launchpad.net/moonmaker/twonkyserver/ubuntu wily main

That's all for Debian users. Please follow the common instructions for twonkyserver!

Installation of twonkyserver package

  1. Run: sudo apt-get update and install it with sudo apt-get install twonkyserver
  2. Set run=yes in /etc/default/twonkyserver
  3. Start TwonkyServer with sudo service twonkyserver start
  4. Open your Browser and go to http://127.0.0.1:9000 in order to configure your TwonkyServer

Removing twonkyserver package

  • If you want to remove it but you want to save your database files: Run: sudo apt-get remove twonkyserver

  • If you want to remove it completly: Run: sudo apt-get purge twonkyserver

Problems with ffmpeg in Ubuntu 14.04/14.10

The transitional ffmpeg package has been removed from trusty/Ubuntu 14.04 and will return to the official Ubuntu repositories with Ubuntu 15.04 Vivid Vervet. But you can use Kyril's PPA:

  1. sudo add-apt-repository ppa:kirillshkrogalev /ffmpeg-next

  2. sudo apt-get update

Problems with installation process

Sometimes it happends, that the installation process stopped a message like "/tmp/twonky folder already exists" and it is not possible to install the package. So, please use the following steps:

  • Remove the tmp folder with rm -R /tmp/twonky
  • Remove the package sudo apt-get remove twonky*
  • Install the package again with sudo apt-get install twonkyserver

Good luck! ;-)

Installation of 'twonkyserver-sortfix'

Are you looking for an official or unofficial way to sort files streamed through Twonky DLNA? I had this problems for folders in twonky on my Panasonic TV. So I created another package where these fixes are implemented. You can install this package with

sudo apt-get install twonkyserver-sortfix

After installation you have to start the fix menu with sudo /usr/bin/twonkysortfix. Select your Device and the patch will be installed. If you are missing your fix, please create a diff (patch) and send it to me. I will throw it into the package.

How to create a diff-patch?

The diff and patch commands are used to get differences between original files and updated files in such a way that other people who only have the original files can turn them into the updated files with just a single patch file that contains only the differences. In this example I will show you how you can make a diff-file from Panasonic_VIERA.xml.

At first you have to create a temporary folder, where you have to copy the xml file inside.

  1. mkdir /tmp /twonkytest

  2. cp /usr /share /twonky /resources /devicedb /Panasonic /Panasonic_VIERA.xml /tmp /twonkytest /Panasonic_VIERA.xml.patch

After this step you can start to edit the file /tmp/twonkytest/Panasonic_VIERA.xml.patch. If you are happy with your changes, you can start to create the diff file with:

  1. diff -u /usr /share /twonky /resources /devicedb /Panasonic /Panasonic_VIERA.xml /tmp /twonkytest /Panasonic_VIERA.xml.patch > /tmp /twonkytest /Panasonic_VIERA.xml.diff

The diff-file (Panasonic_VIERA.xml.diff) is looking like this:

  1. +++ /usr/share/twonky/resources/devicedb/Panasonic/Panasonic_VIERA.xml  2013-11-22 17:24:02.000000000 +0100

  2. @@ -47,8 +47,11 @@

  3.                 </MimeTranslations>

  4.         </Adaptations>

  5.         <DeviceQuirks>

  6. -        <Quirk>RES_ADD_FLAG</Quirk>

  7. +               <Quirk>RES_ADD_FLAG</Quirk>

  8.                 <Quirk>SUPPORT_MPG2TS_TIME_SEEK</Quirk>

  9.                 <Quirk>FORCE_4TH_FIELD</Quirk>

  10. +               <Quirk>VIERA_DIVXPROFILE</Quirk>

  11. +               <Quirk>RES_ADD_FLAG</Quirk>

  12. +               <Quirk>IGNORESORT</Quirk>

  13.         </DeviceQuirks>

  14.  </Client>

In order to include your diff-file into the twonkyserver-sortfix package, you have to send the diff-file to me. The best way is to post it on pastebin.com and send me the link by mail.

Installation of 'twonkyserver-transcoding'

TwonkyServer supports transcoding for media types. In order to realize this, Twonky needs a config file to transcoding from one format into another format that is supported by your Client (Tv, Radio etc.). At first you have to install the package with

sudo apt-get install twonkyserver-transcoding

After installation you have to look into /etc/twonky/cgi-bin in order to activate the transcoding script. The following transcoding scripts are available:

From Media Type To Media Type Script
alac wav alac-wav.desc
all (ts, avi..) mpeg, mpg ffmpeg-all-mpeg.desc
divx (avi) mpeg, mpg ffmpeg-divx-mpeg.desc
mkv mpeg, mpg ffmpeg-mkv-mpeg.desc
flac wav flac-wav.desc
mov mpeg2 vlc-mov-mpeg2.desc
wma mp3 vlc-wma-mp3.desc

Here you can find an example:

  1. exec: vlc $infile --novideo :sout=#transcode{acodec=mp3}:duplicate{dst=std{access=file,mux=ffmpeg,dst=$outfile}} vlc:quit

  2. from=audio/x-ms-wma

  3. to=audio/mpeg

  4. asynchronous

  • exec - Command that starts the transcoding. Variable $outfile and $infile stands for the file
  • from - Source media type
  • to - Destination media type

TwonkyServer Start-/Stop-Script

You can manage your Twonky Server by using the Start-/Stop-Script with

sudo service twonkyserver {start|stop|status|restart|rebuild}
  • start: Start Twonky Server
  • stop: Stop Twonky Server
  • restart: Restart Twonky Server
  • rebuild: Rebuild the Twonky Server Database and restart it

For example:

sudo service twonkyserver restart

Playlists

  • Playlists that contain URLs starting with "http://" do not work. If you have playlists that heavily rely on such URL, you may want to defer the update till the next version.

Internet Radio Playlist

You can use the windows play list (WPL) format:

  1. <?wpl version="1.0"?>

  2. <smil>

  3.     <head>

  4.         <meta name="Type" content="M"/>

  5.         <title>some shoutcast channels </title>

  6.     </head>

  7.     <body>

  8.         <seq>

  9.             <media src="http://yp.shoutcast.com/sbin/tunein-station.pls?id=20594" title="Radio ZU Live"/>

  10.             <media src="http://yp.shoutcast.com/sbin/tunein-station.pls?id=816" title="Joy Turk"/>

  11.             <media src="http://yp.shoutcast.com/sbin/tunein-station.pls?id=1278832" title="Mostly Classical - S K Y . F M"/>

  12.         </seq>

  13.     </body>

  14. </smil>

Save it as myradio.wpl.

Since TwonkyServer Version 7.x.x it's possible to beam a video via Uniform Resource Locator (URL) to your Client. The Syntax is looking like this: x.x.x.x:9000/beam?renderer=[BOOKMARK]&url=[URL]

  • [BOOKMARK] is the twonky boomark or the ip address of the client
  • [URL] is the url of the item to be beamed

Beaming a Youtube video via TwonkyServer

Beaming a video from your local server to a client is looking like this:

http://[SERVER]:9000/nmc/rpc/beam?renderer="[CLIENT]"&url=[VIDEO_URL]
  • [SERVER] is the twonkyserver IP/Domain
  • [CLIENT] is the UPNP Client
  • [VIDEO_URL] is the Internet Video URL

Here you can find an example:

http://192.168.1.2:9000/nmc/rpc/beam?renderer="192.168.1.3"&url=http://www.youtube.com/watch?v=_g4yjktCDyo
  • [SERVER]= 192.168.1.2
  • [CLIENT]= 192.168.1.3
  • [VIDEO_URL]= http://www.youtube.com/watch?v=_g4yjktCDyo

Twonky Port Settings

When you use a firewall you change the way to communicate with other online services. The firewall blocks all incoming and/or outcoming traffic unless you open a port in the firewall (e.g. iptables) to let a specific IP communicate with your twonky server. In the following table you can find the Twonky Server port numbers:

Protocol Port Type Network Argument in Config Description
HTTP 9000 TCP Home httpport=9000 Port of the HTTP server
WebDAV 9090 TCP Home webdavport=9090 WebDAV Port (abandoned since 7.2.0)
SSDP 1900 UDP Home ssdpheartbeatport=1900 Port number for the SSDP heartbeat
HTTP (remote) 9100 TCP Internet httpremoteport=9100 Http server port for remote access
HTTP (tuner) 9003 TCP Home twonkytuner_port=9003 The TwonkyTuner's HTTP port
DLNA DTCP-IP 40000 UDP Home DTCP-IP is integrated into the DLNA specification

You can change the remote port by using the following RPC command:

http://[SERVER]:9000/rpc/set_option?httpremoteport=9100

Remote Access

You have to set various parameters in your /etc/twonky/twonkyserver.ini in order to enable remote access:

  1. # access to web config pages, 0 for denied, 1 for local only, 2 for open

  2. enableweb =

  3.  

  4. # enable https remote connections

  5. enabletls =

  6.  

  7. # http server port for remote access

  8. httpremoteport =

  9.  

  10. # dynamic dns prefix for remote access, including http:// or https://

  11. dyndns =

  12.  

  13. # enable remote access

  14. remoteaccess =

  15.  

  16. # for protection of the web config pages

  17. accessuser =

  18.  

  19. # for protection of the web config pages

  20. accesspwd =

  21.  

  22. # dynamic dns prefix for remote access, including http:// or https://

  23. dyndns =

Alternatively you can set these parameters by using the RPC command interface:

  • http://127.0.0.1:9000/rpc/set_option?enableweb=2
    There should be no need to change this setting, by Default this setting = 2.
    NOTE: If set to anything other than 2, remote access will not work.
  • http://127.0.0.1:9000/rpc/set_option?enabletls=0
    By Default this setting = 1. This value means, that only HTTPS connections will work. If you intend to use HTTP for remote access, it must set to 0.
    NOTE: it appears the HTTPS isn't working as expected, so we are forced to use HTTP.
  • http://127.0.0.1:9000/rpc/set_option?httpremoteport=9100
    By default this setting has no value, also by default the internal port for Twonky is 9000. Therefore, you can use that option for the remote access port.
  • http://127.0.0.1:9000/rpc/set_option?dyndns=http://myserver.dyndns.com By default this setting has no value. The value uses here is what is used in the links generated by twonky for remote access.
    NOTE: if enabletls=1, you must use HTTPS, if not use HTTP.
    NOTE: since enabletls=1 isn't working correctly, enabletls=0 is needed.
  • http://127.0.0.1:9000/rpc/set_option?remoteaccess=1
    By default this setting has no value, meaning its not enabled. This must be set to = 1 for remote access to work.

Add a remote access user:

  • http://127.0.0.1:9000/rpc/set_option?accessuser=someusername - HIGHLY RECOMMENDED
  • http://127.0.0.1:9000/rpc/set_option?accesspwd=somepassword - HIGHLY RECOMMENDED

After this, you have to restart your server.

Access twonky server over internet by using HTTPS

If you have some problems with the HTTPS certificate, you can use HaProxy in combination with a DynDNS provider. Please have a look at my tutorial SSL Certicate for HAProxy, where I describe how you can buy and configure a cheap and secure certificate from GOGETSSL. Furthermore, in my tutorial Dynamic DNS you can find a solution for continuously refreshing your domain with a new IP address.

Database property items

Item Description
upnp:class UpnP class of the item
dc:creator Primary content creator or owner of the object
dc:date The date of the item YYYY-MM-DD
dc:description The description of the item
dc:title Main title of the item
pv:orientation Picture orientation
bitrate Bitrate in bytes/seconds of the encoding of the resource
bitrateConstant Flag to indicate constant or variable Bitrate
bitsPerSample Encoding characteristic of the resource
chapterDuration Chapter duration in ms
chapterFile Filename of a DVD chapter (.vob)
chapterNumber Chapter number
chapterOffset Byte offset at the vob
colorDepth Encoding characteristic of the resource.
duration Time duration of the playback of the resource
pv:extension File/url extension
mimeType The mime type of the item (if not auto detected)
nrAudioChannels Number of audio channels
resolution The resolution of the item (width x height)
sampleFrequency Sample frequency of the audio in HZ.
size Size in bytes of the resource
subtitle If subtitle file (.srt/.sub/.txt/.smi/.ssa/.psb/.ass ) exists for this movie (same filename as movie file except extension) set this to the filename
pv:addedLast60 Set to 1, if added in last 60 days - auto calculated property!
pv:addedTime Timestamp when the item was added (unix time)
upnp:albumArtURI Object ID where the albumart is related - for containers only!
pv:albumArtLength Length of album art - if there / for pictures used for thumbnails!
pv:albumArtOffset Offset to album art - if there / for pictures used for thumbnails!
pv:albumArtResolution XxY resolution of the albumArt in pixels (typically image item or video item).
pv:aspectRatio The aspect ratio of the item
pv:compilation Set to 1 if we have a compilation item
pv:sort Default sort criteria for container
pv:highrated Set if rating >4 - auto calculated property!
pv:lastPlayedTime YYYY-MM-DD
pv:lastUpdated The unix time when the db entry of the item was last updated
pv:modificationTime The the modification time of the item (on disc) (Unix time)
pv:rating Value between 1 (don’t like) to 5 (like)
pv:playcount Number of times an item was played
upnp:actor Name of an actor appearing in a video item
upnp:albumArtist Album Artist
upnp:album Title of the album to which the item belongs.
upnp:artist Name of an artist - always use with role=Performer here
upnp:author Name of an author - always use role=Composer here
upnp:genre Name of the genre to which an object belongs
upnp:originalTrackNumber Original track number on an audio CD or other medium

Other Commands

  • Twonky NMC Test-Tool http://[SERVER]:9000/resources/nmc.html and http://SERVER]:9100/resources/nmc.html
  • Twonky DTCP-IP Test http://[SERVER]:9000/resources/dtcpupload.htm
  • Latest TwonkyServer Status using RPC http://[SERVER]:9000/rpc/info_status
  • See what is currently streaming by using RPC http://[SERVER]:9000/rpc/stream_info
  • Set config option using RPC http://[SERVER]:9000/rpc/set_option?CONFIGOPTION=VALUE
  • Rebuild the database using RPC http://[SERVER]:9000/rpc/rebuild
  • Clear Cache by using RPC http://[SERVER]:9000/rpc/clear_cache
  • Show Twonky Config by using RPC http://[SERVER]:9000/rpc/get_all