@fix-webm-duration/parser

中文文档
1.0.1发布于 2024/07/05MITTypeScriptCommonJS近 30 天下载 98.4万

Parse webm files into individual sections, edit the sections, and compile the file from edited sections back together

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. Parse a blob:
  4. Traverse nodes:
  5. Modify nodes
  6. Compile modified file back to blob

@fix-webm-duration/parser

Parse webm files into individual sections, edit the sections, and compile the file from edited sections back together.

Warning: it's an internal implementation package, the interfaces here can change at any moment! Please don't use it directly in production code, only for debugging contents of webm files while developing!

Installation

Install from a package manager:

npm install @fix-webm-duration/parser

Usage

Parse a blob:

import { WebmFile } from "@fix-webm-duration/parser";

const file = await WebmFile.fromBlob(blob);

It will return an instance of WebmFile, which is a tree of sections with IDs. WebmFile and WebmContainer are containers for other sections, while all other classes of webm nodes (WebmUint, WebmFloat, WebmString) are the final leaves of the tree. WebmBase is the base node class that is uses for nodes with unrecognized IDs (the map of webm nodes in the library is not full, it's only a set of nodes required to fix webm duration).

Traverse nodes:

The data field of a parsed WebmContainer (or WebmFile) object contains a list of child nodes (which could be leaves or other sections).

Use the getSectionById method to get a direct child section by ID, e.g.

const segmentSection: WebmContainer | null = file.getSectionById(0x8538067);

Section IDs could be found in the sections.ts file.

Modify nodes

Use the setValue method to modify the value of nodes, e.g.

const durationSection = infoSection.getSectionById(0x489);
if (!durationSection) throw new Error("Duration section not found");
durationSection.setValue(60000);

Access regular array method for the data field to add or remove child nodes for a sections, e.g.

const durationSection = new WebmFloat("Duration");
durationSection.setValue(duration);
infoSection.data!.push({
    id: 0x489,
    data: durationSection,
});

Compile modified file back to blob

Call updateByData method of all modified WebmContainer and WebmFile objects in the reverse order, i.e. starting from the most nested nodes, and ending with the WebmFile object.

Call the toBlob method of the file to convert the parsed file to blob. Pass MIME type to it if it's not default, e.g. file.toBlob("audio/webm").

版本与发布记录

@fix-webm-duration/parser 共发布 3 个版本,首次发布于 2024/07/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.02024/07/052 年前
1.0.1latest2024/07/052 年前
1.0.02024/07/052 年前

关于 @fix-webm-duration/parser 的常见问题

@fix-webm-duration/parser 是什么?

Parse webm files into individual sections, edit the sections, and compile the file from edited sections back together

如何安装 @fix-webm-duration/parser?

在项目目录运行 npm install @fix-webm-duration/parser,或使用 pnpm add / yarn add / bun add。

@fix-webm-duration/parser 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fix-webm-duration/parser 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@fix-webm-duration/parser 可以商用吗?

@fix-webm-duration/parser 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fix-webm-duration/parser 的下载量有多少?

根据 npm 官方下载统计,@fix-webm-duration/parser 在 2026/10/15 – 2026/11/13 这 30 天内被下载 983,747 次,日均约 32,792 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fix-webm-duration/parser 还在维护吗?

最新版本 1.0.1 发布于 2024/07/05(2 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/07/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。