Jump to content

WD TV Live transcoding fails


acdvorak

Recommended Posts

acdvorak

Hi there,
 
I'm having trouble streaming a handful of movies to my WD TV Live, and after much digging I suspect this to be a bug in Media Browser Server.
 
Most of my files stream directly (without transcoding) and play without issue, but a few cause Media Browser to (incorrectly, AFAIK) fire up FFmpeg and then immediately terminate the process.  The result is a screen like this on my WD TV Live:
 
5391215a2625e_wdtvlivemicro.jpg
 

"Unable to play the selected file.  Please see the User Manual for a list of supported file formats."

 
Contrary to what the above message says, my WD TV can indeed play the video file as-is without transcoding (see below).
 
My entire library is MKV / H.264 encoded with HandBrake, ranging from High Profile @ Level 4.0 to 5.1.  Most of the videos that fail to play are HP@L5.0 or L5.1, but a few are L4.0.  According to the WD TV Live's User Manual, appendix page 211, the device supports a maximum of HP@L4.1 1920×1080p30 w/ a bit rate of HD:40.  However, I routinely stream HP@L5.0 and HP@L5.1 videos over DLNA using Serviio and they play fine without issue.  So the WD TV is certainly capable of directly playing the videos that are failing without any transcoding, but Media Browser appears to be attempting to transcode them anyway, and for some reason it immediately kills the FFmpeg process - even though FFmpeg doesn't throw any errors or abend.

 
Curiously, if I copy the FFmpeg command that Media Browser tries to run and run it manually in command prompt, it works like a charm.  Thus I suspect this is a Media Browser bug.
 
Here's the relevant portion of the Media Browser Server log file (full version attached):
 

21:06:47.4049 Info - App: C:\Users\BobaFett\AppData\Roaming\MediaBrowser-Server\ffmpeg\old\20140105\ffmpeg.exe -fflags genpts -i file:"M:\MB3\Shared\Disney\Brave (2012) [1080p].mkv" -map 0:0 -map 0:1 -map -0:s -vcodec libx264 -force_key_frames expr:if(isnan(prev_forced_t),gte(t,.1),gte(t,prev_forced_t+5)) -vf "scale=trunc(min(iw\,1920)/2)*2:trunc(min((iw/dar)\,1080)/2)*2" -preset ultrafast -crf 23 -r 23.97602 -vsync vfr -profile:v baseline -level 41 -map_metadata -1 -threads 2 -acodec aac -strict experimental -ac 2 -ab 128000 -af "adelay=1,aresample=async=1,volume=2" -y "C:\Users\BobaFett\AppData\Roaming\MediaBrowser-Server\transcoding-temp\533d0985-6037-a22e-7474-7dd0d8ceeec7.ts"
21:06:48.0960 Debug - HttpServer: HTTP GET http://192.168.0.153:8096/mediabrowser/Items/445cc5e11de0ae3b2e93b9473ccb6bda/Images/Primary?params=ec86bcdb5a084c10534a540f0de1eea2;jpg;512;512
21:06:48.1510 Debug - HttpServer: HTTP Response 200 to 192.168.0.159:43914. Response time: 54.003 ms
    Url: http://192.168.0.153:8096/mediabrowser/Items/445cc5e11de0ae3b2e93b9473ccb6bda/Images/Primary?params=ec86bcdb5a084c10534a540f0de1eea2;jpg;512;512
21:06:48.8850 Error - App: Error streaming media
    The specified network name is no longer available
    System.Net.HttpListenerException
       at System.Net.HttpResponseStream.EndWrite(IAsyncResult asyncResult)
       at System.IO.Stream.<BeginEndWriteAsync>b__17(Stream stream, IAsyncResult asyncResult)
       at System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.IO.Stream.<CopyToAsyncInternal>d__2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at MediaBrowser.Api.Playback.Progressive.ProgressiveStreamWriter.<StreamFile>d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at MediaBrowser.Api.Playback.Progressive.ProgressiveStreamWriter.<WriteToAsync>d__0.MoveNext()
    
