stride3d/stride · error · ApplicationException

Could not fill codec parameters. Error code=

Error message

Could not fill codec parameters. Error code={ret.ToString("X8")}

What it means

Thrown by the FFmpegCodec constructor when avcodec_parameters_to_context returns a negative error code, meaning FFmpeg failed to copy the stream's codec parameters (extradata, dimensions, sample rate, etc.) into the freshly allocated codec context. The hex code identifies the underlying AVERROR.

Solutions

  1. Inspect the hex error code (e.g. AVERROR(ENOMEM)=0x80070000 style) to identify the FFmpeg failure and act on it
  2. Validate/re-mux the media file (ffmpeg -i in.mp4 -c copy out.mp4) to repair malformed stream parameters
  3. Check the FFmpeg version: update or pin to one known to handle the media's codec parameters
  4. Catch ApplicationException at stream-open time and skip/fall back to another track

Example fix

// before
ret = ffmpeg.avcodec_parameters_to_context(pCodecContext, originalCodecpar);
if (ret < 0)
    throw new ApplicationException($"Could not fill codec parameters. Error code={ret.ToString("X8")}");
// after
ret = ffmpeg.avcodec_parameters_to_context(pCodecContext, originalCodecpar);
if (ret < 0)
{
    Logger.Error($"avcodec_parameters_to_context failed: {ffmpeg.av_strerror(ret)} (0x{ret:X8})");
    ffmpeg.avcodec_free_context(&pCodecContext); // avoid leak before throwing
    throw new ApplicationException($"Could not fill codec parameters. Error code={ret.ToString("X8")}");
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (codecpar == null || codecpar->extradata == null && codecpar->extradata_size > 0)
{
    Logger.Error("Stream codec parameters are malformed");
    return PlaybackResult.BadStreamParameters;
}

Try / catch

try
{
    var codec = new FFmpegCodec(codecpar);
}
catch (ApplicationException ex) when (ex.Message.StartsWith("Could not fill codec parameters."))
{
    Logger.Error($"Stream open failed: {ex.Message}");
    SkipStreamOrRetryWithTranscodedAsset(ex);
}

Prevention

When it happens

Trigger: avcodec_parameters_to_context failing on a stream whose AVCodecParameters are malformed or incompatible with the chosen decoder — typically corrupt extradata, a codec_id that changed meaning between FFmpeg versions, or an out-of-memory AVERROR(ENOMEM).

Common situations: Corrupted or unusual media files with broken extradata; mismatched FFmpeg version where the container's parameters can't be applied to the decoder; running out of memory while allocating codec context fields on constrained devices.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Video/FFmpeg/FFmpegCodec.cs:48

        /// <summary>
        /// Initializes a new instance of the <see cref="FFmpegCodec"/> class.
        /// </summary>
        public FFmpegCodec(AVCodecParameters* originalCodecpar)
        {
            var codecId = originalCodecpar->codec_id;
            var pCodec = ffmpeg.avcodec_find_decoder(codecId);
            if (pCodec == null)
                // TODO: log?
                throw new ApplicationException("Unsupported codec.");

            int ret;
            var pCodecContext = ffmpeg.avcodec_alloc_context3(pCodec);

            ret = ffmpeg.avcodec_parameters_to_context(pCodecContext, originalCodecpar);
            if (ret < 0)
                // TODO: log?
                throw new ApplicationException($"Could not fill codec parameters. Error code={ret.ToString("X8")}");

            SetupHardwareAcceleration(pCodecContext);

            if (ffmpeg.avcodec_is_open(pCodecContext) == 0)
            {
                ret = ffmpeg.avcodec_open2(pCodecContext, pCodec, null);
                if (ret < 0)
                    // TODO: log?
                    throw new ApplicationException($"Could not open codec. Error code={ret.ToString("X8")}");
            }

            pAVCodecContext = pCodecContext;
        }

        /// <summary>Initializes the platform-specific hardware decode context, when supported.</summary>
        partial void SetupHardwareAcceleration(AVCodecContext* pCodecContext);

        /// <summary>Restores the platform-specific get_format callback after <see cref="ffmpeg.avcodec_flush_buffers"/>.</summary>

View on GitHub (pinned to 96fad776d2)