> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XAppCaptureReadLocalStream

> XAppCaptureReadLocalStream

# XAppCaptureReadLocalStream

Reads the contents of the .mp4 file generated by an earlier call to [XAppCaptureRecordTimespan](/reference/system/xappcapture/functions/xappcapturerecordtimespan).

## Syntax

```cpp theme={null}
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](/reference/system/xappcapture/functions/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](/reference/system/xappcapture/functions/xappcapturerecordtimespan) on how to obtain [XAppCaptureLocalResult](/reference/system/xappcapture/structs/xappcapturelocalresult).

```cpp theme={null}
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](/reference/system/xappcapture/xappcapture_members)


## Related topics

- [XAppCaptureRecordTimespan](/reference/system/xappcapture/functions/xappcapturerecordtimespan.md)
- [XAppCaptureLocalResult](/reference/system/xappcapture/structs/xappcapturelocalresult.md)
- [XAppCapture](/reference/system/xappcapture/xappcapture_members.md)
- [Unity C# API wrappers for the GDK](/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XAppCaptureReadScreenshotStream](/reference/system/xappcapture/functions/xappcapturereadscreenshotstream.md)
