{"record":{"id":"98998fd26748518e","repo":"stride3d/stride","slug":"media-isn-t-open","errorCode":null,"errorMessage":"Media isn't open.","messagePattern":"Media isn't open\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Video/FFmpeg/FFmpegMedia.cs","lineNumber":204,"sourceCode":"            if (ret < 0)\n            {\n                Logger.Error($\"Could not seek frame. Error code={ret.ToString(\"X8\")}\");\n                Logger.Error(GetErrorMessage(ret));\n                return false;\n            }\n\n            return true;\n        }\n\n        [ItemNotNull, NotNull]\n        public int ExtractFrames([NotNull] FFmpegStream stream, int count)\n        {\n            FFmpegUtils.EnsurePlatformSupport();\n            if (isDisposed)\n                throw new ObjectDisposedException(nameof(FFmpegMedia));\n            if (!IsOpen)\n                // TODO: log?\n                throw new InvalidOperationException(@\"Media isn't open.\");\n\n            var pCodecpar = stream.AVStream->codecpar;\n            var streamInfo = GetStreamInfo(stream);\n\n            var dstData = new byte_ptrArray4();\n            var dstLinesize = new int_array4();\n            ffmpeg.av_image_fill_arrays(ref dstData, ref dstLinesize, (byte*)streamInfo.Image.Buffer, DestinationPixelFormat, pCodecpar->width, pCodecpar->height, 1);\n            streamInfo.Image.Linesize = dstLinesize[0];\n\n            var extractedFrameCount = 0;\n\n            // FFmpeg 6.0+: av_init_packet removed; packets must be heap-allocated via av_packet_alloc.\n            var pPacket = ffmpeg.av_packet_alloc();\n            try\n            {\n                for (int i = 0; i < count; i++)\n                {\n                    var extractionStatus = ExtractNextImage(streamInfo, pPacket, stream.AVStream, dstData, dstLinesize);","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Video/FFmpeg/FFmpegMedia.cs#L186-L222","documentation":"ExtractFrames extracts raw frames from an already-opened media. This InvalidOperationException is thrown when ExtractFrames is called on an FFmpegMedia whose Open() has not succeeded (IsOpen is false), or after the media was disposed.","triggerScenarios":"Calling ExtractFrames(stream,...) before calling Open(url), after Open threw (leaving the media not open), or after Dispose().","commonSituations":"Calling extraction APIs in the wrong order in editor/tools code; Open failed earlier due to a missing or corrupt file and the error was swallowed; using the media object after disposal.","solutions":["Call Open(url) and confirm it succeeds before calling ExtractFrames","Check the IsOpen property before extraction and open on demand","Avoid using FFmpegMedia after Dispose; create a new instance","Fix the root cause if Open previously failed (file path, codecs, memory)"],"exampleFix":"// before\nmedia.ExtractFrames(stream, time => ...);\n// after\nif (!media.IsOpen) media.Open(url);\nif (media.IsOpen)\n    media.ExtractFrames(stream, time => ...);","handlingStrategy":"type-guard","validationCode":"if (media.IsDisposed) throw new ObjectDisposedException(nameof(FFmpegMedia));\nif (!media.IsOpen) media.Open(url);","typeGuard":"bool CanExtract(FFmpegMedia m) => !m.IsDisposed && m.IsOpen;","tryCatchPattern":"try { media.ExtractFrames(stream, cb); }\ncatch (InvalidOperationException ex) when (ex.Message == \"Media isn't open.\")\n{\n    media.Open(url);\n    media.ExtractFrames(stream, cb);\n}","preventionTips":["Always call Open before ExtractFrames","Track media lifetime; never reuse disposed instances","Check IsOpen property as a guard clause"],"tags":["invalid-operation","state-error","video","ffmpeg"],"backgroundTag":"invalid-state-transition","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"}