Skip to content

Files

Latest commit

08b568f · Mar 21, 2021

History

History
This branch is 126 commits ahead of, 790 commits behind SuRGeoNix/Flyleaf:master.

VideoPlayer_HWAcceleration

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jun 4, 2020
Jun 4, 2020
Mar 4, 2021
Mar 4, 2021
Jun 4, 2020
Mar 4, 2021
Jun 4, 2020
Mar 4, 2021
Jun 4, 2020
Mar 21, 2021
Jun 4, 2020
Mar 21, 2021

C# Video Demuxing & Hardware(GPU) Decoding / Processing Acceleration Tutorial

(Based on FFmpeg.Autogen bindings for FFmpeg & SharpDX bindings for DirectX)

Lately, I've decided to develop a Video Player for educational purposes as I've never messed with this field before and I found it very interesting (especially for its difficulty and complexity). That's the reason for writing this tutorial, that hopefully will help others to cross those obstacles (on this tutorial focusing on Video Acceleration only).

The very first problem that I came across was the programming language choice that I've made (C# .NET) and that's because there are not any official FFmpeg (for Decoding/Demuxing) or Microsoft DirectX (for Hardware/GPU Acceleration) Libraries. The only solution that I've found was to use the FFmpeg.Autogen C# bindings for FFmpeg and SharpDX (deprecated) for Microsoft DirectX.

The second problem was the lack of documentation for both these Libraries. So many years of their existence and their writings are unfortunately still poor. The only way to understand how they work is by reading low-level large open source code (from projects such as VLC, Kodi etc.).

The main process that this Project/Tutorial follows is the following :-

  • Creating a Direct3D 11 Device (both for Rendering & Decoding)
  • Parsing our Direct3D 11 Device to FFmpeg and initializing FFmpeg's HW Device Context
  • Parsing the created HW Device Context to the desired Video Codec (during Opening Codec)
  • FFmpeg Demuxing packets & HW Decoding Video Frames (NV12 | P010)
  • Copying from FFmpeg's Texture2D Pool array the current decoded Video Frame (CopySubresourceRegion)
  • DirectX Video Processing (VideoProcessorBlt) HW texture (Directly to Backbuffer)
  • Rendering the Backbuffer (PresentFrame)

With the above process we manage to perform both Video Decoding but also Video Proccessing (NV12->RGB) without "touching" our CPU/RAM.

Required Libraries

  • SharpDX (Latest) – NuGet Package
  • FFmpeg.Autogen (Latest) – NuGet Package
  • FFmpeg (Compatible with FFmpeg.Autogen – GPL shared)
  • Check FFmpeg.RegisterFFmpegBinaries() to link FFmpeg .dll libraries