stride3d/stride · error · ApplicationException
Could not open file.
Error message
Could not open file.
What it means
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.
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.
Example fix
// before
media.Open("video.mp4", startPosition: 0, length: -1); // file not deployed
// after
var path = Path.Combine(AppContext.BaseDirectory, "Content", "video.mp4");
if (!File.Exists(path)) throw new FileNotFoundException(path);
media.Open(path, startPosition: 0, length: -1); Defensive patterns
Strategy: try-catch
Validate before calling
if (!File.Exists(path))
throw new FileNotFoundException($"Media file missing: {path}"); Try / catch
try
{
media.Open(url, startPosition, length);
}
catch (ApplicationException ex) when (ex.Message == "Could not open file.")
{
// check logs for the hex code; verify path/permissions and retry or surface to user
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
- Could not find stream info.
- Could not fill codec parameters. Error code=
- Could not find function
- Could not initialize the conversion context.
- Could not open codec. Error code=
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/74c66dfc141a10d3.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Video/FFmpeg/FFmpegMedia.cs:137
public void Open(string url, long startPosition = 0, long length = -1)
{
FFmpegUtils.EnsurePlatformSupport();
if (isDisposed)
throw new ObjectDisposedException(nameof(FFmpegMedia));
if (IsOpen)
// TODO: log?
throw new InvalidOperationException(@"Media is already open.");
if (startPosition != 0 && length != -1)
url = $@"subfile,,start,{startPosition},end,{startPosition + length},,:{url}";
var pFormatContext = ffmpeg.avformat_alloc_context();
var ret = ffmpeg.avformat_open_input(&pFormatContext, url, null, null);
if (ret < 0)
{
Logger.Error($"Could not open file. Error code={ret.ToString("X8")}");
Logger.Error(GetErrorMessage(ret));
throw new ApplicationException(@"Could not open file.");
}
ret = ffmpeg.avformat_find_stream_info(pFormatContext, null);
if (ret < 0)
{
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);View on GitHub (pinned to 96fad776d2)