21:06:48.9210 Debug - HttpServer: HTTP Response 500 to 192.168.0.159:43913. Response time: 1530.0875 ms
    Url: http://192.168.0.153:8096/mediabrowser/videos/445cc5e11de0ae3b2e93b9473ccb6bda/stream.ts?Params=e1b92f346f00d5aad781f913ab298f25;test;445cc5e11de0ae3b2e93b9473ccb6bda;false;h264;aac;;;;128000;2;;1920;1080;0;41
21:06:49.9131 Info - App: Killing ffmpeg process for C:\Users\BobaFett\AppData\Roaming\MediaBrowser-Server\transcoding-temp\533d0985-6037-a22e-7474-7dd0d8ceeec7.ts
21:06:50.0281 Info - App: FFMpeg exited with code -1
21:06:50.0361 Info - App: Deleting partial stream file(s) C:\Users\BobaFett\AppData\Roaming\MediaBrowser-Server\transcoding-temp\533d0985-6037-a22e-7474-7dd0d8ceeec7.ts

Note that in addition to transcoding the video to HP@L4.1, in all cases I observed Media Browser attempts transcode audio tracks to 2.0 ch AAC, which is unnecessary because the WD TV Live supports all Blu-ray audio codecs and channel layouts (e.g., Dolby TrueHD 7.1 ch, DTS-HD MA 5.1 ch).

 

FWIW, I have no problem streaming (transcoding) the same files to my Roku 3 via the Media Browser channel.

 

Here are my system specs:

  • Media Browser Server version 3.0.5267.16902
  • Windows 7 64-bit SP1
  • WD TV Live Streaming Media Player (Gen 3) - WDBHG70000NBK-02

Attached are the full Media Browser Server log file, two ffmpeg transcode log files, and the MediaInfo dumps of the files that are failing.
 
Please let me know if you require any additional information and I'll be happy to provide it.
I have a little bit of experience writing Windows .NET apps in C# and using FFmpeg, so if there's anything I can do to help with this issue, just let me know.
 
Thanks!

mediainfo-brave.txt

mediainfo-princess-frog.txt

mediainfo-snow-white.txt

mediainfo-toy-story-2.txt

mediainfo-toy-story-3.txt

mediainfo-toy-story.txt

mediainfo-up.txt

transcode-61fb02dd-c06f-4304-a533-135ffe597d17.txt

transcode-461e8d72-acee-48ff-a52a-dd38147e7299.txt

server-63537597258.txt

Link to comment
Share on other sites

Hi there,

Thanks for the info. Yea we'd love to have you help us out. For this there's probably no coding required. You might just need to make some edits to the wdtv live dlna profile. Can you play with that?

 

And then once you get through that if you want to take on a development project you'll be more than welcome.

Link to comment
Share on other sites

acdvorak

Certainly.  I suspect it may be related to the WDTV's codec profile:

 

Codec profiles indicate the limitations of a device when playing specific codecs. If a limitation applies then the media will be transcoded, even if the codec is configured for direct play.

 

If that is indeed the culprit, what's the best way for me to debug the DLNA session and see all the information being sent to MB by the WD TV (short of going nuclear and using Wireshark)?  Since I don't have a gen 2 or gen 1 device to test with, I might end up needing to create a new profile that only targets gen 3 WD TVs to avoid breaking earlier generations.

Link to comment
Share on other sites

The best thing to do is use the web interface to save a custom profile. At this point, 90% of the profile settings are editable in the interface, but there are still a few missing, including codec profile conditions. So save the custom version without any changes, then go the app's program data directory -> config -> dlna -> user.

 

Find your custom profile which you can then edit by hand. You could try removing the 2 channel limit for aac, but this was based on servioo's profile so i imagine it's there for a reason. 

 

Then you can adjust the video level, for which we currently have 41 (4.1), although if that's what documentation says then we may want to stick with it.

 

