FFME: WPF MediaElement Alternative
⭐Please star this project if you find it useful!
- Current Status: (2017-12-121) - 2.0, codenamed Michelob is now in beta 2 (see the Releases)
- NuGet Package now available: https://www.nuget.org/packages/FFME.Windows/
- FFmpeg Version: 3.4.0 (32-bit)
- For a history of commits see the repo: https://github.com/unosquare/ffplaydotnet
Features Overview
FFME is a close (and I'd like to think better) drop-in replacement for Microsoft's WPF MediaElement Control. While the standard MediaElement uses DirectX (DirectShow) for media playback, FFME uses FFmpeg to read and decode audio and video. This means that for those of you who want to support stuff like HLS playback, or just don't want to go through the hassle of installing codecs on client machines, using FFME might just be the answer.
FFME provides multiple improvements over the standard MediaElement such as:
- Fast media seeking and frame-by-frame seeking
- Properties such as Position, NaturalDuration, SpeedRatio, and Volume are all Dependency Properties!
- Additional and extended media events. Extracting (and modifying) video, audio and subtitle frames is very easy.
- Ability to easily apply FFmpeg video and audio filtergraphs.
- Ability to extract media metadata and tech specs of a media stream (title, album, bitrate, codecs, FPS, etc).
- Ability to apply volume, balance and speed ratio to media playback.
... all in a single MediaElement control
Known Limitations
Your help is welcome!
- I still have some items I need to address. See the issues section.
- Working on Hardware acceleration D3D 9 and D3D 11
- There currently is no support for opening capture devices such as webcams or TV cards. While this is not too hard to do, it is not (yet) implemented in this library. See issue #48
Windows: Compiling, Running and Testing
Please note that I am unable to distribute FFmpeg's binaries because I don't know if I am allowed to do so. Follow the instructions below to compile, run and test FFME. I will look into releasing a NuGet package. See issue #1
- Clone this repository.
- Download the FFmpeg win32-shared binaries from Zeranoe FFmpeg Builds.
- Extract the contents of the
zip
file you just downloaded and go to thebin
folder that got extracted. You should see 3exe
files and 8dll
files. Select and copy all of them. - Now paste all 11 files from the prior step onto a well-known folder. Take note of the full path. (I used c:\ffmpeg)
- Open the solution and set the
Unosquare.FFME.Windows.Sample
project as the startup project. You can do this by right clicking on the project and selectingSet as startup project
- Under the
Unosquare.FFME.Windows.Sample
project, locate the linepublic string FFmpegPath { get; set; } = @"C:\ffmpeg";
and replace the path so that it points to the folder where you extracted your FFmpeg binaries (dll files). - Click on
Start
to run the project. - You should see a sample media player. Click on the
Open
icon located at the bottom right and enter a URL or path to a media file. - The file or URL should play immediately, and all the properties should display to the right of the media display by clicking on the
Info
icon. - You can use the resulting compiled assemblies in your project without further dependencies. Look for both
ffme.common.dll
andffme.win.dll
.
Windows: NuGet Installation
PM> Install-Package FFME.Windows
Windows: Troubleshooting
If you get the following error: The current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0.
Simply download and install .NET Core SDK v2 or later.
MacOS: Sample Player (in preview)
Compile FFmpeg for Mac (instructions can be found on FFmpeg.AutoGen) and copy the following libraries from /opt/local/lib
's to /Users/{USER}/ffmpeg
(~/ffmpeg
):
- avcodec.57.dylib
- avdevice.57.dylib
- avfilter.6.dylib
- avformat.57.dylib
- avutil.55.dylib
- swresample.2.dylib
- swscale.4.dylib
Note: when building FFmpeg locally, compiled libraries are named differently than in the list above. E.g. avcodec.57.dylib
is actually named libavcodec.57.89.100.dylib
. To properly load libraries, copy and rename each library to match the format in the list above.
In the sample MacOS player, the FFmpeg folder is configured to point to ~/ffmpeg
in the following line of code:
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "ffmpeg");
Note that this can be customized to point to any other folder.
When distributing the player and the associated libraries with your application, dll files should be added to the project as BundleResource
items. Also, each library should be copied to the output directory on build. Afterwards, change the above configuration to use Environment.CurrentDirectory
to search for FFmpeg libraries.
MacOS: Troubleshooting
Make sure you have Xamarin for Visual Studio 2017 installed if you want to open the MacOS projects.
Windows: Using FFME in your WPF Project
Remember: The Unosquare.FFME.Windows.Sample provides a reference implementation of usage
- Create a new WPF application
- Add a reference to
ffme.win.dll
or installFFME.Windows
via NuGet - In your
MainForm.xaml
, add the namespace:xmlns:ffme="clr-namespace:Unosquare.FFME;assembly=ffme.win"
- Finally, create an instance of the FFME control in your
MainForm.xaml
as follows:<ffme:MediaElement x:Name="MediaEl" Background="Gray" LoadedBehavior="Play" UnloadedBehavior="Manual" />
Thanks
In no particular order
- To the FFmpeg team for making the Swiss Army Knife of media. I encourage you to donate to them.
- To Kyle Schwarz for creating and making Zeranoe FFmpeg builds available to everyone.
- To the NAudio team for making the best audio library out there for .NET -- one day I will contribute some improvements I have noticed they need.
- To Ruslan Balanukhin for his FFmpeg interop bindings generator tool: FFmpeg.AutoGen.
- To Martin Bohme for his tutorial on creating a video player with FFmpeg.
- To Barry Mieny for his beautiful FFmpeg logo
Similar Projects
License
- Please refer to the LICENSE file for more information.