{"record":{"id":"85635c32cad773a3","repo":"stride3d/stride","slug":"couldn-t-allocate-a-frame-for-decoding","errorCode":null,"errorMessage":"Couldn't allocate a frame for decoding.","messagePattern":"Couldn't allocate a frame for decoding\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"critical","filePath":"sources/engine/Stride.Video/FFmpeg/FFmpegMedia.cs","lineNumber":161,"sourceCode":"                Logger.Error($\"Could not find stream info. Error code={ret.ToString(\"X8\")}\");\n                Logger.Error(GetErrorMessage(ret));\n                throw new ApplicationException(@\"Could not find stream info.\");\n            }\n\n            AVFormatContext = pFormatContext;\n            Duration = TimeSpan.FromSeconds((double)AVFormatContext->duration / ffmpeg.AV_TIME_BASE);\n            Url = url;\n\n            // Get the streams\n            for (int i = 0; i < pFormatContext->nb_streams; i++)\n            {\n                var stream = FFmpegStream.Create(pFormatContext->streams[i], this);\n                streams.Add(stream);\n            }\n\n            pDecodedFrame = ffmpeg.av_frame_alloc();\n            if (pDecodedFrame == null)\n                throw new ApplicationException(\"Couldn't allocate a frame for decoding.\");\n\n            pCpuCopyFrame = ffmpeg.av_frame_alloc();\n            if (pCpuCopyFrame == null)\n                throw new ApplicationException(\"Couldn't allocate a frame for hardware decoding.\");\n\n            // dispose cached video image from previous file\n            ClearStreamInfo();\n        }\n\n        public bool SeekToTime([NotNull] FFmpegStream stream, long timestamp)\n        {\n            FFmpegUtils.EnsurePlatformSupport();\n\n            if (currentStreams.TryGetValue(stream, out var streamInfo))\n            {\n                // flush the codec buffered images\n                streamInfo.Codec.Flush(pDecodedFrame);\n            }","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Video/FFmpeg/FFmpegMedia.cs#L143-L179","documentation":"FFmpegMedia.Open allocates two reusable AVFrame structs (pDecodedFrame and pCpuCopyFrame) via ffmpeg.av_frame_alloc(). This error is thrown when the first allocation returns null, meaning FFmpeg could not allocate memory for the frame structure (typically an out-of-memory condition or an unloaded/broken native FFmpeg library).","triggerScenarios":"Calling Open() (via CreateAssets or DoCommandOverride) when ffmpeg.av_frame_alloc() returns null — i.e. the process is out of memory, or the FFmpeg native libraries are partially/corruptly loaded so the function cannot allocate.","commonSituations":"Low-memory environments (32-bit processes, embedded devices); corrupted or mismatched FFmpeg native binaries; running without proper native dependencies installed so allocation fails.","solutions":["Ensure 64-bit process and sufficient available memory before opening media","Verify the FFmpeg native libraries load correctly (FFmpegUtils.EnsurePlatformSupport / bundled binaries match the platform)","Retry after freeing memory; close other FFmpegMedia instances that hold frames","Update the FFmpeg native binaries to a version matching the Stride.Video bindings"],"exampleFix":"// before\nmedia.Open(url);\n// after\nFFmpegUtils.EnsurePlatformSupport();\nif (MediaInfo.IsPlatformSupported)\n{\n    using (var media = new FFmpegMedia(services))\n    {\n        media.Open(url); // now with verified native libs\n    }\n}","handlingStrategy":"try-catch","validationCode":"// before opening\nFFmpegUtils.EnsurePlatformSupport();\nif (Environment.Is64BitProcess == false)\n    throw new PlatformNotSupportedException(\"Video requires a 64-bit process\");","typeGuard":null,"tryCatchPattern":"try\n{\n    media.Open(url);\n}\ncatch (ApplicationException ex) when (ex.Message.Contains(\"allocate a frame\"))\n{\n    // log native OOM; free resources and retry or surface a clear failure\n}","preventionTips":["Run 64-bit with adequate memory headroom","Verify FFmpeg native binaries before app start","Close/release unused FFmpegMedia instances promptly"],"tags":["ffmpeg","memory-allocation","video"],"backgroundTag":"module-init-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}