Skip to content

Fix WebVTT cue setting preservation#12340

Open
pdjdev wants to merge 1 commit into
SubtitleEdit:mainfrom
pdjdev:fix/webvtt-preserve-cue-settings
Open

Fix WebVTT cue setting preservation#12340
pdjdev wants to merge 1 commit into
SubtitleEdit:mainfrom
pdjdev:fix/webvtt-preserve-cue-settings

Conversation

@pdjdev

@pdjdev pdjdev commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Problem

WebVTT cue settings could be silently lost or changed after loading and saving a file in Subtitle Edit.

In particular, commonly used settings such as align:left were not preserved. Cue positions that did not exactly correspond to Subtitle Edit's configured ASS alignment presets were inferred from broad coordinate ranges and converted to a nearby {\an1}{\an9} tag.

For example, saving this file again via Save As... without any changes:

WEBVTT

00:00:20.943 --> 00:00:21.730
♪ If this is it ♪

00:00:21.731 --> 00:00:23.356 position:3% line:5% align:left
🎵 If This Is It
By Huey Lewis And The News

00:00:23.357 --> 00:00:25.900
♪ Please let me know ♪

could produce:

WEBVTT

00:00:20.943 --> 00:00:21.730
♪ If this is it ♪

00:00:21.731 --> 00:00:23.356 position:20% line:20%
🎵 If This Is It
By Huey Lewis And The News

00:00:23.357 --> 00:00:25.900
♪ Please let me know ♪

This both removes align:left and changes the author's intended position.

Cause & Fix

The previous GetPositionInfo() logic converted arbitrary position and line values to ASS alignment tags based on coordinate ranges. This is a lossy conversion because WebVTT cue positioning is more expressive than the nine discrete ASS alignment positions.

This PR replaces that inference with GetAssAlignmentTagFromCueSettings().

  • Cue settings are converted to {\an1}{\an9} only when the extracted cue settings exactly match one of the configured SubtitleSettings.WebVttCueAn1WebVttCueAn9 values.
  • Non-matching cue settings are preserved instead of being approximated to an ASS alignment tag.
  • When an ASS alignment tag is added in Subtitle Edit, its configured WebVttCueAn* value overrides existing cue settings during WebVTT export.
  • Cue settings that were converted to an ASS alignment tag are no longer retained as stale metadata. Removing the tag therefore also removes the corresponding cue settings.
  • Applied the same behavior to regular WebVTT, numbered WebVTT, and MP4 vttc parsing.
  • Removed the range-based WebVTT.GetPositionInfo() method.

For example, when an editor adds {\an7} to a cue:

{\an7}🎵 If This Is It
By Huey Lewis And The News

and SubtitleSettings.WebVttCueAn7 is configured as:

position:20% line:20%

the exported WebVTT cue uses that configured placement:

00:00:21.731 --> 00:00:23.356 position:20% line:20%
🎵 If This Is It
By Huey Lewis And The News

Test

Added regression coverage for:

  • preserving non-preset cue settings, including align:left;
  • converting exact preset matches to ASS alignment tags;
  • removing a loaded ASS alignment tag without retaining stale cue settings;
  • ASS alignment tags overriding existing cue settings on save;
  • preserving non-preset cue settings in numbered WebVTT files.

Tested on Windows 11 x64 with a local Release build.

WebVttTest: 14/14 passed.

Note

WebVTT and ASS/SSA have different styling and positioning models, so mapping between them has inherent limitations. A dedicated styling system and editor UI for WebVTT could be a useful future improvement.

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.

1 participant