{"record":{"id":"74c66dfc141a10d3","repo":"stride3d/stride","slug":"could-not-open-file","errorCode":null,"errorMessage":"Could not open file.","messagePattern":"Could not open file\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Video/FFmpeg/FFmpegMedia.cs","lineNumber":137,"sourceCode":"        public void Open(string url, long startPosition = 0, long length = -1)\n        {\n            FFmpegUtils.EnsurePlatformSupport();\n            if (isDisposed)\n                throw new ObjectDisposedException(nameof(FFmpegMedia));\n            if (IsOpen)\n                // TODO: log?\n                throw new InvalidOperationException(@\"Media is already open.\");\n\n            if (startPosition != 0 && length != -1)\n                url = $@\"subfile,,start,{startPosition},end,{startPosition + length},,:{url}\";\n\n            var pFormatContext = ffmpeg.avformat_alloc_context();\n            var ret = ffmpeg.avformat_open_input(&pFormatContext, url, null, null);\n            if (ret < 0)\n            {\n                Logger.Error($\"Could not open file. Error code={ret.ToString(\"X8\")}\");\n                Logger.Error(GetErrorMessage(ret));\n                throw new ApplicationException(@\"Could not open file.\");\n            }\n\n            ret = ffmpeg.avformat_find_stream_info(pFormatContext, null);\n            if (ret < 0)\n            {\n                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);","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Video/FFmpeg/FFmpegMedia.cs#L119-L155","documentation":"FFmpegMedia.Open throws this ApplicationException when ffmpeg.avformat_open_input returns a negative code, meaning FFmpeg could not open the input at the given URL. The hex code and av_strerror text are logged, then a generic 'Could not open file.' exception is thrown.","triggerScenarios":"Calling Open (or CreateAssets/DoCommandOverride) with a url that does not exist, is malformed, is inaccessible, or whose subfile,start/end range is invalid; also when the file is disposed mid-call (ObjectDisposedException is checked before, but the FFmpeg open can still fail).","commonSituations":"Wrong or relative path for the media file; file missing at runtime after build/deployment (content not copied); invalid startPosition/length combination producing a bad subfile protocol URL; unsupported protocol or permission issues; corrupt container FFmpeg cannot probe.","solutions":["Check the logged hex code / av_strerror output to distinguish file-not-found, permission, and protocol errors.","Verify the file exists and the path is absolute/resolved correctly at runtime.","Validate that startPosition/length fall within the file (they build a subfile,,start,X,end,Y,,:url URL).","Deploy the file with the application (mark as content) and check read permissions."],"exampleFix":"// before\nmedia.Open(\"video.mp4\", startPosition: 0, length: -1); // file not deployed\n// after\nvar path = Path.Combine(AppContext.BaseDirectory, \"Content\", \"video.mp4\");\nif (!File.Exists(path)) throw new FileNotFoundException(path);\nmedia.Open(path, startPosition: 0, length: -1);","handlingStrategy":"try-catch","validationCode":"if (!File.Exists(path))\n    throw new FileNotFoundException($\"Media file missing: {path}\");","typeGuard":null,"tryCatchPattern":"try\n{\n    media.Open(url, startPosition, length);\n}\ncatch (ApplicationException ex) when (ex.Message == \"Could not open file.\")\n{\n    // check logs for the hex code; verify path/permissions and retry or surface to user\n}","preventionTips":["Resolve media paths relative to the app base directory, not the working directory.","Mark media files as content so they are deployed.","Validate startPosition/length against the file size before opening.","Check the logged hex AVERROR code to distinguish not-found vs permission vs protocol errors."],"tags":["ffmpeg","file-io","media-loading"],"backgroundTag":"file-open-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"}