ThaUnknown / jassub

Displays subtitles in .ass format via JavaScript. Supports all SSA/ASS features, easily integrates with HTML5 videos.
https://thaunknown.github.io/jassub
MIT License
69 stars 11 forks source link

JASSUB

JavaScript SSA/ASS Subtitle Renderer.

JASSUB is a JS wrapper for libass, which renders SSA/ASS subtitles directly in your browser. It uses Emscripten to compile libass' C++ code to WASM.

Online Demos

Features

Isn't this just the same thing as JavascriptSubtitlesOctopus?

No. See this comparison.

Usage

By default all you need to do is copy the files from the dist/ folder of the repository into the same folder as where your JS runs, then do:

import JASSUB from './jassub.es.js'

const renderer = new JASSUB({
  video: document.querySelector('video'),
  subUrl: './tracks/sub.ass'
})

Note: while the dist/ folder includes a UMD dist it still uses modern syntax. If you want backwards compatibility with older browsers I recommend you run it tru babel.

If you use a bundler like Vite, you can instead do:

npm i jassub
import JASSUB from 'jassub'
import workerUrl from 'jassub/dist/jassub-worker.js?url'
import wasmUrl from 'jassub/dist/jassub-worker.wasm?url'

const renderer = new JASSUB({
  video: document.querySelector('video'),
  subContent: subtitleString,
  workerUrl, // you can also use: `new URL('jassub/dist/jassub-worker.js', import.meta.url)` instead of importing it as an url
  wasmUrl
})

Using only with canvas

You're also able to use it without any video. However, that requires you to set the time the subtitles should render at yourself:

import JASSUB from './jassub.es.js'

const renderer = new JASSUB({
  canvas: document.querySelector('canvas'),
  subUrl: './tracks/sub.ass'
})

renderer.setCurrentTime(15)

Changing subtitles

You're not limited to only display the subtitle file you referenced in your options. You're able to dynamically change subtitles on the fly. There's three methods that you can use for this specifically:

Methods and properties

This library has a lot of methods and properties, however many aren't made for manual use or have no effect when changing, those are usually prefixed with _. Most of these never need to be called by the user.

List of properties:

ASS_Event object properties

ASS_Style object properties

How to build?

Dependencies

Get the Source

Run git clone --recursive https://github.com/ThaUnknown/jassub.git

Build inside a Container

Docker

  1. Install Docker
  2. ./run-docker-build.sh
  3. Artifacts are in /dist/js

    Buildah

  4. Install Buildah and a suitable backend for buildah run like crun or runc
  5. ./run-buildah-build.sh
  6. Artifacts are in /dist/js

    Build without Containers

  7. Install the dependency packages listed above
  8. make
    • If on macOS with libtool from brew, LIBTOOLIZE=glibtoolize make
  9. Artifacts are in /dist/js