WPF 3D Video Example using DiffuseMaterial and MediaElement

February 18, 2013

This was supposed to be so easy according to the books and examples provided by microsoft. Just add a MediaElement and specify the video source. Only it took me 6 hours to figure out what I got nothing on the screen but no errors reported. Additionally, when I implemented this with a media player class and called its “hasVideo()” method, the method always returned false. I tried half a dozen video files I had, re-converted the codecs and containers to all the popular formats, and still no video. But it always played just fine with the windows media player stand-alone application. I finally stumbled on the solution : my video’s were non-standard sizes. This only works with (I am guessing) standard width by height formatted videos, such as 720×480, as opposed to something like 854×480 which was one of my videos. So I used ffmpeg to crop my videos down to standard sizes and now its as easy as it supposed to be.

The code-behind C# method of using a media player object. diffuseMat is the x:Name given to the DiffuseMaterial object in the xaml code.

Entry filed under: Uncategorized. Tags: .

ffmpeg examples Using QtCreator for generic c and c++ projects