But there is one other thing I'd like to solve - even if you're able to successfully remove transcoding, I'd like to know why transcoding isn't working, so it would be nice to get that figured out because it will sometimes be needed.

Link to comment
Share on other sites

acdvorak

Changing AudioChannels from 2 to 8 and VideoLevel from 41 to 51 did the trick: Media Browser now streams all of my HD video files directly to the WD TV Live without transcoding, and everything plays correctly.

 

The 2 channel limit is probably to ensure 100% compatibility with all WD TV setups.  The WD TV can output 480/stereo via composite, or 720/1080 with 7.1 channel audio via HDMI pass-through.  Serviio is likely aiming for the lowest common denominator to ensure that playback always works regardless of how your WD TV is set up.

 

Would it make sense to add a "WDTV Live Gen 3 Surround" DLNA profile that includes the AudioChannels/VideoLevel changes mentioned above?  I'm trying to think of how we can make it easy for people who own a WD TV and want to bitstream full HD audio to their surround sound receiver, but who don't have the time or knowledge to figure out that they need to change the H.264 level value and channel limit to make it work.  Or perhaps it would be better to write up a simple wiki entry (or w/e) describing how to stream "full" Blu-ray quality HD videos to a WD TV Live Gen 3 without transcoding instead?

 

(Also - I figured out how to target Gen 3 WD TV devices using a utility called Coherence UPnP-Inspector that lets you view DLNA devices (clients and servers) and their properties in a simple GUI.  You simply set the "Model URL" identification param to "http://products.wd.com/wdtvliveG3" in the DLNA profile config.)

  • Like 2
Link to comment
Share on other sites

acdvorak

Luke, I agree that we should figure out why transcoding was failing.  What can I do to help investigate further?

Link to comment
Share on other sites

Yea a second profile would fine. is there a way we can detect one vs. the other?

 

As far as transcoding, i haven't' looked at your reports closely enough yet. I'll try to get to them soon.

Link to comment
Share on other sites

acdvorak

Not that I know of.  None of the properties or functions (not sure what they're actually called) exposed by the WDTV returned anything useful.

 

How would you feel about adding a checkbox to enable/disable individual DLNA profiles?  That would allow us to include a "WDTV Live Gen 3 Surround" profile, leave it disabled by default, and if users want to bitstream audio to their receiver, they can just enable the profile in the web UI.

Link to comment
Share on other sites

well actually, just from re-reading your post, can't we use model url to differentiate? that is one of the fields we check.

 

if the earlier gen models support the same video level and audio channels, then i'm fine with pushing the change down. the dlna profile is intended to express what the device supports. if the device supports 5.1 but the user only has stereo speakers, we have other ways of limiting it down to two channels.

Link to comment
Share on other sites

acdvorak

Yes, we can indeed use the Model URL field to differentiate (in fact I'm already doing that in my custom profile).

 

TL;DR: For Gen 3 devices, we can directly play 8 channel audio (any codec supported by the WD TV) and H.264 L5.0 video to the WD TV.  It will handle any necessary conversion from there.  Gen 1 & 2 devices don't support Dolby TrueHD and may or may not tolerate H.264 L5.0, so we should probably have two separate DLNA profiles for Gen 1-2 and Gen 3 (though of course it's ultimately your decision, @@Luke).

 

Long version:
 
The good news is that the WD TV appears to automatically transcode all audio formats it supports into something the TV/receiver it's hooked up to can handle.  As long as the user configures their WD TV properly, we don't have to worry about figuring out what the TV/receiver supports; we only care about what the WD TV itself supports.
 
That said, from reading the user manuals for previous models1, it looks as though only Gen 3 devices support Dolby TrueHD and DTS-HD Master Audio.  Although DTS-HD MA is fully backward-compatible with regular DTS, Dolby TrueHD is not backward compatible with Dolby Digital2.  Thus we may need separate DLNA profiles for earlier WD TV generations vs. Gen 3 devices.

 

As far as H.264 support goes, according to their manuals all 3 generations claim to support HP@L4.1 up to 1920x1080p @ 24 fps (although I can't confirm that since I don't have any Gen 1 or 2 devices).

 

From my testing, the only x264 setting that has any affect on H.264 Level is Reference Frames3.  Realistically, the only difference between L4.0 and L5.0 H.264 videos (at least the ones Media Browser is likely to encounter in the wild) is going to be the number of Reference Frames.  I have successfully tested videos with up to 7 ReFrames on Gen 3 devices.  So although the WD TV Gen 3 may not support all L5.0 specs, it appears to at least support up to 7 Reference Frames, which indicates to me that it should be safe to directly play H.264 L5.0 to WD TV Gen 3 devices.

 

Footnotes:

1. WD TV User Manuals (PDF):

2. On Blu-ray Discs, Dolby TrueHD streams contain a separate, independent inner Dolby Digital stream for backward compatibility with older players.  Unfortunately, most other container formats that I know of (e.g., Matroska) do not support inner streams, so MKV files that contain Dolby TrueHD tracks would need to be converted to something else for pre-Gen 3 WD TVs.

 

3. x264 Reference Frame counts and their corresponding H.264 Levels:

  • 1-4 ReFrames = L4.0
  • 7-13 ReFrames = L5.0
  • 14-16 ReFrames = L5.1
  • Like 1
Link to comment
Share on other sites

Great stuff. It looks like you have a very good handle on this so I'm comfortable going with your opinion. So once you've got it worked out if you want to post the updated xml or submit a pull request that'd be great .thanks.

Link to comment
Share on other sites

acdvorak

Additional information for those interested:

 

According to this forum post:

 

The WDTV's Sigma chip only has the physical space to keep track of 4 reference frames while it's decoding streams.  The chip meets L4.1 playback specs.

But since the file was encoded out of spec, with 8 reference frames, the resulting video is garbled, because it's expecting the decoder to remember 8 different frames of video at any one time, and providing difference information from those 8 frames.  Since the WDTV can only keep track of 4 frames at any one time, it knows that some pixels are different than what was in ReFrames 5-8, but it no longer knows what ReFrames 5-8 look like, so it can't properly decode the picture.

 

 

The post is from early 2011, which is prior to the Gen 3's release, so it most likely applies to the Gen 2.

 

The Gen 3 has 512 MB memory (source), which should (I think) be enough to hold several additional ReFrames beyond what it "officially" supports (4).  But that's purely speculation based on a cursory reading of the H.264 (04/13) spec and H.264 article on Wikipedia (specifically the Levels and Decoded Picture Buffering sections) -- so don't quote me on it ;-)

Edited by acdvorak
Link to comment
Share on other sites

acdvorak

@@Luke - Is there a separate audioCodec value for Dolby TrueHD?  I only see ac3 in the system profiles.  Are you not currently distinguishing between TrueHD and Dolby Digital / DD+?

Link to comment
Share on other sites

  • 2 weeks later...
kbrutlag

Hey guys, I'm very interested in this topic.  I have a WD TV Live Gen 2 (I think ) that I would love to get working with MB.  My collection is in raw formats for both DVD and Blu Ray, and I receive the same message you (acdvorak) posted a screen shot (literally) of to kick off this thread. 

Link to comment
Share on other sites

@@Luke - Is there a separate audioCodec value for Dolby TrueHD?  I only see ac3 in the system profiles.  Are you not currently distinguishing between TrueHD and Dolby Digital / DD+?

 

it could be identified using truehd, although i don't believe i've seen competing profiles ever  look for it. but i could be wrong.

Link to comment
Share on other sites

acdvorak

There's definitely still a transcoding issue here.  I found a video with dimensions larger than 1080 (1920x1440 - see mediainfo-the-artist-mkv.txt), which triggered Media Browser to transcode it before streaming to the WD TV.  The transcode failed with the same error message as the screenshot I originally posted (see server-mkv-63538448832.txt and transcode-mkv.txt).

 

