mozilla / vtt.js

A JavaScript implementation of the WebVTT specification
http://dev.w3.org/html5/webvtt/
Apache License 2.0
479 stars 94 forks source link

Make Parser Async #373

Open jaruba opened 6 years ago

jaruba commented 6 years ago

Related to:

https://github.com/mozilla/vtt.js/issues/340 https://github.com/videojs/video.js/issues/1913 https://github.com/video-dev/vtt.js/issues/4 https://github.com/videojs/video.js/issues/5252

(probably many more that I don't know about too)

Short Explanation of the Issue:

This method: https://github.com/mozilla/vtt.js/blob/master/lib/vtt.js#L1097 is fully synchronous, and relies on being synchronous throughout the entire logic. Tested against 15 subtitles of 1600-2000 lines, it took around 700-900ms in my tests to parse each subtitle.

More specifically these lines: https://github.com/mozilla/vtt.js/blob/master/lib/vtt.js#L1199-L1315 in which the iteration of the entire file is wrapped in a try { } catch(e) { } and also every iteration of subtitle time lines (CUE state) is wrapped in another try { } catch(e) { }, all this while iterating synchronously through what may possibly be very large subtitle files efficiently block the entire page for some time.

Possible solutions:

So callback hell it is.. this dropped the loading time of WebVTT.Parser.parse() to 20-50ms from 700-900ms. I'm sure it can be improved a lot more, but it's a starting point.

I tested this PR with the same 15 subtitles, they all went through and worked like a charm with VideoJS, I tried to test with vtt.js's tests too, but most of those fail anyway as described in: https://github.com/mozilla/vtt.js/issues/343

So I'm just leaving this here for y'all to babble about. Gonna go pour a good glass of wine 'cause my mind's spinning from the try, catch, throw, continue, return hurricane I just got out of.

silviapfeiffer commented 6 years ago

@rillian who's responsible for captions at Mozilla these days...?

gkatsev commented 6 years ago

It's also on my todo list to review. Though, we'd need a PR against our fork https://github.com/videojs/vtt.js/

also, as part of video-dev, we're going to try and maintain vtt.js unless mozilla steps up: https://github.com/video-dev/vtt.js

gkatsev commented 4 years ago

I just tried porting this over to videojs/vtt.js but ran into a bunch of issues. The main issue I found is that if I have multiple captions that get parsed, if one of them gets a parser error, none of the other captions end up working.

jaruba commented 4 years ago

@gkatsev This was from more then one year ago.. I've completely fixed this since for my needs. Including this issue: https://github.com/videojs/video.js/issues/5252

But due to the fact that this PR was ignored, and all fixes started from this one terribly inefficient module, I never got to pushing my commits to the rest of the repos so they're now lost to time in an old and highly customised version of videojs that I'm using in a hobby project. (where it works perfectly and has been tested against thousands of subtitles since)

I remember VideoJS itself required quite a few changes to get this working properly, it was not a drop-in change. Redoing all of it might require significant effort on my side, and honestly, I'm not motivated to go down that rabbit's hole again.

Disclaimer: I've worked professionally on (and created) many different video players through the last few years, so I know exactly how they should work and am comfortable with the logic involved.

gkatsev commented 4 years ago

That's totally understandable. I just spent some time refactoring the video.js fork and I'll probably take a look at making changes to make it asynchronous as well. If you do find the commits, they would be super helpful. Appreciate you trying to get this started.

JohannesKuehnel commented 3 years ago

@RickEyre @humphd @rillian Is anyone of you still with Mozilla and able to tell if this project has been completely abandoned or still has a maintainer?

gkatsev commented 3 years ago

I don't think anyone at Mozilla has the bandwidth to maintain this. For Video.js, we maintain our own fork. Our fork is almost ready to ship WebVTT regions!

JohannesKuehnel commented 3 years ago

I don't think anyone at Mozilla has the bandwidth to maintain this. For Video.js, we maintain our own fork. Our fork is almost ready to ship WebVTT regions!

In a different ticket you mentioned you are also low on resources to get the async parsing going, so I thought I would try reaching someone upstream. 😸

gkatsev commented 3 years ago

Yup, they have even less for this 😁