stride3d/stride · error · InvalidOperationException
AVAssetReader create failed
Error message
AVAssetReader create failed: {error.LocalizedDescription} What it means
AVAssetReader.FromAsset failed to construct an AVAssetReader for the extracted asset slice; Apple reported an NSError whose LocalizedDescription is embedded in the message. This wraps the underlying AVFoundation failure so the backend can abort loading/seeking cleanly.
Solutions
- Inspect error.LocalizedDescription in the message for the concrete AVFoundation cause
- Verify the temp file exists and is a valid movie (test with AVAsset status)
- Re-encode the video to an Apple-supported format (H.264/H.265 in MP4/MOV)
- Check disk space and sandbox write permissions for the temp directory
- Confirm the URL/slice arguments (startPosition, length) point at a complete asset
Defensive patterns
Strategy: try-catch
Validate before calling
var asset = AVAsset.FromUrl(NSUrl.FromFilename(tempFilePath));
if (asset == null || !asset.Playable || asset.Tracks.Length == 0)
throw new InvalidOperationException("Asset missing or not playable before CreateReader"); Type guard
bool AssetReadable(NSUrl url) => NSFileManager.DefaultManager.FileExists(url.Path) && AVAsset.FromUrl(url)?.Playable == true;
Try / catch
try { backend.Initialize(url, start, len); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("AVAssetReader create failed"))
{ /* log AVFoundation error; fall back to software decode or re-encode */ } Prevention
- Ship only Apple-supported codecs/containers (H.264/H.265 MP4/MOV)
- Verify temp extraction succeeded and file is non-empty before init
- Check disk space and sandbox permissions for temp files
When it happens
Trigger: The asset slice file extracted to the temp path is not readable/valid video; the media format is unsupported by AVAssetReader; the NSUrl points at a missing or empty temp file; internal AVFoundation errors (e.g. failed to open, unsupported codec).
Common situations: Downloading/streamed videos with unsupported codecs (e.g. certain VP9/AV1 containers); temp file extraction partially failed (disk full, sandbox restrictions); URLs pointing at assets not present in the app bundle.
Related errors
- AVAssetReader.StartReading failed
- AVFoundationVideoBackend already initialized.
- AVAssetReader (audio) create failed
- AVAssetReader.StartReading (audio) failed
- Failed to compile a video asset, ffmpeg was not found.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/80aefad6349d2741.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Video/Backends/AVFoundationVideoBackend.cs:261
{
if (imageBuffer is CVPixelBuffer pixelBuffer)
{
UploadFrameToTarget(pixelBuffer);
}
}
adjustedTicksSinceLastFrame %= frameDurationTicks;
presentedSampleBuffer?.Dispose();
presentedSampleBuffer = sampleBuffer;
}
private void CreateReader(TimeSpan startTime)
{
DisposeReader();
reader = AVAssetReader.FromAsset(asset, out var error);
if (error != null)
throw new InvalidOperationException($"AVAssetReader create failed: {error.LocalizedDescription}");
if (startTime > TimeSpan.Zero)
{
// Timescale 600 covers all common video framerates exactly (24/25/30/50/60 fps all
// hit integer tick counts at 600).
var startCMTime = new CMTime((long)(startTime.TotalSeconds * 600), 600);
reader.TimeRange = new CMTimeRange { Start = startCMTime, Duration = CMTime.PositiveInfinity };
}
// Ask the reader to deliver decoded BGRA pixel buffers backed by IOSurface. BGRA is the
// VideoToolbox native output format for H.264/HEVC SDR content — picking it avoids an
// internal NV12→RGB conversion. The IOSurface is imported as a VkImage in UploadFrameToTarget.
var settings = new NSMutableDictionary
{
[CVPixelBuffer.PixelFormatTypeKey] = NSNumber.FromInt32((int)CVPixelFormatType.CV32BGRA),
[CVPixelBuffer.IOSurfacePropertiesKey] = new NSDictionary(),
};
videoOutput = new AVAssetReaderTrackOutput(videoTrack, settings)View on GitHub (pinned to 96fad776d2)