stride3d/stride · critical · ApplicationException

Couldn't allocate a frame for decoding.

Error message

Couldn't allocate a frame for decoding.

What it means

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).

Solutions

  1. Ensure 64-bit process and sufficient available memory before opening media
  2. Verify the FFmpeg native libraries load correctly (FFmpegUtils.EnsurePlatformSupport / bundled binaries match the platform)
  3. Retry after freeing memory; close other FFmpegMedia instances that hold frames
  4. Update the FFmpeg native binaries to a version matching the Stride.Video bindings

Example fix

// before
media.Open(url);
// after
FFmpegUtils.EnsurePlatformSupport();
if (MediaInfo.IsPlatformSupported)
{
    using (var media = new FFmpegMedia(services))
    {
        media.Open(url); // now with verified native libs
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before opening
FFmpegUtils.EnsurePlatformSupport();
if (Environment.Is64BitProcess == false)
    throw new PlatformNotSupportedException("Video requires a 64-bit process");

Try / catch

try
{
    media.Open(url);
}
catch (ApplicationException ex) when (ex.Message.Contains("allocate a frame"))
{
    // log native OOM; free resources and retry or surface a clear failure
}

Prevention

When it happens

Trigger: 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.

Common situations: Low-memory environments (32-bit processes, embedded devices); corrupted or mismatched FFmpeg native binaries; running without proper native dependencies installed so allocation fails.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/85635c32cad773a3. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Video/FFmpeg/FFmpegMedia.cs:161

                Logger.Error($"Could not find stream info. Error code={ret.ToString("X8")}");
                Logger.Error(GetErrorMessage(ret));
                throw new ApplicationException(@"Could not find stream info.");
            }

            AVFormatContext = pFormatContext;
            Duration = TimeSpan.FromSeconds((double)AVFormatContext->duration / ffmpeg.AV_TIME_BASE);
            Url = url;

            // Get the streams
            for (int i = 0; i < pFormatContext->nb_streams; i++)
            {
                var stream = FFmpegStream.Create(pFormatContext->streams[i], this);
                streams.Add(stream);
            }

            pDecodedFrame = ffmpeg.av_frame_alloc();
            if (pDecodedFrame == null)
                throw new ApplicationException("Couldn't allocate a frame for decoding.");

            pCpuCopyFrame = ffmpeg.av_frame_alloc();
            if (pCpuCopyFrame == null)
                throw new ApplicationException("Couldn't allocate a frame for hardware decoding.");

            // dispose cached video image from previous file
            ClearStreamInfo();
        }

        public bool SeekToTime([NotNull] FFmpegStream stream, long timestamp)
        {
            FFmpegUtils.EnsurePlatformSupport();

            if (currentStreams.TryGetValue(stream, out var streamInfo))
            {
                // flush the codec buffered images
                streamInfo.Codec.Flush(pDecodedFrame);
            }

View on GitHub (pinned to 96fad776d2)