Mike Taulty's Blog
Bits and Bytes from Microsoft UK
Silverlight 5 Beta Rough Notes–Hardware Decoded H.264

Blogs

Mike Taulty's Blog

Elsewhere

Archives

Note: these are early notes based on some initial experiments with the Silverlight 5 beta, apply a pinch of salt to what you read.

This is a simple one – I’d read that Silverlight 5 could now do hardware decoding of H.264 encoded video on Windows so I thought I’d give that a try.

I wanted a 1080p video so I did a quick search and came up with http://www.h264info.com/clips.html (I’ve no idea of the legality of these video clips by the way) and I downloaded the trailer for “The Bourne Ultimatum”).

This is 80MB of video clip, it runs for 1 minute 30 seconds and, according to Windows Explorer, it runs at 1920x816.

I first played the video in Windows Media Player where my machine was pretty much idle during the playback;

image

Note that this wasn’t some scientific test, I was just playing the video and other apps and services were definitely running on my machine and that might be some of the spikes there.

Next, I made a Silverlight 5 application and dropped the 80MB video onto the website that the application launches from and played it with a simple MediaElement;

 <MediaElement
      Width="1920"
      Height="816"
      Source="trailer.mp4" />

and this is how Task Manager displayed it;

image

Clearly, this is costing me a bunch more CPU cycles than Windows Media Player was. I switched on GPU Acceleration for the plugin in my ASPX page;

image

and ran the video again;

image

it seemed a little lower but I suspect that’s a freak result. I switched on BitmapCache for my MediaElement;

image

and ran it again;

image

and that picture looks pretty good Smile and settles down to practically not touching the CPU too much during the 90 seconds of that video.

At the point where I started this post, I wasn’t sure ( based on some docs that I’d read ) whether I’d have to explicitly switch on enableGPUAcceleration and CacheMode in order to get this functionality but, from the tests so far, it seems pretty conclusive that I do need to in the Silverlight 5 beta ( unless I’m seeing a false positive result here? ).


Posted Tue, May 3 2011 12:23 PM by mtaulty
Filed under: , ,

Comments

Alex van Beek wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Tue, May 3 2011 12:59 PM

That's interesting, because setting the cachemode instructs Silverlight to cache an element as a bitmap. This would be ineffecient for a video which changes each frame and thus should be cached again. What are your thoughts about this?

Mike Taulty's Blog wrote Silverlight 5 Beta Rough Notes–Trick Play Video
on Tue, May 3 2011 1:18 PM

Note: these are early notes based on some initial experiments with the Silverlight 5 beta, apply a pinch

DotNetShoutout wrote Silverlight 5 Beta Rough Notes–Hardware Decoded H.264 - Mike Taulty's Blog
on Tue, May 3 2011 3:58 PM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Misi wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Tue, May 3 2011 10:01 PM

good and simple post

mtaulty wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Tue, May 3 2011 10:54 PM

Alex,

I think you're correct for UIElements generally but I was under the impression that in order to opt-in to hardware acceleration for a MediaElement you also used the CacheMode property and set it to BitmapCache and the option is basically saying "let the hardware deal with it".

I could be wrong. I wrote about it for Silverlight 3 back here

mtaulty.com/.../silverlight-3-and-gpu-acceleration.aspx

and I notice the MSDN page here;

msdn.microsoft.com/.../system.windows.uielement.cachemode(v=vs.95).aspx

using it as an example.

Mike.

Alex van Beek wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Wed, May 4 2011 5:46 PM

Hmmz, In Silverlight 4 it only improves performance if the video isn't played in it's native size, since the stretching is done on the gpu. In the native size, bitmapcaching actually reduces performance because of the constant cache invalidation, as this post also points out: forums.silverlight.net/.../302351.aspx

Maybe the meaning of "bitmapcaching" has changed in Silverlight 5 for the MediaElement, which makes it less obvious what bitmapcaching actually does.

Ahh well, it's still a great feature to have!

mtaulty wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Thu, May 5 2011 12:05 AM

Alex,

Yes, that was my impression of the state of play with Silverlight 4 - i.e. it's not hardware decoding, it's scaling.

However, in SL5 it's also decoding and it seemed from what I experimented with here that you do have to set CacheMode in order for it to kick in.

However, as I said in the post - I wasn't originally expecting to have to "do" anything to get hardware decoding to work because I'd read some specs that suggested you wouldn't have to do that.

Perhaps I've been fooled by some side-effect of scaling although I seem to think that I set the video to play at its native resolution so I wonder how that happened if it's the case?

I'll ask internally and see if I have this right or not.

Mike.

Hans wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Thu, May 5 2011 3:24 PM

Hi,

Which GPU do you have in the PC used creating this blogpost ? We experience some better performance but never better than Media Player?

Richard Bergmans wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Thu, May 5 2011 3:39 PM

Hi Mike,

I followed this easy sample with the same trailer you used. But I do not see that much difference in processor load.

Probably the hardware plays an important part in this, can you tell me what kind of hardware you did run this sample on ?

With regards,

Richard

mtaulty wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Fri, May 6 2011 10:16 AM

I'm running a Dell XPS 1640. It's a little old now but it's the best laptop I've ever had so I've stuck with it.

CPU = Core2 Duo T9600 at 2.80Ghz

GPU = ATI Mobility Radeon HD 4670

Mike.

mtaulty wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Tue, May 10 2011 8:47 AM

I asked about whether it is necessary to set CacheMode on a MediaElement in order to get hardware accelerated decode.

What I heard is that the hardware decode will happen even if you don't set CacheMode.

HOWEVER - if you don't set CacheMode then the decoded video frames will be copied from the GPU memory to the main memory for playing which is quite expensive.

So, I take that as saying that in reality you DO have to set CacheMode if you want the full benfit.

Mike.

jcribeiro wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Wed, May 18 2011 11:42 AM

Hi Mike,

Do you have your test page online?

Can you tell me your system performance playing the same video file in Media Player Classic?

Cheers

Jose

Richard Bergmans wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Thu, May 26 2011 12:36 PM

Hi Mike,

I tried the example on a machine with a ATI gpu and now I see the difference clearly indeed.

So I tried this also on two other computers one with a CrystalHD decoder and the other one with a nvidia ion decorder.

But on those two computers the gpu does not seems to be used. With windows media player the movie trailer plays fine with almost no processor usage.

Do you know if SL5 Beta 1 only supports the ATI gpu's ?

Or could it be some other reason ?

With regards,

Richard Bergmans

mtaulty wrote re: Silverlight 5 Beta Rough Notes–Hardware Decoded H.264
on Thu, May 26 2011 3:36 PM

Richard,

I'm not sure on this one - interestingly on my ATI GPU I have some problems with SL5's 3D support so I'd heard that Nvidia was "better" right now so it's interesting that you're seeing different.

I'll see if I  can find out more.

Mike.

Farhad Alaydrus wrote Silverlight 5: H.264 Hardware Decode
on Fri, Jul 8 2011 5:54 AM

*Tulisan adalah hasil dari percobaan sederhana di laptop saya. Hasil mungkin dapat berbeda di perangkat