XAppCaptureReadLocalStream

Reads the contents of the .mp4 file generated by an earlier call to XAppCaptureRecordTimespan.

Syntax

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

Parameters

handle _In_
Type: XAppCaptureLocalStreamHandle

Handle to the local recording file that was created by XAppCaptureRecordTimespan earlier.

startPosition _In_
Type: size_t

Start position in the stream.

bytesToRead _In_
Type: uint32_t

Number of bytes to read.

buffer _Out_writes_to_(bytesToRead, *bytesWritten)
Type: uint8_t *

The buffer to write the stream data to.

bytesWritten _Out_
Type: uint32_t *

On function completion, contains the number of bytes written to the supplied buffer.

Return value

Type: HRESULT

Function result.

Remarks

A maximum of two recordings can exist at once. On stream close, the file is deleted. When the game exits, recordings will automatically be deleted to prevent stale files.

See XAppCaptureRecordTimespan on how to obtain 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);

Requirements

Header: XAppCapture.h

Library: xgameruntime.lib

Supported platforms: Windows, Xbox One family consoles and Xbox Series consoles

See also

XAppCapture members