0.4.1 • Published 2 months ago

ass-html5 v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

ass-html5

Display ASS/SSA subtitles on html5 videos

ass-html5 uses the ass-compiler from weizhenye.

CI workflow Publish workflow License npm bundle size npm

🏗 PROJECT UNDER DEVELOPEMENT 🏗

Table of Contents

Installation

pnpm add ass-html5

Usage

Options

optiondescriptionrequiredtypedefault
assTextThe ass text stringstringundefined
videoThe video to display the subtile on. Can be either an HTMLVideoElement or string (html query selector )HTMLVideoElement / stringundefined
fontsCustom fonts to load🚫Font[]undefined
zIndexzIndex of the rendering frame🚫numberDrawn after the video

Simple HTML

!NOTE The simple video tag element, on fullscreen mode, the position of the video is absoluty on top of any element. No other element can go on top of it.

It's therefore recommanded to use a third party player rather than the native one. You can see an example with plry here.

<script src="https://cdn.jsdelivr.net/npm/ass-html5@<VERSION>/dist/ass.min.js"></script>
<video src="/assets/video.mp4" id="video" controls></video>
<script>
	document.addEventListener('DOMContentLoaded', async () => {
		let res = await fetch('/assets/video.ass')
		let assSubs = await res.text()

		const ass = new ASS({
			assText: assSubs,
			video: document.getElementById('video')
		})
		await ass.init()
	})
</script>

Svelte and Plry

<script lang="ts">
    import video from '$lib/assets/video.mp4'
    import cc from '$lib/assets/cc.ass?raw'
    import ASS from 'ass-html5'
    import { onMount } from 'svelte';
    import Plyr from 'plyr'

    const ass = new ASS({
        assText: cc,
        video: "#video-test"
    })

    let vidElement: HTMLVideoElement
    let player: Plyr
    onMount(async () => {
        player = new Plyr(vidElement)
        await ass.init()
    })

</script>

<div class="video-container">
    <!-- svelte-ignore a11y-media-has-caption -->
    <video
        preload="metadata"
        src="{video}"
        id="video-test"
        controls
        autoplay
        class="vid"
        bind:this={vidElement}
    ></video>
</div>

videojs

In the head :

<script src="https://cdn.jsdelivr.net/npm/ass-html5@<VERSION>/dist/ass.min.js" defer></script>
<script src="https://vjs.zencdn.net/8.3.0/video.min.js" defer></script>
<link href="https://vjs.zencdn.net/8.3.0/video-js.css" rel="stylesheet" />

In the body :

<video
	id="my-video"
	class="video-js"
	controls
	preload="auto"
	width="1280"
	height="720"
	data-setup="{}"
>
	<source src="assets/video.mp4" type="video/mp4" />
</video>

In the script tag :

<script>
	document.addEventListener('DOMContentLoaded', async () => {
		let res = await fetch('/assets/video.ass')
		let assSubs = await res.text()

		var player = videojs('my-video')

		player.ready(async () => {
			// Get the video element from the player
			var videoElement = player.el().getElementsByTagName('video')[0]
			const ass = new ASS({
				assText: assSubs,
				video: videoElement
			})
			await ass.init()
		})
	})
</script>
0.4.1

2 months ago

0.4.0

2 months ago

0.3.6

9 months ago

0.3.5

9 months ago

0.3.4

9 months ago

0.3.3

9 months ago

0.3.2

9 months ago

0.3.1

9 months ago

0.3.0

9 months ago

0.2.7

10 months ago

0.2.6

10 months ago

0.2.5

10 months ago

0.2.4

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.0

10 months ago

0.0.1

10 months ago

0.0.0

10 months ago