Hardware Acceleration

This topic explains how to enable Intel Graphics, AMD, or NVIDIA hardware acceleration.

For detailed information about the supported hardware platforms, see About Hardware Acceleration.

.NET

To enable hardware encoding, on the output MediaPin, set the HardwareEncoder parameter to HardwareEncoder.Auto. This must be done before calling Transcoder.Open:

// create output socket
var outputSocket = MediaSocket.FromPreset(Preset.Video.iPad.H264_720p);

// enable hardware acceleration
var outVideoPin = outputSocket.Pins[0];
outVideoPin.Params.Add(Param.HardwareEncoder, HardwareEncoder.Auto);

Complete .NET Code

using PrimoSoftware.AVBlocks;

namespace HardwareEncoding
{
    class Program
    {
        static void Main(string[] args)
        {
            Library.Initialize();

            var inputInfo = new MediaInfo() {
                InputFile = "Wildlife.wmv"
            };

            if (inputInfo.Load()) {

                // create input socket
                var inputSocket = MediaSocket.FromMediaInfo(inputInfo);

                // create output socket
                var outputSocket = MediaSocket.FromPreset(Preset.Video.iPad.H264_720p);

                // enable hardware acceleration
                var outVideoPin = outputSocket.Pins[0];
                outVideoPin.Params.Add(Param.HardwareEncoder, HardwareEncoder.Auto);

                outputSocket.File = "Wildlife.mp4";

                // configure Transcoder and run 
                using (var transcoder = new Transcoder())
                {
                    transcoder.AllowDemoMode = true;

                    transcoder.Inputs.Add(inputSocket);
                    transcoder.Outputs.Add(outputSocket);

                    if (transcoder.Open())
                    {
                        transcoder.Run();
                        transcoder.Close();
                    }
                }
            }

            Library.Shutdown();
        }
    }
}

C++

To enable hardware encoding, on the output MediaPin*, set the HardwareEncoder parameter to HardwareEncoder::Auto. This must be done before calling Transcoder::open:

// create output socket
auto outputSocket = primo::make_ref(
    Library::createMediaSocket(Preset::Video::iPad::H264_720p)
);

// enable hardware acceleration
auto outVideoPin = outputSocket->pins()->at(0);
outVideoPin->params()->addInt(Param::HardwareEncoder, HardwareEncoder::Auto);

Complete C++ Code

// HardwareEncoding.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

using namespace primo::codecs;
using namespace primo::avblocks;

int _tmain(int argc, _TCHAR* argv[])
{
    // needed for Windows Media Codecs
    CoInitializeEx(nullptr, COINITBASE_MULTITHREADED);

    Library::initialize();

    auto inputInfo = primo::make_ref(
        Library::createMediaInfo()
    );
    inputInfo->setInputFile(L"Wildlife.wmv");

    if (inputInfo->load()) {

        // create input socket
        auto inputSocket = primo::make_ref(
            Library::createMediaSocket(inputInfo.get())
        );

        // create output socket
        auto outputSocket = primo::make_ref(
            Library::createMediaSocket(Preset::Video::iPad::H264_720p)
        );

        // enable hardware acceleration
        auto outVideoPin = outputSocket->pins()->at(0);
        outVideoPin->params()->addInt(Param::HardwareEncoder, HardwareEncoder::Auto);

        outputSocket->setFile(L"Wildlife.mp4");

        // configure Transcoder inputs and outputs 
        auto transcoder = primo::make_ref(
            Library::createTranscoder()
        );

        transcoder->inputs()->add(inputSocket.get());
        transcoder->outputs()->add(outputSocket.get());

        // run Transcoder
        if (transcoder->open()) {
            transcoder->run();
            transcoder->close();
        }
    }

    Library::shutdown();

    CoUninitialize();

    return 0;
}


Last updated on April 8th, 2017 02:55:54 PM