(此文章同时发表在本人微信公众号“dotNET每日精华文章”,欢迎右边二维码来关注。)

题记:曾经在Windows Phone上想开发一个支持多种格式的媒体播放器是比较困难的一件事情,因为无法利用FFmpege这样的开源库。不过现在好了,微软提供了一个开源的FFmpegInterop解决了此问题。

由于WinRT和Windows Phone平台的限制,在上面的APP只能播放内置多媒体播放器支持的几种格式(比如WMV,MP4等),虽然这些格式还是能满足大部分情况。不过如果你打算开发一款格式支持更全面的播放器(或者你的软件打算播放一些额外的格式,比如mkv、flv和mov等),那么就比较分周折了,因为一些常用的开源多媒体库无法直接使用。就连VLC这样的著名软件都迟迟没有推出WP版本。

微软曾经发布了一系列编译指令来构建和WinRT兼容的FFmpeg。不过这样做会带来性能损耗。为了解决这个问题,微软最近在GitHub上发布了一个名为FFmpegInterop的开源库,解决了这个问题。这个开源库利用FFmpege来处理媒体内容,但回放使用Windows媒体框架。这种方式能够获得更好的性能,因为Windows媒体框架可以利用硬件加速。微软同时也发布了使用C#、C++和JavaScript编写的示例媒体播放器APP。

大致用法是:

  1. 创建一个FFmpegInterop对象,插接到XAML的MediaElement对象中或者WinJS的HTML5 Video组件中
  2. 使用FileOpenPicker打开一个本地文件,作为一个流传递给FFmpegInterop

上述使用步骤的C#代码类似如下:

   1: // Instantiate FFmpeg object and pass the stream from opened file

   2: IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read);

   3: FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(readStream, false, false);

   4:  

   5: // Pass MediaStreamSource to Media Element

   6: mediaElement.SetMediaStreamSource(FFmpegMSS.GetMediaStreamSource());

更详细的用法可以通过“阅读原文”来了解。从原文地址中也可以找到该项目的GitHub地址。

(特别提醒,微软在GitHub上的主页还列出了很多开源项目,是个不容错过的宝藏。)

原文地址:http://blogs.windows.com/buildingapps/2015/06/05/using-ffmpeg-in-windows-applications/

Windows和Windows Phone应用终于可以使用FFmpeg了的更多相关文章

  1. Windows下使用Visual Studio 2010编译ffmpeg全过程

    在visual studio 2010中调用ffmpeg http://blog.sina.com.cn/s/blog_4178f4bf01018wqh.html Windows下使用Visual S ...

  2. Installing the .NET Framework 3.5 on Windows 8, Windows 8.1 and Windows 10

    Installing the .NET Framework 3.5 on Windows 8, Windows 8.1 and Windows 10 .NET Framework (current v ...

  3. 用C#创建Windows服务(Windows Services)

    用C#创建Windows服务(Windows Services) 学习:  第一步:创建服务框架 创建一个新的 Windows 服务项目,可以从Visual C# 工程中选取 Windows 服务(W ...

  4. Memory Limits for Windows and Windows Server Releases

    来源:https://msdn.microsoft.com/en-us/library/windows/desktop/aa366778(v=vs.85).aspx Limits on memory ...

  5. Notice to users of DB Query Analyzer in Windows 7, Windows 8 and Windows 10

        UnlikeWinXP, VISTA, Windows2000, Windows Nt and Win98,Windows 7 / Windows 8 / Windows 10 select  ...

  6. How to detect, enable and disable SMBv1, SMBv2, and SMBv3 in Windows and Windows Server

    转自:https://support.microsoft.com/en-us/help/2696547/detect-enable-disable-smbv1-smbv2-smbv3-in-windo ...

  7. [转载]Memory Limits for Windows and Windows Server Releases

    Memory Limits for Windows and Windows Server Releases This topic describes the memory limits for sup ...

  8. C# windows服务:创建Windows服务(Windows Services)的一般步骤

    C#创建Windows服务(Windows Services) Windows服务在Visual Studio 以前的版本中叫NT服务,在VS.net启用了新的名称.用Visual C# 创建Wind ...

  9. [微软]The latest version of Windows is Windows Sandbox

    The latest version of Windows is Windows Sandbox by Surur @mspoweruser Dec 19, 2018 at 1:40 GMT As h ...

随机推荐

  1. oracle 存储过程中调用存储过程

    create procedure sp_name() begin ……… end 比如: create procedure pro_showdbs() show datebase; end //用ex ...

  2. git branch使用

    (1) git配置global信息: git config --global user.name "Your Name" git config --global user.emai ...

  3. 【GoLang】golang中 channel 实现同步 与mutex/atomic 实现同步的讨论

    参考资料: https://groups.google.com/forum/#!topic/golang-china/q4pFH-AGnfs

  4. JavaScript工作原理和Node异步I/O

    1. 什么是JavaScript解析引擎? 简单地说,JavaScript解析引擎就是能够“读懂”JavaScript代码,并准确地给出代码运行结果的一段程序.比如var a=1+2:对于静态语言来说 ...

  5. WinForm开发框架--动态读取DLL模式

    1\ WinForm开发框架--动态读取DLL模式   http://www.2cto.com/kf/201306/217199.html 2\ 广州爱奇迪     http://www.iqidi. ...

  6. 通过nsenter连接docker容器

    通常连接Docker容器并与其进行交互有四种方法.详情见:https://github.com/berresch/Docker-Enter-Demo,下面摘录nsenter连接的方式. 查看是否安装n ...

  7. CEF3开发者系列之JS与C++交互之一

    JS与Native交互是相对于比较困难的技术,在学习这门技术之前,我们先了解下浏览器内核中的JS引擎与chromium内核的V8引擎相关知识.在浏览器应用中,JS与本地代码互相调用,得益于浏览器内核对 ...

  8. ios UIWindow 错误使用导致无法接收motionEnded(摇一摇)函数

    今天遇到一个问题,第一次运行程序时,- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event函数无法调用,第二次就好了 ...

  9. Zookeeper服务常用的操作命令

    Zookeeper服务安装之后,一般会在这个服务的基础之上安装其他的大数据平台,其他的框架一般会提供很多接口对Zookeeper中的内容进行一定的操作,但是功能相对单一,所以有些时候,有必要我们自己登 ...

  10. 【leetcode】Evaluate Reverse Polish Notation(middle)

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...