Click here to Skip to main content
15,797,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My goal is to draw a video with an alpha channel on top of the screen as efficiently as possible(with the least amount of CPU consumption) and, if possible, with blending modes. What suggestions do you have?
Posted
Comments
Sergey Alexandrovich Kryukov 25-Dec-14 16:41pm    
It is not called "draw a video with an alpha channel". What are you using for your UI? If you used WPF, it would not be a big problem... If you are using something like System.Windows.Forms (or anything else not based on DirectX), I would not recommend to use DirectX at all...
—SA
mostwanted4 25-Dec-14 16:57pm    
I've not settled on a project type but I've tried in WPF with a MediaElement and I didn't succeed. I'm open to any ideas.
Sergey Alexandrovich Kryukov 26-Dec-14 0:20am    
I never try exactly what you wanted (as I understand, you want to show semi-transparent video, is that correct?), but I successfully tried similar things with video and transparency with WPF. Maybe I need to try it...
—SA
mostwanted4 26-Dec-14 3:12am    
It's not just a semi-transparent video. Each frame also has a (different)alpha mask. Imagine, let's say, a basketball falling from the top of the screen; the ball will be 100% non-transparent and it will have a semi-transparent shadow on the ground and the rest of the video is 100% transparent.

P.S. I find really weird the fact that this topic was not explored on the internet(I haven't found even one project), the closest one being Per Pixel Alpha Blend in C# but with images.
Sergey Alexandrovich Kryukov 26-Dec-14 12:48pm    
Ah, this... But this is really easy. in certain sense... You just should not use the standard video stream formats and codecs, but create your own. Who told you that the video standards would support such things and why would the do it? Maybe I don't know something; then please explain. Even if you assemble your video from your own frames in ARGB pixel format, why do you think any alpha data will be supported in resulting video. Do you understand that in compressed video there are no individual frames (there are key frames though)?
—SA

Sorry for so incomplete answer, but I think your request is so exotic that it would be a hard to find a developer who directly dealt with such features. I, for example, found something only after discussing your problem. However, I surprised that you could not find anything. Please see:
http://bit.ly/1vhCSJC[^].

See also my comments to the question.

—SA
 
Share this answer
 
Comments
mostwanted4 26-Dec-14 16:30pm    
Ok, maybe I haven't been clear. My question is not what format do I need for my video, for all I care I might just as well have a folder with tons of PNGs. I want to know how to play the actual video and what control/libraries I need to do so.

EDIT: looking back on your format comments I realized that my video could also be a GIF(with a transparent backgound) and then found this gif player http://wpfanimatedgif.codeplex.com/ might not be the best way but it seems to work for now. I'm still open to better ideas.
Sergey Alexandrovich Kryukov 26-Dec-14 16:32pm    
The question is: why would you want to play these tons as video? Seriously, this is all about it. Your ultimate goals, please. Don't say "my goal is to show all those PNGs", say why do you want it?
—SA
mostwanted4 26-Dec-14 16:50pm    
My ultimate goal is to create a interactive assistant with an awesome interface. Let's say that I want to watch a movie and I open its folder then an animation will appear which when clicked will download the subtitle or when I'm on deviantart and I watch an image for more than 3 secs I want a nice animation which asks me to store this image and when I'm on that site I can see an animated bar which if clicked will show all my stored images. I hope you get the idea.
Sergey Alexandrovich Kryukov 26-Dec-14 19:28pm    
Not 100%, but I think you should better to listen to my advice on (non-video) animation and vector graphics I already mentioned...
—SA
And I have an alternative idea for you. However, I cannot promise that it fits your purpose. This is the problem of your question: you never shared your ultimate purposes, and without it your request may not make sense.

But let me just speculate. First step is: if you wanted to create video with the use of alpha channel, it's apparent that it should be prepared in some very special way. It's apparent that if you simply take a camera and take some video, that video will make all channels 100% opaque, even if alpha is formally utilized. Now, the next step: therefore, it cannot be "just video", so it could be only some animation in the wide sense of this word. Even if this video includes some "real" video from the camera, it should have some "manipulated" elements.

And here is then main step: animation does not mean video. In other words, motion picture does not mean having "traditional" frame-by-frame video, moreover, having the video could be a harmful idea, a pure redundancy. I'll illustrate it on a speculative example. Suppose you want to have one or few graphical objects, something like balls, fly over some UI interface, over some list boxes, check boxes and grid view, having them in the background and even leaving them accessible to your mouse events. But this problem becomes trivial if you give up pointless video. You should have just UI element animated, without rendering the background, which would only take up memory and compromise performance. And, if you want, you can even show the semi-transparent background, say, blue skies with clouds, still showing your UI controls. Not a problem at all: this background would be static or almost static and work in a separate layer. But should you try to put it on video, in addition to all your problems, all that layers would become a part of video and contribute to the cost of rendering the whole frame on each move.

So, this is the conclusion: instead of using video, you can use WPF animation. Mind you, I don't mean standard WPF animation (storyboard-based), which could be too limited. You could animate some UIElement objects (typically, on a Canvas) and use a separate thread and Dispatcher.Invoke to modify these objects and their coordinates and doing other coordinate space transforms. The object can use either vector or pixel graphics. Moreover, you can draw complicated vector objects using excellent open-source InkScape (or something else at your liking), export resulting SVG as XAML, embed this XAML as WPF resource and animate in your application. This is all pretty trivial stuff.

If you need some further detail, I'll gladly try to help more. First, just think about it.

—SA
 
Share this answer
 
Comments
mostwanted4 26-Dec-14 17:03pm    
First of all, I would like to thank you for your patience with me. Secondly, I'd like to mention my UI plan: I want to create some buttons in phostoshop then animate them in after effects(have a default animation,a hover animation, mouse down and mouse up) then export these to an animation and then scroll through it depending on the user interaction(e.g. start from frame 0 and loop until frame 50, if the users hovers loop from 65 to 100 etc)
Sergey Alexandrovich Kryukov 26-Dec-14 19:26pm    
You are very welcome. I don't think this is a good plan, especially if you want to implement advanced effects. Making UI or UI element using Photoshop is a usual mistake of some UI designers without good software background, better don't repeat it. If you want to go in for DirectX and, hence, nearly unavoidable WPF, you should better focus on vector graphics, with all its benefits, including avoiding pixellation. I already mentioned better tool, InkScape; there are others. With DirectX and WPF, it's vector time now. The images are much more reach than you may think...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900