Home

Awesome

FFME: The Advanced WPF MediaElement Alternative

Join the chat at https://gitter.im/ffmediaelement/Lobby Analytics NuGet version NuGet Build status Codacy Badge

:star: Please star this project if you like it and show your appreciation via PayPal.Me

ffmeplay

Status Updates

Please note the current NuGet realease might require a different version of the FFmpeg binaries than the ones of the current state of the source code.

Quick Usage Guide for WPF Apps

Get Started

  1. Open Visual Studio and create a new WPF Application.

    Target Framework must be set to .net 5.0 or above

  2. Install the NuGet Package from your Package Manager Console:

    PM> Install-Package FFME.Windows
    
  3. Acquire the FFmpeg shared binaries (either 64 or 32 bit, depending on your app's target architecture)

    by either

  1. Within your application's startup code (Main method)

    set the Unosquare.FFME.Library.FFmpegDirectory variable to the path of the folder where the DLLs and EXEs are located, e.g.

Unosquare.FFME.Library.FFmpegDirectory = @"c:\ffmpeg";

And use the FFME MediaElement control as you would any other WPF control.

Example

in your main window (e.g MainWindow.xaml)

Additional Usage Notes

Features Overview

FFME is an advanced and close drop-in replacement for <a href="https://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement(v=vs.110).aspx">Microsoft's WPF MediaElement Control</a>. While the standard MediaElement uses DirectX (DirectShow) for media playback, FFME uses <a href="http://ffmpeg.org/">FFmpeg</a> 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:

... all in a single MediaElement control

FFME also supports opening capture devices. See example URLs below and issue #48

device://dshow/?audio=Microphone (Vengeance 2100):video=MS Webcam 4000
device://gdigrab?title=Command Prompt
device://gdigrab?desktop

If you'd like audio to not change pitch while changing the SpeedRatio property, you'll need the SoundTouch.dll library v2.1.1 available on the same directory as the FFmpeg binaries. You can get the SoundTouch library here.

About how it works

First off, let's review a few concepts. A packet is a group of bytes read from the input. All packets are of a specific MediaType (Audio, Video, Subtitle, Data), and contain some timing information and most importantly compressed data. Packets are sent to a Codec and in turn, the codec produces Frames. Please note that producing 1 frame does not always take exactly 1 packet. A packet may contain many frames but also a frame may require several packets for the decoder to build it. Frames will contain timing informattion and the raw, uncompressed data. Now, you may think you can use frames and show pixels on the screen or send samples to the sound card. We are close, but we still need to do some additional processing. Turns out different Codecs will produce different uncompressed data formats. For example, some video codecs will output pixel data in ARGB, some others in RGB, and some other in YUV420. Therefore, we will need to Convert these frames into something all hardware can use natively. I call these converted frames, MediaBlocks. These MediaBlocks will contain uncompressed data in standard Audio and Video formats that all hardware is able to receive.

The process described above is implemented in 3 different layers:

A high-level diagram is provided as additional reference below. arch-michelob-2.0

Some Work In Progress

Your help is welcome!

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.

  1. Clone this repository and make sure you have <a href="https://dotnet.microsoft.com/download/dotnet-core/3.1">.Net Core 3.1 or above</a> installed.
  2. Download the FFmpeg shared binaries for your target architecture: <a href="https://ffmpeg.org/download.html">FFmpeg Windows Downloads</a>.
  3. Extract the contents of the <code>zip</code> file you just downloaded and go to the <code>bin</code> folder that got extracted. You should see 3 <code>exe</code> files and multiple <code>dll</code> files. Select and copy all of them.
  4. Now paste all files from the prior step onto a well-known folder. Take note of the full path. (I used c:\ffmpeg\)
  5. Open the solution and set the <code>Unosquare.FFME.Windows.Sample</code> project as the startup project. You can do this by right clicking on the project and selecting <code>Set as startup project</code>. Please note that you will need Visual Studio 2019 with dotnet 5.0 SDK for your target architecture installed.
  6. Under the <code>Unosquare.FFME.Windows.Sample</code> project, find the file App.xaml.cs and under the constructor, locate the line <code>Library.FFmpegDirectory = @"c:\ffmpeg";</code> and replace the path so that it points to the folder where you extracted your FFmpeg binaries (dll files).
  7. Click on <code>Start</code> to run the project.
  8. You should see a sample media player. Click on the <code>Open</code> icon located at the bottom right and enter a URL or path to a media file.
  9. The file or URL should play immediately, and all the properties should display to the right of the media display by clicking on the <code>Info</code> icon.
  10. You can use the resulting compiled assemblies in your project without further dependencies. Look for ffme.win.dll.

ffmeplay.exe Sample Application

The source code for this project contains a very capable media player (FFME.Windows.Sample) covering most of the use cases for the FFME control. If you are just checking things out, here is a quick set of shortcut keys that ffmeplay accepts.

Shortcut KeyFunction Description
GExample of toggling subtitle color
LeftSeek 1 frame to the left
RightSeek 1 frame to the right
+ / Volume UpIncrease Audio Volume
- / Volume DownDecrease Audio Volume
M / Volume MuteMute Audio
UpIncrease playback Speed
DownDecrease playback speed
ACycle Through Audio Streams
SCycle Through Subtitle Streams
QCycle Through Video Streams
CCycle Through Closed Caption Channels
RReset Changes
Y / HContrast: Increase / Decrease
U / JBrightness: Increase / Decrease
I / KSaturation: Increase / Decrease
EExample of cycling through audio filters
TCapture Screenshot to desktop/ffplay folder
WStart/Stop recording packets (no transcoding) into a transport stream to desktop/ffplay folder.
Double-clickEnter fullscreen
EscapeExit fullscreen
Mouse Wheel Up / DownZoom: In / Out

Thanks

In no particular order

Similar Projects

License