Free DLNA serv­er which works good with my Sony BRAVIA TV

In sev­er­al pre­vi­ous posts I wrote about my quest for the right source for­mat to stream video to my Sony BRAVIA TV (build in 2009). The last week-end I final­ly found some­thing which sat­is­fies me.

What I found was servi­io, a free UPnP-AV (DLNA) serv­er. It is writ­ten in java and runs on Win­dows, Lin­ux and FreeB­SD (it is not list­ed on the web­site, but we have an not-so-up-to-date ver­sion in the ports tree). If nec­es­sary it transcodes the input to an appro­pri­ate for­mat for the DLNA ren­der­er (in my case the TV).

I test­ed it with my slow Net­book, so that I was able to see with which input for­mat it will just remux the input con­tain­er to a MPEG trans­port stream, and which input for­mat would be real­ly re-encoded to a for­mat the TV understands.

The bot­tom line of the tests is, that I just need to use a sup­port­ed con­tain­er (like MKV or MP4 or AVI) with H.264-encoded video (e.g. encod­ed by x264) and AC3 audio.

The TV is able to chose between sev­er­al audio streams, but I have not test­ed if servi­io is able to serve files with mul­ti­ple audio streams (my wife has a dif­fer­ent moth­er lan­guage than me, so it is inter­est­ing for us to have mul­ti­ple audio streams for a movie), and I do not know if DLNA sup­ports some­thing like this.

Now I just have to replace minidl­na (which only works good with my TV for MP3s and Pic­tures) with servi­io on my FreeB­SD file serv­er and we can for­get about the disk-juggling.

Sony BRAVIA TV & DLNA formats

As I wrote ear­li­er, I try to get some infos which for­mats my Sony BRAVIA 5800 TV is able to play over the net­work. Sony is not real­ly help­ful (they tell only names some­one with a DLNA spec could cor­rect­ly inter­pret). Now I took the time to move my TV into a dif­fer­ent sub­net (the same where my NAS is in, not like before in a DMZ), and I installed minidl­na. After some net­work sniff­ing, the use of the Intel UPnP Device Spy and some minidlna-source read­ing I have now a bet­ter idea what my Sony TV expects.

The DLNA-specification seems to man­date a MIME-type and some DLNA-specific iden­ti­fi­er which describes the con­tent a play­er (a DLNA-Renderer) is able to dis­play. In the fol­low­ing I will present the MIME-type, the DLNA-identifier, and prob­a­bly a Sony-specific identifier.

Regard­ing pic­tures the TV only accepts JPEGs, bit in small, medi­um and large sizes. I did not both­er to look up what this means in real val­ues, so far this is not of high inter­est for me. For audio the TV accepts MP3s and LPCM (raw PCM sam­ples). The raw sniffed data from the TV looks like this:

image/jpeg:DLNA.ORG_PN=JPEG_SM
image/jpeg:DLNA.ORG_PN=JPEG_MED
image/jpeg:DLNA.ORG_PN=JPEG_LRG
audio/mpeg:DLNA.ORG_PN=MP3
audio/L16:DLNA.ORG_PN=LPCM

The more inter­est­ing part for me is the video part. The TV sup­ports MPEG2 Video (the MPEG_ part in the DLNA.ORG_PN) and H.264 (the AVC_ part in the DLNA.ORG_PN). For MPEG2 it sup­ports pro­gram streams (PS in DLNA.ORG_PN) and trans­port streams (TS in DLNA.ORG_PN). For PS it sup­ports PAL and NTSC res­o­lu­tions (720×576 is PAL, HD res­o­lu­tions like 720p or 1080i or 1080p are not sup­port­ed). The packet-length of a trans­port steam can be 188 bytes or 192 bytes. If the width is >= 1288 or the height is >= 720, minidl­na adds HD in DLNA.ORG_PN, else it will add SD. The EU in DLNA.ORG_PN is for SD video with a height of 576 or 288 pix­els. Depend­ing of the com­bi­na­tion of the packet-length and if there is a time­stamp in use or not, the DLNA.ORG_PN will have a _ISO or a _T appended.

