FFME: WPF MediaElement Alternative
⭐Please star this project if you find it useful!
- MediaElement Status: Still Work in progress (see the Releases section for a code-complete version)
- Estimated Beta Release Date: 7/2/2017
- MediaElement Codename: Michelob (because it uses very little CPU and RAM!)
- FFmpeg Version: 3.2.4
- For a history of commits see the repo: https://github.com/unosquare/ffplaydotnet
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 be the answer.
FFME provides multiple improvements over the standard MediaElement such as:
- Asynchronous and synchronous frame scrubbing
- 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.
- Ability to easily apply filtergraphs.
- Ability to extract media metadata and tech specs of a media stream (title, album, bitrate, FPS, etc).
... all in a single MediaElement control
Your help is welcome!
- I still have a lot of TODOs in this new version -- but I am getting through them :)
- SpeedRatio other than 1.0 could adjust audio pitch. Currently, if SpeedRatio is less than 1.0, there is no audio playback, and if SpeedRatio is greater than 1.0, samples just play faster. This situation can be greatly improved by manually manipulating the samples passed to the Audio Renderer.
- (Nice to have) It would be nice to implement a method on the control that is able to extract a copy of the current video frame.
- 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.
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
- Clone this repository.
- Download the FFmpeg win32-shared binaries from Zeranoe FFmpeg Builds.
- Extract the contents of the
zipfile you just downloaded and go to the
binfolder that got extracted. You should see 3
exefiles and 8
dllfiles. Select and copy all of them.
- Now paste all 11 files from the prior step onto a well-known foleder. Take note of the full path.
- Open the solution and set the
Unosquare.FFME.Sampleproject as the startup project. You can do this by right clicking on the project and selecting
Set as startup project
- Under the
Unosquare.FFME.Sampleproject, locate the line
Unosquare.FFME.MediaElement.FFmpegDirectory = @"C:\ffmpeg";and replace the path so that it points to the folder where you extracted your FFmpeg binaries (dll files).
- Click on
Startto run the project.
- You should see a very simplistic media player. Enter a URL or a path to a file in the textbox at the bottom of the window and then click on
- The file or URL should play immediately, and all the properties should display to the right of the media display.
- You can use the resulting compiled assembly in your project without further dependencies as FFME is entirely self-contained. The locations of the compiled FFME assembly, depending on your build configuration are either
Using FFME in your Project
The Unosquare.FFME.Sample provides a reference implementation of usage
- Create a new WPF application
- Add a reference to
- In your
MainForm.xaml, add the namespace:
- Finally, create an instance of the FFME control in your
<ffme:MediaElement x:Name="MediaEl" Background="Gray" LoadedBehavior="Play" UnloadedBehavior="Manual" />
In no particular order
- To the FFmpeg team for making the Swiss Army Knife of media. I encourage 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 contribut improvements that they really need :P
- To Ruslan Balanukhin for his FFmpeg interop bindings generator tool: FFmpeg.AutoGen.
- To Martin Bohme for his excellent tutorial on creating a video player with FFmpeg.
- To Barry Mieny for his beautiful FFmpeg logo
- The NAudio portion of this library
Unosquare.FFME\NAudiois distributed under Ms-PL. Please see LICENSE.txt.
- Code generated by the FFmpeg.Autogen tool
Unosquare.FFME\FFmpeg.Autogendoes not specify a license by the tool's author.
- The source code of the FFME project excluding the items above is distributed under the Ms-PL.