Skip to content

Show MKV progress window for multi-track files (#12193)#12197

Merged
niksedk merged 1 commit into
mainfrom
fix/mkv-progress-multi-track-12193
Jul 5, 2026
Merged

Show MKV progress window for multi-track files (#12193)#12197
niksedk merged 1 commit into
mainfrom
fix/mkv-progress-multi-track-12193

Conversation

@niksedk

@niksedk niksedk commented Jul 5, 2026

Copy link
Copy Markdown
Member

Fixes #12193

Problem

The Matroska "please wait" progress window (added in #11712) only appeared when an MKV had a single subtitle track. With multiple tracks, the Pick Matroska track dialog opens first, the UI froze during parsing, and the progress window never showed.

Root cause

MatroskaFile.GetSubtitle(...) reads and caches the whole file's cluster data on its first call; later calls are instant. That first read is the slow part.

  • Single track → goes straight to the threaded ExtractMatroskaSubtitleAsync, which shows the progress window. Works.
  • Multiple tracks → the picker dialog opens first. When it draws, SelectAndScrollToRow(0) fired TrackChanged(), which called GetSubtitle(...) synchronously on the UI thread to build the preview — that first (heavy) read froze the UI with no progress window.

Fix

In PickMatroskaTrackViewModel:

  • Rewrote TrackChanged()async TrackChangedAsync(). Parsing now runs off the UI thread in Task.Run via a static BuildPreview(...) that returns plain data (text + pre-decoded Avalonia Bitmaps, no controls); grid rows/Image controls are built back on the UI thread.
  • Shows the same 25 MB-gated PleaseWaitWindow with the determinate progress callback, only until the initial cluster read completes (_clusterLoaded), so later track switches don't flash a progress window.
  • Serialized preview parsing with a SemaphoreSlim (MatroskaFile isn't thread-safe — single shared FileStream) plus a _trackChangeToken to discard stale previews on rapid selection changes.
  • Added a try/catch that logs via Se.LogError so a parse error in the fire-and-forget task isn't unobserved.
  • Dropped a dead format.ToText(...) call from the old AddTextContent (result was unused).

Testing

Builds clean (0 warnings / 0 errors). Not yet exercised against a real >25 MB multi-track MKV — reviewer confirmation on real media welcome.

🤖 Generated with Claude Code

The Matroska progress window (PR #11712) only appeared for single-track
files. With multiple subtitle tracks, the Pick-Matroska-track dialog
opens first and its preview called GetSubtitle synchronously on the UI
thread. That first call is the one that reads/caches all cluster data,
so the dialog froze with no progress window.

Rewrite the dialog preview (TrackChanged -> async TrackChangedAsync) to
parse off the UI thread via Task.Run and show the same 25 MB-gated
PleaseWaitWindow until the initial cluster read completes. Serialize
parsing with a SemaphoreSlim (MatroskaFile is not thread-safe) plus a
token to drop stale previews on rapid selection changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@niksedk niksedk merged commit 85cd94d into main Jul 5, 2026
3 checks passed
@niksedk niksedk deleted the fix/mkv-progress-multi-track-12193 branch July 5, 2026 06:10
@lukastribus

Copy link
Copy Markdown

reviewer confirmation on real media welcome.

Confirmed v5.1.0-beta12 fixes this (tested on real media).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MKV parsing progress bar doesn't appear with multiple subtitles

2 participants