@fix-webm-duration/fix

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

navigator.mediaDevices.getUserMedia + MediaRecorder create WEBM files without duration metadata. This library appends missing metadata section right to the file blob.

原始使用文档

@fix-webm-duration/fix

navigator.mediaDevices.getUserMedia + MediaRecorder create WEBM files without duration metadata.

This library appends missing metadata section right to the file blob.

Installation

Install from a package manager:

npm install @fix-webm-duration/fix

Then, the library could be imported:

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

Usage

Syntax:

const newBlob = await fixWebmDuration(blob, duration, options = {});

where

  • blob is Blob object with file contents from MediaRecorder
  • duration is video duration in milliseconds (you should calculate it while recording the video)
  • options is an object of options:
    • options.logger - a callback for logging debug messages or false. The callback should accept one argument - the message string. By default, console.debug will be used for logging. Passing false will disable the logging.

fixWebmDuration will parse and fix your file asynchronously and return the fixed blob once the result is ready.

If the original blob already contains duration metadata section and the duration value is not empty, the callback will receive it without any changes made.

Example:

let mediaRecorder;
let mediaParts;
let startTime;

function startRecording(stream: MediaStream, options: MediaRecorderOptions) {
    mediaParts = [];
    mediaRecorder = new MediaRecorder(stream, options);
    mediaRecorder.onstop = async () => {
        const duration = Date.now() - startTime;
        const buggyBlob = new Blob(mediaParts, { type: "video/webm" });

        const fixedBlob = await fixWebmDuration(buggyBlob, duration)
        displayResult(fixedBlob);
    };
    mediaRecorder.ondataavailable = (event) => {
        var data = event.data;
        if (data && data.size > 0) {
            mediaParts.push(data);
        }
    };
    mediaRecorder.start();
    startTime = Date.now();
}

function stopRecording() {
    mediaRecorder.stop();
}

function displayResult(blob: Blob) {
    // ...
}

Note: this example is not a MediaRecorder usage guide.

版本与发布记录

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

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

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

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

navigator.mediaDevices.getUserMedia + MediaRecorder create WEBM files without duration metadata. This library appends missing metadata section right to the file blob.

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

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

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

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

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

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

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

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

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

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

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

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