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

@fix-webm-duration/parser

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fix-webm-duration/parser

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

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@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").

FAQs

Package last updated on 05 Jul 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