{"record":{"id":"80aefad6349d2741","repo":"stride3d/stride","slug":"avassetreader-create-failed-error-localizeddescription","errorCode":null,"errorMessage":"AVAssetReader create failed: {error.LocalizedDescription}","messagePattern":"AVAssetReader create failed: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Video/Backends/AVFoundationVideoBackend.cs","lineNumber":261,"sourceCode":"        {\n            if (imageBuffer is CVPixelBuffer pixelBuffer)\n            {\n                UploadFrameToTarget(pixelBuffer);\n            }\n        }\n        adjustedTicksSinceLastFrame %= frameDurationTicks;\n\n        presentedSampleBuffer?.Dispose();\n        presentedSampleBuffer = sampleBuffer;\n    }\n\n    private void CreateReader(TimeSpan startTime)\n    {\n        DisposeReader();\n\n        reader = AVAssetReader.FromAsset(asset, out var error);\n        if (error != null)\n            throw new InvalidOperationException($\"AVAssetReader create failed: {error.LocalizedDescription}\");\n\n        if (startTime > TimeSpan.Zero)\n        {\n            // Timescale 600 covers all common video framerates exactly (24/25/30/50/60 fps all\n            // hit integer tick counts at 600).\n            var startCMTime = new CMTime((long)(startTime.TotalSeconds * 600), 600);\n            reader.TimeRange = new CMTimeRange { Start = startCMTime, Duration = CMTime.PositiveInfinity };\n        }\n\n        // Ask the reader to deliver decoded BGRA pixel buffers backed by IOSurface. BGRA is the\n        // VideoToolbox native output format for H.264/HEVC SDR content — picking it avoids an\n        // internal NV12→RGB conversion. The IOSurface is imported as a VkImage in UploadFrameToTarget.\n        var settings = new NSMutableDictionary\n        {\n            [CVPixelBuffer.PixelFormatTypeKey] = NSNumber.FromInt32((int)CVPixelFormatType.CV32BGRA),\n            [CVPixelBuffer.IOSurfacePropertiesKey] = new NSDictionary(),\n        };\n        videoOutput = new AVAssetReaderTrackOutput(videoTrack, settings)","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Video/Backends/AVFoundationVideoBackend.cs#L243-L279","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"var asset = AVAsset.FromUrl(NSUrl.FromFilename(tempFilePath));\nif (asset == null || !asset.Playable || asset.Tracks.Length == 0)\n    throw new InvalidOperationException(\"Asset missing or not playable before CreateReader\");","typeGuard":"bool AssetReadable(NSUrl url) => NSFileManager.DefaultManager.FileExists(url.Path) && AVAsset.FromUrl(url)?.Playable == true;","tryCatchPattern":"try { backend.Initialize(url, start, len); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"AVAssetReader create failed\"))\n{ /* log AVFoundation error; fall back to software decode or re-encode */ }","preventionTips":["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"],"tags":["ios","avfoundation","avassetreader","video"],"backgroundTag":"api-error-response","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}