Login
 
Archive
Links
Search
Blog List
There are no categories in this blog.
 
May 21

Written by: Jeremiah Morrill
5/21/2008 2:41 PM

I've been playing around with the new WPF 3.5 SP1 beta lately and I wanted to test the performance of the new WriteableBitmap in comparison to the VRE.

The test simply copies the same pixel buffer to the WriteableBitmap or the VRE at a specific interval.  This way we can see the raw CPU it takes to just update pixels.

For this test, I use a 1280x720 (720p) pixel buffer at around 30FPS.  On my quad-core system, the VRE eats an average of ~1% CPU (it jumps to 2% then to 0% sometimes) and the new WriteableBitmap did an average of ~4.5% CPU usage, which is very good in my opinion.  So if we put this in single-core numbers (multiply usage by number of cores), as WPF is STA, we can say that the VRE uses around 4% of the CPU core the rendering/ui thread are running on and the WriteableBitmap uses ~18%.

There are some pros and cons to consider.  The upside to the WriteableBitmap is you are supposed to get tear-free video all the time, whereas the MediaElement (the driving force of the VRE) has had tearing problems on some systems (though I consider this a bug in WPF).  The WriteableBitmap is also included in the framework and should be perfect for simple pixel updates.  The upside to the VRE is obviously CPU usage and the VRE has the ability to update the pixel buffer on any thread, not just UI (Dispatcher) thread.  The downside to the VRE is that there is a DShow filter that must be registered and of course, its not built into the framework.  But MediaElement is...

Here is the test application I built so everyone can test it out for themselves and check my methods :).  To use the VRE make sure to register the .ax file w/ admin privs.  You will also need .NET 3.5 SP1 installed.

-Jer

Tags:

13 comments so far...

Re: New WriteableBitmap vs. VideoRendererElement

Wow, on my system (oooold) writeablebitmap uses about 30-40% and VRE uses approx 2-13%

Thanks alot for your work, I´m currently using your VRE Webcam demo in a security prototype i´m developing, where authentication takes place using our face recognition/verification algorithm.

By Simsod on   5/21/2008 10:54 PM

Re: New WriteableBitmap vs. VideoRendererElement

Wow! That's fantastic. I'm glad Microsoft added the new functionality of the WriteableBitmap, but really, there's no feasible way to do performant video in WPF beyond MediaElement (and of course the VRE). I guess I'm still glad the VRE is relevant, but I've never been 100% happy with the amount of trickery involved to make the VRE happen. I have been hoping D3DImage will be the answer to our cries! We will find out when they release it!

-Jer

By Jeremiah Morrill on   5/21/2008 11:02 PM

Re: New WriteableBitmap vs. VideoRendererElement

I haven't looked at the new WriteableBitmap, but under 3.5 non SP1, you are better off using the InteropBitmap. It is faster than the WriteableBitmap.

The WriteableBitmap copies the pixels from the input buffer into its buffer then pushes its buffer down to the GPU.

The InteropBitmap allows you to create a shared buffer then just call Invalidate to update the GPU. It gives you the benefit of not having to do a copy.

I'd be interested to see what improvements they have made to the WriteableBitmap.

-AC

By Andrew Collard on   5/28/2008 6:24 AM

Re: New WriteableBitmap vs. VideoRendererElement

Hi,

Great work!

I have a few questions concerning the VideoRendererElement...

If I wanted a solution that was more managed (.NET) could the C++ code be converted to C# and still work in WPF?

Can DVR functions be built in so I can at least pause playback, just like I can pause a video playing from internet explorer? I think there are a few calls in the streaming API that may allow me to do this with WPF.

Thanks