Since Media Browser killed the FFmpeg process shortly after it started, I copied the command it executed and ran it to completion.  I then copied the resulting .ts file (mediainfo-the-artist-ts-ultrafast.txt) to a flash drive and attempted to play it on the WD TV via USB, which worked just fine (it played correctly).  Next, I copied the .ts file to one of my library folders being watched by Media Browser and attempted to stream it to the WD TV over DLNA.  Strangely, Media Browser again attempted to transcode the video, even though it was already in the appropriate format/resolution (see server-ts-ultrafast-63538905600.txt and transcode-ts-ultrafast.txt).

 

Looking at the MediaInfo dump of the first .ts file (mediainfo-the-artist-ts-ultrafast.txt), I thought there might be an issue with the H.264 profile/level, so I re-ran the FFmpeg command using the superfast preset instead of the ultrafast preset used by Media Browser.  It didn't make any difference: The resuling second .ts file (mediainfo-the-artist-ts-superfast.txt) played fine over USB, but Media Browser tried (and failed) to transcode it over DLNA (see server-ts-superfast-63538905600.txt and transcode-ts-superfast.txt).

 

The server log files lead me to suspect that there's something wrong with how Media Browser is communicating with the WD TV over DLNA:

2014-06-21 23:04:02.6255 Info - App: ...\ffmpeg.exe -fflags genpts -i file:"M:\Test\The Artist (2011) [1080p] [ultrafast].ts" -map 0:0 -map 0:1 -map -0:s -vcodec copy -bsf h264_mp4toannexb -map_metadata -1 -threads 2 -acodec copy -y "...\transcoding-temp\57ebff8f-771c-8a21-59e9-d4034d5e29f7.ts"
2014-06-21 23:04:03.2915 Error - App: Error streaming media
The specified network name is no longer available
System.Net.HttpListenerException
    at System.Net.HttpResponseStream.EndWrite(IAsyncResult asyncResult)
    at System.IO.Stream.<BeginEndWriteAsync>b__17(Stream stream, IAsyncResult asyncResult)
    at System.IO.Stream.<CopyToAsyncInternal>d__2.MoveNext()
    at MediaBrowser.Api.Playback.Progressive.ProgressiveStreamWriter.<StreamFile>d__3.MoveNext()
    at MediaBrowser.Api.Playback.Progressive.ProgressiveStreamWriter.<WriteToAsync>d__0.MoveNext()
2014-06-21 23:04:04.2996 Info - App: Killing ffmpeg process for ...\transcoding-temp\57ebff8f-771c-8a21-59e9-d4034d5e29f7.ts
2014-06-21 23:04:04.5116 Info - App: FFMpeg exited with code -1
2014-06-21 23:04:04.5116 Info - App: Deleting partial stream file(s) ...\transcoding-temp\57ebff8f-771c-8a21-59e9-d4034d5e29f7.ts

Any idea why that exception might be getting thrown only when transcoding but not when direct-playing?

Edited by acdvorak
Link to comment
Share on other sites

Thanks for that info, very helpful. The work I just checked in was mostly around the xml responses are upnp methods, not so much with transcoding. So this particular issue still remains.

 

For the first transcode failure, the exception is getting thrown because the WDTV has disconnected. It saw something in the output stream that it didn't like and so it aborted.

 

For the second, it is clearly an error on the part of the server. Notice 

 

[NULL @ 05730060] Packet header is not contained in global extradata, corrupted stream or invalid MP4/AVCC bitstream
Failed to open bitstream filter h264_mp4toannexb for stream 0 with codec copy: Invalid argument
 

I see why it's not direct playing the second time through - the transcoding profile says convert the audio to aac, but the direct play profiles do not indicate support for aac within ts. So I am guessing the ts direct play profile needs aac added to it.

 

So once that change is made to the profile, then we just need to figure out why the original transcode is failing. can you try changing the transcoding container to mp4? Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...