질문하기질문하기
 

제안된 답변Alpha Channel Videos in WPF

  • 2008년 2월 8일 금요일 오후 1:30Adwait Joshi 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

     

    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

모든 응답

  • 2008년 2월 8일 금요일 오후 1:52Jeremiah Morrill 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    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.

  • 2008년 2월 8일 금요일 오후 2:58Adwait Joshi 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.

     

  • 2008년 2월 8일 금요일 오후 3:04Jeremiah Morrill 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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?

     

  • 2008년 2월 8일 금요일 오후 3:08Adwait Joshi 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.

     

  • 2008년 2월 10일 일요일 오후 4:32Adwait Joshi 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Any ideas how can I accomplish this ?
  • 2008년 6월 5일 목요일 오후 12:58JakeSee 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
     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
  • 2008년 8월 5일 화요일 오후 3:43Hunsoul 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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...
  • 2008년 8월 5일 화요일 오후 8:15Brendan Clark - MSFT 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     제안된 답변
    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.
  • 2008년 8월 29일 금요일 오전 10:47snesne 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    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; 

  • 2008년 8월 29일 금요일 오후 6:01Brendan Clark - MSFT 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    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.