pbs / pycaption

Python module to read/write popular video caption formats
Apache License 2.0
256 stars 136 forks source link

SCC to VTT positioning issues #210

Closed darrellenns closed 2 years ago

darrellenns commented 3 years ago

There appear to be multiple issues with positing, both in the SCC reader and the VTT writer.

Take the following test case:

Scenarist_SCC V1.0

00:00:00:21     9420 9476 4345 ce54 4552 45c4 942c 8080 8080 942f

00:00:01:19     9420 9470 4c45 4654 20c1 4c49 c7ce 45c4 942c 8080 8080 942f

00:00:02:17     9420 94f8 9723 5249 c7c8 5420 c14c 49c7 ce45 c480 942c 8080 8080 942f

The first caption should be centered, the second should be left aligned with the title safe frame, and the third should be right aligned with the title safe frame.

The resulting WebVTT (using WebVTTWriter(relativize=True,video_width=1920,video_height=1080)) is as follows:

WEBVTT

00:01.034 --> 00:01.935 align:left position:37.5%,start line:93.33% size:62.5%
CENTERED

00:02.035 --> 00:02.936 align:left position:0%,start line:93.33% size:100%
LEFT ALIGNED

00:03.036 --> 00:07.036 align:left position:50%,start line:93.33% size:50%
RIGHT ALIGNED

This can be viewed using https://zcorpan.github.io/live-webvtt-viewer/.

The result is that all captions are left aligned. This seems to be because the "position" attribute is invalid. It should not include ",start" - just a percentage value. I'm guessing this is a bug in the VTT writer? I have also tried manually removing the ",start" as follows:

WEBVTT

00:01.034 --> 00:01.935 align:left position:37.5% line:93.33% size:62.5%
CENTERED

00:02.035 --> 00:02.936 align:left position:0% line:93.33% size:100%
LEFT ALIGNED

00:03.036 --> 00:07.036 align:left position:50% line:93.33% size:50%
RIGHT ALIGNED

In this case, the centered line appears correct, the left aligned line is all the way to the edge of the frame (instead of within the title safe region), and the right aligned text is about 2/3 of the way to the right.

The same SCC source converted using Telestream CaptionMaker results in the following VTT, which renders correctly:

WEBVTT

00:00:01.000 --> 00:00:01.935 align:middle line:85% position:50% size:20%
CENTERED

00:00:02.001 --> 00:00:02.936 align:middle line:85% position:25% size:30%
LEFT ALIGNED

00:00:03.002 --> 00:00:04.003 align:middle line:85% position:75% size:33%
RIGHT ALIGNED
ana-nichifor commented 3 years ago

Hi, on pycaption 2.0.2 we released the implementation for SCC tab offsets and enforced caption safe area limits which visibly improved positioning. We will also remove the "start" positioning alignment on the next release (2.0.3) and here's how it will look:

WEBVTT
00:01.034 --> 00:01.935 align:left position:40% line:89% size:50%
CENTERED

00:02.035 --> 00:02.936 align:left position:10% line:89% size:80%
LEFT ALIGNED

00:03.036 --> 00:07.036 align:left position:57.5% line:89% size:32.5%
RIGHT ALIGNED

Horizontally they seem closer now, the only difference being that positioning percentages in pycaption relate to the left side of the caption, while your example places the middle at that percentage. Another problem I noticed is the viewer you're using, it seems to enforce a right padding that is not there, I suggest testing the files on another player. I attached a few examples on how the pycaption result looks like on video.js.

Screenshot 2021-11-04 at 17 47 25 Screenshot 2021-11-04 at 17 47 37 Screenshot 2021-11-04 at 17 47 08