It also sup­ports H.264. The DLNA.ORG_PN starts with a AVC in this case. Only trans­port streams (TS  in DLNA.ORG_PN) is sup­port­ed. As with MPEG2, the packet-length of the TS can be 188 or 192 bytes. Depend­ing of the com­bi­na­tion of the packet-length and if there is a time­stamp in use or not, the DLNA.ORG_PN will have a _ISO or a _T append­ed. Depend­ing on the pro­file used, minidl­na adds some more infos to the DLNA.ORG_PN, BL if it is a baseline-profile, MP if it is a main-profile, and HP if it is a high-profile. I do not see this in the valid video for­mats my TV request­ed over the wire. As with the MPEG2 for­mat, SD or HD is added (in minidl­na) depend­ing on the width and height, but also on the bitrate of the video. For the main-profile the width has to be <= 720, the height <= 576 and the bitrate <= 10M (base 10, not base 2) for SD, and the width has to be <=1920, the height <= 1152 and the bitrate <= 20M (base 10, not base 2) for HD. For the high-profile the width has to be <=1920, the height <=1152, the bitrate <= 30M (base 10, not base 2) and the audio has to be AC3 to get the HD added in DLNA.ORG_PN. The audio is spec­i­fied in DLNA.ORG_PN as MPEG1_L3 for MP3, AC3 for AC3, and AAC or AAC_MULT5 for AAC (stereo or 5‑channel). As can be seen below, the TV seems only to sup­port AC3 audio for AVC. The TV also has _24_, _50_ and _60_ in DLNA.ORG_PN. I did not find those things in the minidl­na source (but I have not real­ly searched for this). I could imag­ine that _24_ stands for 24 pic­tures per sec­ond, and the _50_ and _60_ for pro­gres­sive videos (with 50 respec­tive­ly 60 pic­tures per sec­ond), but this is pure spec­u­la­tion from my side. Here is the raw sniffed data:

video/mpeg:DLNA.ORG_PN=AVC_TS_HD_24_AC3_ISO;SONY.COM_PN=AVC_TS_HD_24_AC3_ISO
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=AVC_TS_HD_24_AC3;SONY.COM_PN=AVC_TS_HD_24_AC3
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=AVC_TS_HD_24_AC3_T;SONY.COM_PN=AVC_TS_HD_24_AC3_T

video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_PS_PAL
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_PS_NTSC

video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_TS_SD_50_L2_T
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_TS_SD_60_L2_T
video/mpeg:DLNA.ORG_PN=MPEG_TS_SD_EU_ISO
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_TS_SD_EU
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_TS_SD_EU_T
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_TS_SD_50_AC3_T
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_TS_SD_60_AC3_T
video/mpeg:DLNA.ORG_PN=MPEG_TS_HD_50_L2_ISO;SONY.COM_PN=HD2_50_ISO
video/mpeg:DLNA.ORG_PN=MPEG_TS_HD_60_L2_ISO;SONY.COM_PN=HD2_60_ISO
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_TS_HD_50_L2_T;SONY.COM_PN=HD2_50_T
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_TS_HD_60_L2_T;SONY.COM_PN=HD2_60_T

video/mpeg:DLNA.ORG_PN=AVC_TS_HD_50_AC3_ISO;SONY.COM_PN=AVC_TS_HD_50_AC3_ISO
video/mpeg:DLNA.ORG_PN=AVC_TS_HD_60_AC3_ISO;SONY.COM_PN=AVC_TS_HD_60_AC3_ISO
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=AVC_TS_HD_50_AC3;SONY.COM_PN=AVC_TS_HD_50_AC3
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=AVC_TS_HD_60_AC3;SONY.COM_PN=AVC_TS_HD_60_AC3
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=AVC_TS_HD_50_AC3_T;SONY.COM_PN=AVC_TS_HD_50_AC3_T
video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=AVC_TS_HD_60_AC3_T;SONY.COM_PN=AVC_TS_HD_60_AC3_T

video/x-mp2t-mphl-188

So far I did not get the time to exper­i­ment with this. I also have the impres­sion that minidl­na has still some rough edges (the sin­tel video I used to test before with a dif­fer­ent media serv­er, does not show up in the list with minidlna).

Stream­ing video to a Sony Bravia (via DLNA)

I have a Sony Bravia TV with a net­work (eth­er­net) con­nec­tion. Let­ting aside the fact that he is in anoth­er sub­net than my NAS and as such I can not use a DLNA (UPnP-AV) serv­er (it is using mul­ti­cast and the Sim­ple Ser­vice Dis­cov­ery Pro­to­col (SSDP) which is not tra­vers­ing sub­nets in the WLAN-LAN-ADSL-router I use), there is no good expla­na­tion from Sony what I can feed to the TV.

When search­ing the net I can find some obscure sug­ges­tions and descrip­tions, but not all of them work for all peo­ple which try them. So it seems I have to research this myself. Luck­i­ly my router has a build-in UPnP-AV serv­er which I can use to play around (the file size is lim­it­ed to the size of the USB mem­o­ry stick I have con­nect­ed to the router, as he can not stream con­tent which is avail­able in a NAS in the network).

Sony tells the TV is able to receive MPEG2 TS and PS con­tain­ers. MPEG2 PS is more or less what you have on DVD. It is able to play SD and HD con­tent from the PS con­tain­er, and the video for­mat needs to be MPEG2. They do not explain what SD or HD means in this con­text (the valid res­o­lu­tions), and they do not tell what kind of audio is allowed.

For the MPEG2 TS con­tain­er they addi­tion­al­ly allow H.264 video, and they spec­i­fy EU, EU‑T and EU-ISO as sup­port­ed in this case. Again, they do not explain what those EU* parts are sup­posed to mean.

