This is the core library of the chaptertool project and provides the functionality to handle the formats below.
Click here to open the web GUI or go install chaptertool locally for CLI use.
class | description | key | ext | info |
---|---|---|---|---|
ChaptersJson | Podcasting 2.0 Chapters | chaptersjson | json |
spec |
FFMetadata | FFMetadata | ffmpegdata | txt |
spec |
MatroskaXML | Matroska XML chapters | matroskaxml | xml |
spec |
MKVMergeXML | MKVToolNix mkvmerge XML | mkvmergexml | xml |
spec |
MKVMergeSimple | MKVToolNix mkvmerge simple | mkvmergesimple | txt |
spec |
WebVTT | WebVTT Chapters | webvtt | vtt |
spec |
Youtube | Youtube Chapter Syntax | youtube | txt |
|
FFMpegInfo | FFMpegInfo | ffmpeginfo | txt |
read only, used internally |
PySceneDetect | PySceneDetect | pyscenedetect | csv |
project home |
VorbisComment | Vorbis Comment Format | vorbiscomment | txt |
spec |
AppleChapters | "Apple Chapters" | applechapters | xml |
source |
ShutterEDL | Shutter EDL | edl | edl |
source |
PodloveSimpleChapters | Podlove Simple Chapters | psc | xml |
spec |
PodloveJson | Podlove Simple Chapters JSON | podlovejson | json |
source |
MP4Chaps | MP4Chaps | mp4chaps | txt |
source |
AppleHLS | Apple HLS Chapters | applehls | json |
spec, partial support |
Scenecut | Scenecut format | scenecut | json |
source |
npm i @mtillmann/chapters
import { ChaptersJson } from '@mtillmann/chapters';
const chapters = new ChaptersJson()
chapters.add({ startTime: 0, title: 'Intro' })
chapters.add({ startTime: 30, title: 'Some Topic' })
const json = chapters.toString()
Autoformat
is a helper that can be used to automatically detect the format of a given input and return the corresponding class,
key or a new instance of the detected class. It also provides a method to convert the input to a specific format.
import { Autoformat } from '@mtillmann/chapters'
import { WebVTT } from '@mtillmann/chapters'
const content = '<podcasting 2.0 chapters.json>...'
const instance = Autoformat.detect(content) // returns an instance of ChaptersJson
const instance2 = Autoformat.from(content) // returns an instance of ChaptersJson
const key = Autoformat.detect(content, 'key') // returns 'chaptersjson'
const className = Autoformat.detect(content, 'class') // returns ChaptersJson
const webVttString = 'WEBVTT...';
const autodetectedWebVtt = Autoformat.detect(webVttString) // returns an instance of WebVTT
const fail = Autoformat.as('chaptersjson', webVttString) // throws an error
const vtt = Autoformat.as('webvtt', webVttString) // returns an instance of WebVTT
const vtt2 = Autoformat.as(WebVTT, webVttString) // returns an instance of WebVTT
All formats support the following methods:
Creates a new instance of the class, optionally with a duration in seconds.
const chapters = (new ChaptersJson(3600)).from(input)
the constructor will not accept any input due to javascript's order of initialization which prevents the parse method from having access to cerain locally defined properties and methods.
Creates a new media item. This is the suggested way to create a media item from a string:
const chapters = MatroskaXML.create(input)
// chapters is now an instance of MatroskaXML
const chapterString = WebVTT.create(chapters).toString()
// chapterString is now a string representation of the chapters
Populates the media item's chapters from the given input.
Converts the media item to another format.
Adds a chapter.
Adds a chapter at the given index.
Adds a chapter at the given time.
Removes the chapter at the given index.
Updates the chapters and duration. Called automatically after adding or removing chapters.
Returns the end time for the chapter at the given index.
Expands the first chapter to start at 0.
Applies a minimum length to the chapters.
Checks if a chapter exists at the given start time.
Updates the start time for the chapter at the given index.
Returns the index of the chapter with the given start time.
Returns the index of the chapter at the given time.
Convert the chapters to a string.
If pretty
is true
, the output will be formatted for better readability. Only supported by json
and xml
formats.
Some formats support additional options:
option | type | default | description |
---|---|---|---|
imagePrefix |
string |
'' |
Prefix for image URLs |
writeRedundantToc |
boolean |
false |
Write redundant TOC attributes |
writeEndTimes |
boolean |
false |
Write end times |
option | type | default | description |
---|---|---|---|
acUseTextAttr |
boolean |
false |
When set, the text-attribute will be used instead of node textContent |
option | type | default | description |
---|---|---|---|
psdFramerate |
number |
23.976 |
Framerate of the video file |
psdOmitTimecodes |
boolen |
false |
When set, the first line will be omitted |
option | type | default | description |
---|---|---|---|
frameRate |
number |
30 |
Framerate of the video file |
ptsScale |
number |
1 |
PTS scale (See below) |
score |
number |
0.5 |
Score threshold |
When asked about the ptsScale
-value, ChatGPT said:
The number "1001" in the context of video processing and multimedia, especially in relation to frame rates and timecodes, is often associated with the NTSC color system used in North America and Japan. In this system, the frame rate is often described as "29.97 frames per second", but it's technically 30000/1001 frames per second, which is approximately 29.97 but not exactly. This is known as a "drop frame" rate, and the "1001" comes from this fractional frame rate.
When you use 1
the output pts
will be the same as the frame
number. When you use 1001
the output pts
will be the same as the frame
number multiplied by 1001
.