Stellen Sie eine FrageStellen Sie eine Frage
 

Vorgeschlagene AntwortAlpha Channel Videos in WPF

  • Freitag, 8. Februar 2008 13:30Adwait Joshi TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

     

    Is it possible to use the media element to play alpha channel videos in WPF ? Also how can I play .mov files or .swf in WPF. Is there an easy way to do this in WPF ?

     

    Adwait

Alle Antworten

  • Freitag, 8. Februar 2008 13:52Jeremiah Morrill TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    It's not possible for the media element to do alpha channels of video.  You could export your video to a png sequence (and write some code to play it) to honor the transparency, but that might not be feasible in all situations.

     

    To play .mov files, you just need the directshow filters to play them and MediaElement should then be compatible.  Maybe this will work.  For flv files, you might want to try installing the ffdshow codec.

     

    As for swf files, you will have to embed the flash applet in your wpf app using something like HwndHost or WindowsFormsHost.  Or if yer feeling frisky, you can try using this http://www.codeplex.com/WPFWin32Renderer

     

    -Jer

     

    BTW - Those are 32bit codecs, so make sure your .NET app is compiled for x86, or else your app will not be able to load them on a 64bit os.

  • Freitag, 8. Februar 2008 14:58Adwait Joshi TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    So is it fair to say that if I have these codes, I would just put a mov file in the media element and it should start playing ? I tried that but it did not play. Actually nothing played at all.

     

  • Freitag, 8. Februar 2008 15:04Jeremiah Morrill TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Do the mov files play fine in Windows Media Player?  Also, are you able to get any media file (like a WMV) to play via the MediaElement?

     

  • Freitag, 8. Februar 2008 15:08Adwait Joshi TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    YEs I am able to play .mov files in WPM and I am able to play wmv, mpg, avi files in the media element just not the mov.

     

  • Sonntag, 10. Februar 2008 16:32Adwait Joshi TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Any ideas how can I accomplish this ?
  • Donnerstag, 5. Juni 2008 12:58JakeSee TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
     I also want to alpha key my videos on MediaElement and I saw in the SP1 beta WPF demo something similar to that where the video (a volcano) was able to go transparent.

    Can anyone confirm this please?
    Jake See
  • Dienstag, 5. August 2008 15:43Hunsoul TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    I'm interested in playing .mov and .mp4 with WPF.
    Does anybody know how can I accomplish it?
    It can play wmv but when I try to play a .mp4 it doesn't show anything. It's strange because the Blend designer shows the first frame of the .mp4 video in the mediaelement.

    Waiting for an aswer...
  • Dienstag, 5. August 2008 20:15Brendan Clark - MSFT TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Vorgeschlagene Antwort
    JakeSee said:

     I also want to alpha key my videos on MediaElement and I saw in the SP1 beta WPF demo something similar to that where the video (a volcano) was able to go transparent.

    Can anyone confirm this please?


    Jake See



    The demo you are describing is using a new feature in 3.5 SP1 - custom ShaderEffects.  You can try this feature out with the 3.5 SP1 beta.  Greg Schecter's blog has a good introduction for how to author these Effects: http://blogs.msdn.com/greg_schechter/archive/2008/05/09/a-series-on-gpu-based-effects-for-wpf.aspx

    Color-keying a video is fairly simple.  You need to write a pixel shader that takes one input (the color to remove), and then set the rgba values for pixels that color to zero.  Then, create a ShaderEffect class with that pixel shader.  To use it all you need to do is set yourMediaElement.Effect to an instance of your new class.
  • Freitag, 29. August 2008 10:47snesne TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Enthält Code
    I have written a shader that sets the alphavalue of a targetcolor to zero, as descriped in the above posting. The shader itself works, but the result is blended within the background color of the component that carries the mediaplayer. I thought about something like a 'bltmode' or so that is set to 'add' for default!? When setting the target pixel's color to black (rgb(0,0,0)) and the alpha value to 0, it works fairly nice.
    Is there something like a 'bltmode' anywhere? I cannot find useful information about this issue.. I just want to use the media as an 'overlay', not as a blending component.

    Here is my shader code:

    sampler2D input : register(s0); 
    float4 transparentColor : register(c0); 
     
    bool equals(float f1, float f2) 
        float f = abs(f1 - f2); 
        return f < 0.0001f; 
     
    float4 main(float2 uv : TEXCOORD) : COLOR 
    {    
        float4 result = tex2D(input, uv);     
     
        if( (equals(result.r, transparentColor.r)) && 
            (equals(result.g, transparentColor.g)) && 
            (equals(result.b, transparentColor.b)) ) 
        { 
            result.r = 0; 
            result.g = 0; 
            result.b = 0; 
            result.a = 0; 
        } 
         
        return result; 

  • Freitag, 29. August 2008 18:01Brendan Clark - MSFT TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    Yes, there was a mistake in my post, that's the shader I meant to describe :)  As far as your other question goes, everything in WPF alpha blends into the content behind it by design.  Supporting different blend modes is definitely something we're looking into for future versions.