Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DirectX from subprocess executed by windows service

I need to execute ffmpeg process from windows service and capture it's standard output. It works fine until I use hardware acceleration. Because accessing DirectX from windows service is restricted, the subprocess also fails to access it.

When I'm executing the same code from console application, everything works OK, but the same code executed from windows service fails to use hardware acceleration.

        string ffmpegArgs = /*-hwaccel dxva2 */"-threads 0 -probesize 100512 -i c:/Temp/test.mp4 -vf yadif -vcodec libx264 -preset ultrafast -tune zerolatency -profile baseline -x264-params keyint=20:min-keyint=20:scenecut=-1 -acodec aac -b:a 48k -flags +cgop -f mp4 -movflags empty_moov+default_base_moof+frag_keyframe c:/temp/output.avi";

        var psi = new ProcessStartInfo
        {
            FileName = "c:/Temp/ffmpeg4/ffmpeg.exe",
            Arguments = ffmpegArgs,
            WorkingDirectory = "c:/Temp/ffmpeg4",
            CreateNoWindow = false,
            WindowStyle = ProcessWindowStyle.Hidden,
            RedirectStandardInput = false,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            UseShellExecute = false
        };

        var processVideo = new Process { StartInfo = psi }.Start();

I need somehow break the inherited restrictions to be able to execute ffmpeg with hardware acceleration (access DirectX API). Any suggestions?

like image 833
Igor Gorelik Avatar asked Oct 27 '22 14:10

Igor Gorelik


1 Answers

You can instruct FFMPEG process to use DirectX 11 Hardware Video acceleration. In this case, FFMPEG will need to create a DirectX 11 device, by calling D3D11CreateDevice function, which doesn't need any window handles to be supplied.

In order to make FFMPEG utlize DirectX 11 hardware video acceleration, you need to specify the following hwaccel parameter instead:

-hwaccel d3d11va
like image 110
VuVirt Avatar answered Nov 10 '22 14:11

VuVirt