0.0.6 • Published 4 months ago
search-in-video v0.0.6
Search-In-Video
在视频中搜索字幕返回对应的导航点,借助导航点跳转播放至自己感兴趣的视频片段。
Note
目前仅支持在外挂字幕和内嵌软字幕的视频中搜索,包括:
- SRT
- ASS/SSA
- MKV
导航点(即返回结果)是一个JavaScript对象,如:
{
"content": "subtitle content",
"startTime": "1234"
}
导航点中
startTime
的单位是毫秒。
Install
npm install search-in-video
API
async function* searchInMkv(keyword: string, stream: Readable, videoIdentifier: string) ``` 在MKV视频中搜索字幕,参数stream为内嵌软字幕的MKV视频流,`videoIdentifier`用来标识该视频的字幕缓存。注意,如果`videoIdentifier`为空字符串,每次搜索都会解析视频。
async function* searchInSrt(keyword: string, srtStream: Readable) ``` 在SRT外挂字幕流中搜索。
async function* searchInSsa(keyword: string, ssaStream: Readable) ``` 在ASS/SSA外挂字幕流中搜索 。
function* search(keyword: string, subtitles: Array) ``` subtitles是一个导航点数组。
async function extractFromMkv(stream: Readable) ``` 从MKV视频流中提取所有字幕,返回一个导航点数组,可作为`search`函数的参数。
Example
在SRT外挂字幕中搜索:
const {searchInSrt} = require('search-in-video');
const fs = require("fs");
(async () => {
const result = searchInSrt('content', fs.createReadStream('/path/to/test.srt'))
for await (const obj of result) {
console.log(obj);
}
})();