从 Windows 服务执行的子进程中使用 DirectX

Igo*_*lik 5 c# directx winapi windows-services ffmpeg

我需要从 Windows 服务执行 ffmpeg 进程并捕获它的标准输出。它工作正常,直到我使用硬件加速。由于windows服务访问DirectX受到限制,子进程也无法访问。

当我从控制台应用程序执行相同的代码时,一切正常,但从 Windows 服务执行的相同代码无法使用硬件加速。

        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();
Run Code Online (Sandbox Code Playgroud)

我需要以某种方式打破继承的限制,以便能够通过硬件加速(访问 DirectX API)执行 ffmpeg。有什么建议?

VuV*_*irt 3

您可以指示 FFMPEG 进程使用DirectX 11 硬件视频加速。在这种情况下,FFMPEG 将需要通过调用D3D11CreateDevice函数来创建DirectX 11 设备,该函数不需要提供任何窗口句柄。

为了使 FFMPEG 使用 DirectX 11 硬件视频加速,您需要指定以下 hwaccel 参数:

-hwaccel d3d11va
Run Code Online (Sandbox Code Playgroud)