views:

140

answers:

4

Hi,

I am making an application that will allow users to apply certain tools to analyse videos & images. I need help with how i actaully draw/write on the video loaded into windows media player within my form and being able to save it on. It needs to be able to lert the user draw freehand and shapes on it. Thanks in Advance,

Chris :)

+1  A: 

If you are using WPF, try placing an InkCanvas on top of your video and setting the Background to transparent. You can then save and load up the shapes the users draw on top of the video.

A little proof-of-concept with a picture instead of a video:

alt text

I suspect you may be using WinForms though, where this may be more difficult. If so, a good excuse to learn WPF!


EDIT: With WinForms, you would have to make your own custom control that acts as a transparent overlay and add brush strokes to it. It would be extremely hard to implement well (with transparent background, which doesn't play well with WinForms). I would recommend using WPF if you are still at a stage you can change your application's UI. WPF works on XP and up.


EDIT2: After googling, there are some InkCanvas equivalents that people have made for WinForms, but I have no idea how good they are and may not support transparent backgrounds.

You could always have the video that you want annotated in a new WPF window and the rest of your application in WinForms.

Callum Rogers
So what should i do because i am doing it on a WinForm in XP?
Chris Bacon
+1  A: 

This is a non-trivial, if not impossible task to accomplish with the wmp control in winforms.

I don't know of any way to actually draw on the wmp but you could draw on a transparent panel overlaid over the wmp. This will not work will the video is playing but you can show the drawing while it is paused. I have used this technique to draw over a 3rd party video control that works similarly to wmp.(Edit - this does not seem to work with the wmp control)

However, as real transparent panels are also rather tricky in winforms, another way would be to grab an image from the video and draw on the overlaid image. Again, only when it is paused.

This commercial control does enable drawing over the video. It has an event that fires every frame that you can use to do the drawing. The big downside, though is that you can't really do anything too fancy as your drawing routine needs to finish before the next frame is drawn.

I would strongly encourage you to use WPF(even if its a wpf control hosted within a winforms app) to show your video. It is a whole lot easier to draw on video(including playing video) in wpf.

EDIT

I just tested drawing over the wmp using a transparent panel and its doesn't behave as my 3rd party control did,so I suggest you do the video playing bit in WPF and host that in your winforms app. (I just tested that too using @Callums inkcanvas suggestion and it works like a charm)

geoff
Thanks, but how do i do this technique of putting a WPF in a WinForm? Or do i need to get rid of it completely and just remake it on WPF? but if there is a way in which i don't have to delete and change my project to WPF then that would be ideal :)
Chris Bacon
@Chris: You can put a WinForm control into WPF but not the other way around.
Callum Rogers
@Callum - Not true - you can host a wpf control inside a winforms app: http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.aspx
geoff
@gwoff: Oh wow, learn something new everyday. Then the problem is solved, perhaps, in that he can write the Video + Annotations bit in WPF and host it in his WinForms application.
Callum Rogers
@Callum - yes, that's what I would do.
geoff
Chris Bacon
@Chris, yes take a look at http://www.codeproject.com/KB/WPF/Ink1.aspx#SaveAsISF. Also, if my answer or comments helped you, please consider upvoting my answer :)
Callum Rogers
@Chris - You will not be able to save the annotations onto the video, if that's what you mean. For that you're into the world of 3rd party components to re-encode the video. Otherwise you need to save the annotations separately along with the time in the video, so that you can 'replay' them over the video. You might need to implement your own drawing mechanism using mouse events if the InkCanvas doesn't provide enough flexibility.
geoff
Ok thanks, but how do i do this inkcanvas that allows me to save the annotations separately to play over the video again?
Chris Bacon
A: 

Ok, by far and away the best way of doing this is to use Silverlight. Silverlight supports all of the major streaming formats and also provides complete access to the framebuffer.

Easy :-)

Alan Simes
Silverlight is just a subset of WPF that is designed to be used with webpages.
Callum Rogers
I dont follow? Please see http://wpfslguidance.codeplex.com/releases/view/30311. It is not just a subset of WPF, once of the major differences is how easy it is to distribute Silverlight applications via the Web. See the video overlay support in Silverlight for more information.
Alan Simes
@Alan - @Chris already has an existing winforms app that he wants this functionality in. How does silverlight solve that? Also SL cannot run in full trust(elevated-yes but not full) and the SL MediaElement can only play WMV VC-1 or h.264 video out of the box. WMP or WPF MediaPlayer can playback any video that the user has codecs installed for.
geoff
A: 

You might look at XNA (www.xna.com) from Microsoft. It is made for managed languages like c# and should support video.

I've only used it for drawing in c#, but it gets the job done.

I should also note that XNA will function as part of a regular Windows Forms app. For what it's worth, I have also prototyped something like this with Flash; Flash allows you to import each frame of the movie file into the editor and create a SWF that can respond to user interaction.

However, this approach is useless if you need to update the movie in real-time. Flash (last I checked) could only import the movie at design time.

Tim