SubtitleEdit/subtitleedit · error · InvalidOperationException
Failed to initialize mpv: {_mpvContext.GetErrorString(err)}
Error message
Failed to initialize mpv: {_mpvContext.GetErrorString(err)} What it means
Thrown inside ReviewSpeechViewModel.PlayAudio when LibMpvDynamicPlayer.Initialize() returns a negative mpv error code while preparing an audio preview. Initialize() invokes the native mpv_initialize on the handle created by LoadLib(); a negative value means the mpv core could not be brought up. Critically, this site wraps the throw in try/catch: because callers disable every play/regenerate row before awaiting and only the playback timer re-enables them, an unhandled exception here would leave the whole dialog dead until it is reopened, so the catch logs via SeLogger, calls ResetPlaybackUiState(), and shows a MessageBox.
Source
Thrown at src/ui/Features/Video/TextToSpeech/ReviewSpeech/ReviewSpeechViewModel.cs:324
MessageBoxIcon.Error);
}
return;
}
try
{
lock (_playLock)
{
_mpvContext?.Stop();
_mpvContext?.Dispose();
_mpvContext = new LibMpvDynamicPlayer();
_mpvContext.LoadLib();
var err = _mpvContext.Initialize();
if (err < 0)
{
throw new InvalidOperationException($"Failed to initialize mpv: {_mpvContext.GetErrorString(err)}");
}
}
await _mpvContext.LoadAudio(fileName);
}
catch (Exception exception)
{
// An mpv load/init failure must not escape: the callers disable all rows before
// awaiting and only the playback timer re-enables them, so an unhandled throw
// leaves every play/regenerate button dead until the window is reopened.
SeLogger.Error(exception, $"ReviewSpeech: unable to play audio file \"{fileName}\"");
ResetPlaybackUiState();
if (Window != null)
{
await MessageBox.Show(
Window,
Se.Language.General.Error,
"Unable to play audio: " + exception.Message,View on GitHub (pinned to 17a9f07487)
Solutions
- Read the SeLogger output — the message embeds mpv's GetErrorString(err) which names the concrete failure.
- Verify libmpv (libmpv.dll / libmpv.dylib / libmpv.so) bitness/arch matches the running process (x64 on 64-bit).
- Install the Visual C++ Redistributable on Windows (or the equivalent C++ runtime on the platform).
- Use SE's built-in 'Download video player' to replace a suspect/corrupt libmpv with a known-good copy.
Example fix
// before - assumes load always succeeds
_mpvContext.LoadLib();
var err = _mpvContext.Initialize();
if (err < 0) throw new InvalidOperationException($"Failed to initialize mpv: {_mpvContext.GetErrorString(err)}");
// after - guard the load step so the error is actionable
_mpvContext.LoadLib();
if (!_mpvContext.CanLoad())
throw new InvalidOperationException("libmpv could not be loaded - check the player path/bitness.");
var err = _mpvContext.Initialize();
if (err < 0) throw new InvalidOperationException($"Failed to initialize mpv: {_mpvContext.GetErrorString(err)}"); Defensive patterns
Strategy: try-catch
Validate before calling
_mpvContext = new LibMpvDynamicPlayer();
if (!_mpvContext.CanLoad())
{
SeLogger.Error("libmpv not found for audio preview");
return; // or prompt to download the player
} Try / catch
// Already the recommended pattern at this site: catch resets UI state.
try { /* LoadLib/Initialize/LoadAudio */ }
catch (Exception ex)
{
SeLogger.Error(ex, $"ReviewSpeech: unable to play \"{fileName}\"");
ResetPlaybackUiState();
await MessageBox.Show(Window, Se.Language.General.Error, "Unable to play audio: " + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
} Prevention
- Call CanLoad() before Initialize() to separate 'library missing' from 'init failed'.
- Keep libmpv arch/bitness aligned with the process via SE's player download.
- Ensure the C++ runtime required by libmpv is installed.
When it happens
Trigger: LoadLib() located a libmpv binary but mpv_initialize failed: wrong-architecture/bitness libmpv (e.g. x86 dll in an x64 process), missing dependent runtime such as the Visual C++ redistributable, a corrupted libmpv, or an mpv option rejected during initialization.
Common situations: User installed/replaced libmpv manually with the wrong build; a Windows machine lacking the VC++ runtime; a portable build whose libmpv was quarantined by antivirus; SE updated to a libmpv build requiring a newer runtime.
Related errors
- Failed to initialize mpv: {player.GetErrorString(err)}
- Failed to initialize mpv: {_mpvContext.GetErrorString(err)}
- "{process.StartInfo.FileName} {process.StartInfo.Arguments}"
- Failed to initialize mpv: {_mpvPlayer.GetErrorString(err)}
- MPV delegates not loaded for software rendering.
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/c24e1955d056c36d.
Report an issue: GitHub.