2

我正在尝试使用桌面复制 API 捕获我的桌面,使用 NVENC 对 D3DTexture2D 进行编码并通过本地网络发送它。在我到达需要锁定比特流并提取数据的部分之前,一切的性能都非常高。下面是使用的代码:

        NV_ENC_LOCK_BITSTREAM lockBitstreamData = { NV_ENC_LOCK_BITSTREAM_VER };
        lockBitstreamData.outputBitstream = vOutputBuffer[m_iGot % m_nEncoderBuffer];
        lockBitstreamData.doNotWait = false;
        auto starti = std::chrono::system_clock::now();
        NVENC_API_CALL(m_nvenc.nvEncLockBitstream(m_hEncoder, &lockBitstreamData));
        auto end = std::chrono::system_clock::now();
        std::chrono::duration<double> elapsed_seconds = end - starti;
        std::time_t end_time = std::chrono::system_clock::to_time_t(end);

        std::cout << "finished computation at " << std::ctime(&end_time)
            << "elapsed time: " << elapsed_seconds.count() << "s\n";
        uint8_t *pData = (uint8_t *)lockBitstreamData.bitstreamBufferPtr;

        if (vPacket.size() < i + 1)
        {
            vPacket.push_back(std::vector<uint8_t>());
        }

        vPacket[i].clear();
        vPacket[i].insert(vPacket[i].end(), &pData[0], &pData[lockBitstreamData.bitstreamSizeInBytes]);
        i++;

        NVENC_API_CALL(m_nvenc.nvEncUnlockBitstream(m_hEncoder, lockBitstreamData.outputBitstream));

“NVENC_API_CALL(m_nvenc.nvEncLockBitstream(m_hEncoder, &lockBitstreamData));” 从桌面低负载下的 10 毫秒到我在高负载下全屏运行游戏时的平均 90 毫秒。我们的约束要求“实时”60fps,所以超过 16ms 的任何东西都太高了。有没有办法让它下来?

4

0 回答 0