stride3d/stride · error · ApplicationException

Unsupported codec.

Error message

Unsupported codec.

What it means

Thrown by the FFmpegCodec constructor when ffmpeg.avcodec_find_decoder returns null for the stream's codec_id, meaning the linked FFmpeg build has no decoder for that codec. The constructor aborts before allocating the codec context.

Solutions

  1. Link/ship an FFmpeg build that includes a decoder for the codec (enable the needed decoders, e.g. non-free/proprietary where licensed)
  2. Verify the codec with ffprobe and transcode the media to a supported codec (H.264/AAC)
  3. Check ffmpeg.avcodec_find_decoder for the specific codec_id in a small test to confirm build support
  4. Ensure the correct FFmpeg native binaries are deployed, not a trimmed variant

Example fix

// before
var pCodec = ffmpeg.avcodec_find_decoder(codecId);
if (pCodec == null)
    throw new ApplicationException("Unsupported codec.");
// after
var pCodec = ffmpeg.avcodec_find_decoder(codecId) ?? ffmpeg.avcodec_find_decoder_and_init(codecId); // or log codecId
if (pCodec == null)
{
    Logger.Error($"No decoder available for codec {codecId}; rebuild FFmpeg with it enabled");
    throw new ApplicationException($"Unsupported codec {codecId}.");
}
Defensive patterns

Strategy: fallback

Validate before calling

// Pre-check decoder availability before opening the stream
if (ffmpeg.avcodec_find_decoder(codecpar->codec_id) == null)
{
    Logger.Error($"No FFmpeg decoder for codec_id {codecpar->codec_id}");
    return PlaybackResult.UnsupportedCodec;
}

Try / catch

try
{
    var codec = new FFmpegCodec(codecpar);
}
catch (ApplicationException ex) when (ex.Message == "Unsupported codec.")
{
    SkipStreamOrShowUnsupportedFormatMessage(ex);
}

Prevention

When it happens

Trigger: Opening media whose stream uses a codec not compiled into the FFmpeg build (e.g. proprietary codecs like certain H.264 variants, ProRes, or AC-3 when built without them), or a corrupt container that reports an unknown/invalid codec_id.

Common situations: Using a minimal FFmpeg build (no GPL/proprietary decoders enabled) against common commercial media; playing exotic codecs on a stripped distribution; FFmpeg native binaries swapped for a reduced-size build.

Related errors


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

Appendix: source

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

        private bool isDisposed = false;

        private AVHWDeviceType HardwareDeviceType => AVHWDeviceType.AV_HWDEVICE_TYPE_D3D11VA;

        public bool IsHardwareAccelerated { get; private set; }

        public AVPixelFormat HardwarePixelFormat => FindPixelFormat(HardwareDeviceType);

        /// <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")}");
            }

View on GitHub (pinned to 96fad776d2)