By jameswpierce@gmail.com (spamblock remove to send e on   5/29/2008 9:19 AM

Re: New WriteableBitmap vs. VideoRendererElement

Hi again...

Im using the VRE and at first saw a good amount of page tearing with audio and video out of sync. My developer changed some settings so the tearing is gone but the CPU is running at 100%. What should the expected CPU load be?

Thanks

By JamesWPierce@gmail.com on   5/29/2008 12:19 PM

Re: New WriteableBitmap vs. VideoRendererElement

James,

I'm sorry you are experiencing issues. 100% CPU and tearing are usually issues with the GPU hardware, whether its not adequate or the video drivers are out of date or your application is being rendered in software.

Do a test with the MediaElement and see if you get the same issue. Most likely you will.

By Jeremiah Morrill on   5/29/2008 1:13 PM

Re: New WriteableBitmap vs. VideoRendererElement

James,

Also, it would take quite a bit of work to make the C++ code into .NET as DirectShow filters are C++ and inherit from C++ classes.

You can build in play/pause/etc, but you have to build those in yourself. The VRE is ONLY a performant way to render video...nothing more.

Hope this helps.

By Jeremiah Morrill on   5/29/2008 1:17 PM

Re: New WriteableBitmap vs. VideoRendererElement

Jeremiah, I have a question about VRE, hope you don't mind that it isn't directly related to this post.
If my source device has audio output, can I connect it to the MediaElement owned by the VRE? I'm trying to make a tuner app and I'd like to keep the volume control in the MediaElement.

Thanx

By David Frenkiel on   6/4/2008 1:46 AM

Re: New WriteableBitmap vs. VideoRendererElement

So you want to be able to use the volume properties on the MediaElement? I don't think that is a good way to go about it.

You should query the IBasicAudio interface and run the put_Volume method. You can even make your own WPF control and dep property to this so you can databind to it.

-Jer

By Jeremiah Morrill on   6/4/2008 2:22 AM

Re: New WriteableBitmap vs. VideoRendererElement

Regarding the performance numbers you cite, I added another option to the sample program you provide with the VRE. This one opens a TCP/IP socket to a legacy commercial DVR, starts receiving MPEG4 packets, and hands them to the VRE for rendering. At CIF resolution (360x240) and 15IPS, I am using mid to upper 20's of CPU on a Pentium 4 3GHz system. I commented out the call to VideoRenderer.WriteSample but left everything else in -- the TCP/IP comms, even the alloc and free of the unmanaged byte array for each frame -- and the CPU usage drops to 0 or 1%. Any idea what is going on? I can send you my code if you like. Thanks,

--mvp

By Marc Perrone on   6/19/2008 3:30 PM

Re: New WriteableBitmap vs. VideoRendererElement

Feel free to email at jeremiah.morrill at gmail.com. I'd love to take a look.

If you sending the compressed samples to the VRE, the CPU will drop significantly because the extra load of decoding the frames is not happening and you are just doing socket communications at that point.

Hit me up over email and we can chat about it some more :)

By Jeremiah Morrill on   6/19/2008 3:34 PM

Re: New WriteableBitmap vs. VideoRendererElement

I've noticed that wpf/vre will sometimes use a lot of cpu(more than writeablebitmap), I can provoke it by doing "ctrl-alt-del" on a computer in a domain(ctrl-alt-del does not show taskmanager but shows the lock/loginout/taskman popup).
I suspect wpf is loosing 3d acceleration, so I tried to use the wpf performance debugger to see if disabling acceleration from there had the same effect but I could not reproduce it that way(not sure if that would work anyway though).

By Øystein E. Krog on   7/6/2008 10:57 AM

Re: New WriteableBitmap vs. VideoRendererElement

Hi Jer,
I stumbled upon your page because I am looking to try to create a skype eske package for me and my fiancé. Skype is great but the video is poor. We both have 2mp webcams. I am a mainly a C# programmer with v little experiance of WPF, but pick things up quickly. Do you think the VRE would be a good tool to use? BTW, I have some C++ experiance, but will have to pick out my notes.
Oh, and do you think that writting a skype mimic would be easy and can be done with WPF?

Sorry for all these questions. If you think yes, could you put me some good material to start researching as I have never done anything with codecs or video before and so a lot of the terminology is new to me.

Dewy

By Dewy on   7/10/2008 2:01 PM

Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment    Cancel  
  Minimize
Text/HTML Minimize
Copyright 2007
Downloaded from DNNSkins.com