1 Star 0 Fork 0

Ekber/ASS

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
MIT

ASS.js

Build status Coverage Dependencies NPM version License File size jsDelivr

Browser compatibility

ASS.js uses ass-compiler to parse ASS subtitle file format, and then renders subtitles on HTML5 video.

Demo

ASS specs(zh-Hans)

Installation

npm install assjs

Usage

<video id="video" src="example.mp4"></video>

<script src="dist/ass.min.js"></script>
<script>
fetch('/path/to/example.ass')
  .then(res => res.text())
  .then((text) => {
    const ass = new ASS(text, document.getElementById('video'));
  });
</script>

API

Initialization

const ass = new ASS(text, video, {
  // Subtitles will display in the container.
  // The container will be created automatically if it's not provided.
  container: document.getElementById('my-container'),

  // see resampling API below
  resampling: 'video_width',
});

Resize

If you change the size of video, you should call it.

ass.resize();

Show

ass.show();

Hide

ass.hide();

Destroy

ass.destroy();

Resampling

When script resolution(PlayResX and PlayResY) don't match the video resolution, this API defines how it behaves. However, drawings and clips will be always depending on script origin resolution.

There are four valid values, we suppose video resolution is 1280x720 and script resolution is 640x480 in following situations:

  • video_width: Script resolution will set to video resolution based on video width. Script resolution will set to 640x360, and scale = 1280 / 640 = 2.
  • video_height(default): Script resolution will set to video resolution based on video height. Script resolution will set to 853.33x480, and scale = 720 / 480 = 1.5.
  • script_width: Script resolution will not change but scale is based on script width. So scale = 1280 / 640 = 2. This may causes top and bottom subs disappear from video area.
  • script_height: Script resolution will not change but scale is based on script height. So scale = 720 / 480 = 1.5. Script area will be centered in video area.
ass.resampling = 'video_width';

TODO

Items with strikethrough means they won't be supported.

  • [Script Info]
    • Synch Point
    • PlayDepth
    • WrapStyle: 0, 3
    • Collisions: Reverse
  • [Events]
    • Picture
    • Sound
    • Movie
    • Command
    • Dialogue
      • Effect
        • Karaoke: as an effect type is obsolete
        • Scroll up: fadeawayheight
        • Scroll down: fadeawayheight
        • Banner: fadeawaywidth
      • Text (override codes)
        • \k, \kf, \ko, \kt, \K: Karaoke
        • \q: 0, 3
        • \t([<t1>, <t2>, ][<accel>, ]<style modifiers>): <accel>, \2c, \2a, \[i]clip
  • [Fonts]
  • [Graphics]

Known issues

  • \N in Aegisub has less height than <br> in browsers, subbers should avoid to use multiple \N to position a dialogue, use \pos instead.
  • A dialogue with multiple \t is not rendered correctly, for transforms in browsers are order-sensitive.
  • When a dialogue has Effect (Banner, Scroll up, Scroll down) and \move at the same time, only \move works.
  • For I'm using the clip-path CSS property to implement \clip, IE and Edge are not supported yet.
  • \be is just treated as \blur.
The MIT License (MIT) Copyright (c) 2014 weizhenye Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

No description expand collapse
JavaScript and 2 more languages
MIT
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ekber/ASS.git
git@gitee.com:ekber/ASS.git
ekber
ASS
ASS
master

Search