XAppCaptureReadLocalStream

读取由先前对 XAppCaptureRecordTimespan 的调用生成的 .mp4 文件的内容。

语法

HRESULT XAppCaptureReadLocalStream(
  XAppCaptureLocalStreamHandle handle,
  size_t startPosition,
  uint32_t bytesToRead,
  uint8_t * buffer,
  uint32_t * bytesWritten
)

参数

handle _In_
类型:XAppCaptureLocalStreamHandle

XAppCaptureRecordTimespan 之前创建的本地录制文件的句柄。

startPosition _In_
类型:size_t

流中的起始位置。

bytesToRead _In_
类型:uint32_t

要读取的字节数。

buffer _Out_writes_to_(bytesToRead, *bytesWritten)
类型:uint8_t *

要将流数据写入其中的缓冲区。

bytesWritten _Out_
类型:uint32_t *

函数完成时,包含写入到提供的缓冲区的字节数。

返回值

类型:HRESULT

函数结果。

备注

一次最多可以存在两个录制文件。 在关闭流时,将删除该文件。 当游戏退出时,将自动删除录制内容以防止出现过时文件。

请参阅 XAppCaptureRecordTimespan,以了解如何获取 XAppCaptureLocalResult

const int MAX_DATA = 1024;

XAppCaptureLocalResult localResult = {0};
XAppCaptureLocalStreamHandle localHandle = nullptr;
HANDLE file = INVALID_HANDLE_VALUE;

uint8_t buffer[MAX_DATA];
/* 5 seconds, for example. You should call XAppCaptureGetVideoCaptureSettings() to ensure there's sufficient duration available */
uint64_t durationInMs = 5000;
size_t totalBytesRead = 0;
size_t fileSize = 0;

XAppCaptureRecordTimespan(nullptr, durationInMs, &localResult);

localHandle = localResult.clipHandle;
fileSize = localResult.fileSizeInBytes;

/* T:\ is one example of a writeable local directory. Be aware that the T:\ drive can be invalidated on suspend or resume, and as such it's better to use PLS */ 
file = CreateFileA("T:\\MyFile.mp4", GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

while (totalBytesRead < fileSize)
{
    uint32_t bytesRead = 0;
    uint32_t bytesWritten = 0;
    if (SUCCEEDED(XAppCaptureReadLocalStream(localHandle, totalBytesRead, sizeof(buffer), buffer, &bytesRead)))
    {
        WriteFile(file, buffer, bytesRead, &bytesWritten, NULL);

        totalBytesRead += bytesRead;
    }
    else
    {
        break;
    }
}

/* You must always close a local stream handle even if nothing was read in */
XAppCaptureCloseLocalStream(localHandle);

要求

头文件:XAppCapture.h

库:xgameruntime.lib

支持平台:Windows、Xbox One 系列主机和 Xbox Series 主机

另请参阅

XAppCapture 成员