Skip to content

smcilveen/ffmediaelement

 
 

Repository files navigation

FFME: WPF MediaElement Alternative

Analytics

⭐Please star this project if you find it useful!

Features Overview

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)

Known Limitations

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.

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

  1. Clone this repository.
  2. Before you open the solution, please make sure you download the FFmpeg win32-shared binaries from Zeranoe FFmpeg Builds.
  3. Extract the contents of the 7z file you just downloaded and locate the bin folder.
  4. You should see 3 exe files and 8 dll files. Select and copy all of them.
  5. Now paste all 11 files from the prior step onto the following folder (inside the cloned repository): {repositiories root}\ffmediaelement\Unosquare.FFmpegMediaElement\ffmpeg32.
  6. 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 selecting Set as startup project
  7. Click on Start to run the project.
  8. 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.
  9. The file or URL should play immediately.
  10. 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

Using FFME in your Project

The Unosquare.FFmpegMediaElement.Tests project shows most common usages

  1. Create a new WPF application
  2. Add a reference to Unosquare.FFmpegMediaElement.dll
  3. In your MainForm.xaml, add the namespace: xmlns:ffme="clr-namespace:Unosquare.FFmpegMediaElement;assembly=Unosquare.FFmpegMediaElement"
  4. 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

Similar Projects

License

  • 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.

About

WPF MediaElement replacement based on FFmpeg

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 51.6%
  • Smalltalk 48.4%