unosquare / ffmediaelement

FFME: The Advanced WPF MediaElement (based on FFmpeg)
https://unosquare.github.io/ffmediaelement/
Other
1.17k stars 241 forks source link

Which method turns on hardware acceleration? #638

Open kuangxj opened 1 year ago

kuangxj commented 1 year ago

Issue Title (change this title!)

The CPU has always been high,and I want to reduce the performance of the CPU through hardware acceleration. I looked at the example and spent a lot of time not finding this method or example. Please tell me if you know.

Please enter a general description for the issue. Delete sections that are not relevant and provide additional sections if necessary.

Issue Categories

Version Information

Steps to Reproduce

  1. Step 1
  2. Step 2
  3. Step 3

Expected Results

Sample Code

XAML

<MainWindow>
</MainWindow>

C

System.Console.WriteLine("Change Me Please!");

Command line ffplay

ffplay "hello.mp4"

Delete This Section

OneB1t commented 1 year ago

onMediaOpening

        // Setting Advanced Video Stream Options is also possible
        if (e.Options.VideoStream is StreamInfo videoStream)
        {
            // Example of forcing a codec for a stream
            // e.Options.DecoderCodec[videoStream.StreamIndex] = "mjpeg";

            // Hardware device priorities
            var deviceCandidates = new[]
            {
                //AVHWDeviceType.AV_HWDEVICE_TYPE_CUDA,
                //AVHWDeviceType.AV_HWDEVICE_TYPE_D3D11VA,
                AVHWDeviceType.AV_HWDEVICE_TYPE_DXVA2
            };

           foreach (var deviceType in deviceCandidates)
           {
               var accelerator = videoStream.HardwareDevices.FirstOrDefault(d => d.DeviceType == deviceType);
               if (accelerator == null) continue;
               e.Options.VideoHardwareDevice = accelerator;

               break;
           }