For the unspec­i­fied audio I assume this means AC‑3, AAC and MPEG Audio Lay­er 2 (some peo­ple use MP2 to describe this audio for­mat). I suc­cess­ful­ly test­ed AAC and AC‑3, and I have read that MP2 works too. Based upon my expe­ri­ences with the video part (more below) I assume the sam­pling rate and bitwidth mat­ter. So far I tried with 48 kHz and 16 bit per channel.

For the EU* parts I have not found any trust­wor­thy ref­er­ence what this could mean, but it looks this refers to some aspects of DVB/DVB‑T/DVB‑S(2) as it is used in Europe. I guess this is a bit linked with valid res­o­lu­tions the TV is able to handle.

For the video part I have found mixed reports. From hat I have read in the Wikipedia page of the H.264 video for­mat, I assumed the fail­ures are relat­ed to a wrong res­o­lu­tion and maybe the fact that some parts of the video do not con­form to spe­cif­ic “lev­els” of the H.264 for­mat. Some tell you are not allowed to use more than X ref­er­ence frames, some tell you can not use advanced fea­ture Y.

The first test I did was to take the Sin­tel video from Blender. I down­loaded the MP4 ver­sion and remuxed it into a MPEG2-TS con­tain­er (I used tsMux­eR to do this). The TV was able to play the AAC audio, but it did not show the video. When I look at the video prop­er­ties, I see that it has a res­o­lu­tion of 1280×544 at 24 FPS. For H.264 videos which use the “High” pro­file and are com­pat­i­ble up to lev­el 4.1, I do not see this res­o­lu­tion list­ed as valid in the Wikipedia page. Valid res­o­lu­tions are 1280×720 at 30, 60 and 68.3 FPS, and 1280×1024 at 42.2 FPS. This could explain why it is not working.

As a sec­ond test I took a video resized it to 624×256 (I did not pay much atten­tion to the scale in the pro­gram I used to test this, I just hoped it takes a good one, now that I try to sum­ma­rize what I inves­ti­gat­ed so far, I see that this size is not one of the valid sizes list­ed in the lev­els for H.264) at 23.976 FPS and reen­cod­ed it with the default options of the x264 encoder. The result­ing video played just fine on the TV.

My third test was to encode a resized (from 640×272 to 640×480) video at 23.976 FPS with weight­ed, upto 4 adap­tive B‑frames, mixed ref­er­ences, 4 ref­er­ence frames, and some oth­er options (this includes B‑pyramid, which seems to be enabled by default). And again, the result­ing video played just fine (despite the fact that I found com­ments in the net which sug­gest that B‑pyramid needs to be disabled…).

I still have to test some HD sizes, but it looks like one key aspect for com­pat­i­bil­i­ty is that the video is encod­ed with the right res­o­lu­tion (I have to admit, I do not real­ly know what this means, as one video had a res­o­lu­tion which was dif­fer­ent from what the valid sizes for the H.264 lev­els are) and com­plies to only lev­el 4.1 (or 4) and below (basi­cal­ly this means to obey some bitrate lim­i­ta­tions and the num­ber of max. ref­er­ence frames for the giv­en res­o­lu­tion). The 23.976 FPS I men­tioned above are not list­ed as one of the valid FPS in the lev­els for H.264, so I do not think the FPS have to strict­ly con­form to what is spec­i­fied for the lev­els. It looks more this is just an upper lim­it so that the video could also use some low­er FPS.

So far I took the sin­tel video and added some black bor­ders on top and below to get to the 1080×720 res­o­lu­tion. I used avide­mux 2.5.4 for this. The ver­sion I tried can only pro­duce a MP4 con­tain­er with this video/audio com­bi­na­tion, and my hope was to remux it with tsMux­eR to a MPEG2-TS, but tsMux­eR does not find a valid video or audio stream inside the MP4 con­tain­er. I am still search­ing for a pro­gram which is able to remux the result­ing MP4 into a MPEG2-TS. I found a tool which extracts the streams from the MP4 con­tain­er, but the only free MPEG2-TS mux­er seems to be tsMux­eR, which I was not able to con­vince to mux the two streams into a MPEG2-TS file. It seems I have either to wait until avide­mux knows how to gen­er­ate MPEG2-TS streams with H.264 and AAC, or until it gen­er­ates a MP4 con­tain­er with H.264 and AAC which tsMux­eR is able to handle.

What I also want to test is, if I can use the open-gop options (either in “nor­mal” or in “blu­ray” mode), but I did not took the time to test this.

The only think I can tell defin­i­tive­ly ATM is, that despite to all the infor­ma­tion I found in the net about this, noth­ing can be told about the hard require­ments except, that the video encod­ing can not exceed lev­el 4.1 (or 4), because so far no hard­ware decoder chip seems to sup­port a high­er lev­el. It seems I can use more or less all options avail­able for the H.264 encod­ing, and the res­o­lu­tion and FPS does not seem to mat­ter that much. I looks more that you have to find a ver­sion of an H.264 encoder which works for you, and after that you can more or less do what you want.