Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

libpgs

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libpgs

Renderer for graphical subtitles (PGS) in the browser.

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
increased by27.96%
Maintainers
1
Weekly downloads
 
Created
Source

libpgs-js

This library renders the graphical subtitles format PGS (.sub / .sup) in the browser.

Work in progress

This project is still in progress. It should be able to play 99% of Blue ray subtitles (Yes, I made that number up). But some rare used PGS features - like cropping - aren't implemented yet.

  • Basic PGS rendering.
  • Auto syncing to video element.
  • Custom subtitle time offset.
  • Support subtitle cropping.
    • If you know a movie or show that is using the cropping feature, please let me know!
  • Improve performance by using a WebWorker to render.

Usage

Install the package via npm:

npm i --save libpgs

Create with default canvas

The PGS renderer will create a default canvas element next to the video element:

const videoElement = document.getElementById('video-element');
const pgsRenderer = new libpgs.PgsRenderer({
    video: videoElement,
    subUrl: './subtitle.sup'
});

The created default canvas element is using a style definition like this:

position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
width: '100%';
height: '100%';
pointer-events: 'none';
object-fit: 'contain';

This only works if the video element is stretched in its parent and if the parent is using the css position property.

<div style="position: relative">
    <video id="video-element" src="./video.mp4"></video>
</div>

Create with custom canvas

It is also possible to provide a custom canvas element and position it manually:

const videoElement = document.getElementById('video-element');
const canvasElement = document.getElementById('canvas-element');
const pgsRenderer = new libpgs.PgsRenderer({
    video: videoElement,
    canvas: canvasElement,
    subUrl: './subtitle.sup'
});

Time offset

You can also adjust time offset between video and subtitle:

// Rendering the subtitle 3 seconds in advance of the video
pgsRenderer.timeOffset = 3.0;

Destroy

Make sure to dispose the renderer when leaving:

// Releases video events and removes the default canvas element
pgsRenderer.dispose();

Licence

MIT License

Keywords

FAQs

Package last updated on 12 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc