MediaElement显示的视频中的快照 [英] Snapshot from a video displayed by MediaElement

查看:94
本文介绍了MediaElement显示的视频中的快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个"正在运行"的视频(例如wmv文件)。 (分别显示)在MediaElement中。


现在我想在用户按下(触摸)某个按钮时从视频制作快照。


<我找到了一个如何使用WriteableBitmap在Silverlight中非常容易地做到这一点的示例:

http://paulyanez.com/interactive/index.php/2009/11/creating-thumbnails-of -Video帧与 - WriteableBitmap的功能于微软表达共混物/



不幸的是,WinRT中的WriteableBitmap类没有带UIElement参数的构造函数。


然后我找到了一个如何轻松地做到这一点的例子在WPF中:
http ://www.thomasclaudiushuber.com/blog/2008/04/06/take-snapshots-of-videos-with-wpf/


遗憾的是我们没有RenderTargetBitmap类在WinRT中,现有的WriteableBitmap类没有类似于RenderTargetBitmap所具有的Render方法的类似构造或类似。


Windows.Graphics.Imaging命名空间中有一些类,如ImageStream,BitmapFrame和BitmapDecoder它有一个名为"GetFrameAsync"的方法。这可能会起作用。我看到的问题是,你必须分别计算视频文件中
帧的位置 - 它的字节流 - 这又取决于视频文件的类型,如果它是计算将是不同的一个wmv或一个mp4。即使我不知道是否可以将BitmapDecoder用于视频文件 - 我认为它们的图像文件访问量为
,至少我可以在某些SDK示例中看到这种用法。

最后但并非最不重要的是,在这个解决方案中,我会以第二种方式访问​​视频文件 - 换句话说:MediaElement已经访问了视频文件 - 为什么不分别使用它的输出。


正如微软已经做了一个大的&在WinRT中使多媒体编程非常容易的一个非常出色的工作我无法相信从视频文件中获取快照(特别是当它已经显示在
中时)没有简单的方法(或者至少计划将来)一个MediaElement)。


有没有人玩过类似或想法的东西?


提前致谢!

解决方案

嗨Gebco,


我认为没有一种方法可以在Xaml中完全实现这一点。 


正如您所发现的,MediaElement可以播放视频,但它不提供任何提取内容的方法。 在开发人员预览中,Windows.UI.Xaml没有提供任何方式(例如Silverlight的WriteableBitmap.Render或WPF的RenderTargetBitmap)
来将UIElement呈现为位图(如果您感兴趣,有几个早期的讨论:

http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/39b3c702-caed-47e4-b7d3-b51d75cbca9b
 例如)。


要提取帧,您需要下拉到Media Foundation对象(可能通过创建自定义帧抓取视频效果)。


- Rob


I have a video (e.g. a wmv file) that is "running" (respectively displayed) in a MediaElement.

Now I want to make snapshots from the video as the user presses (touches) a certain button for example.

I found an example how to do that very easily in Silverlight with WriteableBitmap : http://paulyanez.com/interactive/index.php/2009/11/creating-thumbnails-of-video-frames-with-writeablebitmap-in-microsoft-expression-blend/.
Unfortunately the WriteableBitmap class in WinRT does not have a constructor with an UIElement parameter.

Then I found an example how to do that quite easily in WPF : http://www.thomasclaudiushuber.com/blog/2008/04/06/take-snapshots-of-videos-with-wpf/.
Unfortunately we do not have a RenderTargetBitmap class in WinRT and the existing WriteableBitmap class has no similar construct or somthing like the Render Method as RenderTargetBitmap has.

There are some classes in the Windows.Graphics.Imaging Namespace like ImageStream, BitmapFrame and BitmapDecoder which has a method called "GetFrameAsync" which might do the job. The Problem I see there is, that you have to calculate the position of the frame in the video-file respectively its byte-stream - which in turn depends on the video file type, the calculation would be diffrent if it is a wmv or a mp4. Even I do not know if it is possible to use a BitmapDecoder for video files - I think they are made for image file access, at least I can see that kind of use in some of the SDK samples.
Last but not least in this solution I would access the video-file in a second way - or to say it in other words: the MediaElement has already access to the video file - why not use it respectively its ouput.

As Microsoft has done a big & a very great job on making multimedia programming very easy in WinRT I cannot believe that there is no easy way (or at least planned for the future) to grab a snapshort from a video-file (especially when its already displayed in a MediaElement).

Has anyone play around with something similar or an idea ?

Thanks in advance !

解决方案

Hi Gebco,

I don't think there's a ready way to do this purely from within Xaml. 

As you've found, the MediaElement can play the video but it doesn't provide any way to extract the contents.  In the developer preview, Windows.UI.Xaml doesn't provide any way (such as Silverlight's WriteableBitmap.Render or WPF's RenderTargetBitmap) to render a UIElement into a bitmap (there are several earlier discussions of this if you are interested: http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/39b3c702-caed-47e4-b7d3-b51d75cbca9b for example).

To extract the frame you'll need to drop down to the Media Foundation objects (possibly by creating a custom framegrabbing video effect).

--Rob


这篇关于MediaElement显示的视频中的快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