⭐Please star this project if you find it useful!
FFME is a close 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 implements additional improvements over the standard MediaElement such as:
- Asynchronous and synchronous frame scrubbing
- Fast media seeking
- Frame-by-frame seeking
- Media properties such as Position, NaturalDuration, SpeedRatio, and Volume (among others) are exposed as dependency properties
- Additional and extended media events
... all in a self-contained assembly (dll)
Your help is welcome!
- SpeedRatio other than 1.0 should 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 NAudio.
- (To be confirmed) Writing to the Position dependency property from another dependency property may make the source value lose synchronization with the target value.
- (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.
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.
- Before you open the solution, please make sure you download the FFmpeg win32-shared binaries from Zeranoe FFmpeg Builds.
- Extract the contents of the
7z
file you just downloaded and locate thebin
folder. - You should see 3
exe
files and 8dll
files. Select and copy all of them. - Now paste all 11 files from the prior step onto the following folder (inside the cloned repository):
{repositiories root}\ffmediaelement\Unosquare.FFmpegMediaElement\ffmpeg32
. - Open the solution and set the
Unosquare.FFmpegMediaElement.Tests
project as the startup project. You can do this by right clicking on the project and selectingSet as startup project
- Click on
Start
to 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 top of the window and then click on
Open
. - The file or URL should play immediately.
- You can use the resulting compiled assembly in your project without further dependencies FFME is entirely self-contained. The locations of the compiled FFME assembly, depending on your build configuration are either
...\ffmediaelement\Unosquare.FFmpegMediaElement\bin\Debug\Unosquare.FFmpegMediaElement.dll
or...\ffmediaelement\Unosquare.FFmpegMediaElement\bin\Release\Unosquare.FFmpegMediaElement.dll
The Unosquare.FFmpegMediaElement.Tests project shows most common usages
- Create a new WPF application
- Add a reference to
Unosquare.FFmpegMediaElement.dll
- In your
MainForm.xaml
, add the namespace:xmlns:ffme="clr-namespace:Unosquare.FFmpegMediaElement;assembly=Unosquare.FFmpegMediaElement"
- 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" />
In no particular order
- To the FFmpeg team for making the Swiss Army Knife of media.
- 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
- 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.
- The NAudio portion of this library
Unosquare.FFmpegMediaElement\NAudio
is distributed under Ms-PL. Please see LICENSE.txt. - Code generated by the FFmpeg.Autogen tool
Unosquare.FFmpegMediaElement\FFmpeg.Autogen
does 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.