0.0.4 • Published 8 months ago

dempeg v0.0.4

Weekly downloads
-
License
AGPL-3.0
Repository
github
Last release
8 months ago

dempeg

A lightweight, dependency-free MP4 decrypter for Node.js.

Features

  • Decryption of MP4 files with MPEG Common Encryption (CENC)
  • Small size (~10kB without types)
  • Command-line interface
  • Segment-by-segment processing with JavaScript library
  • Custom handler for subsample processing

Prerequisites

Installation

Install library as dependency for your project:

npm install dempeg

Install globally to use as command-line tool:

npm install -g dempeg

Usage

Library

File decryption

import { decryptFile } from 'dempeg';

decryptFile('./input.mp4', './output.mp4', {
  key: 'eb676abbcb345e96bbcf616630f1a3da',
  keyId: '100b6c20940f779a4589152b57d2dacb',
});

Segment-by-segment decryption

import { decryptSegment } from 'dempeg';

const segments = [
  // List of MPEG-DASH segments
  // ...
];
const results = [];

(async () => {
  for (const segment of segments) {
    const decrypted = await decryptSegment(segment, {
      key: 'eb676abbcb345e96bbcf616630f1a3da',
      keyId: '100b6c20940f779a4589152b57d2dacb',
    });
    results.push(decrypted);
  }
})();

// Do something with results...

Custom subsample handler

import { createDecipheriv } from 'node:crypto';
import { decryptSegment } from 'dempeg';

const segments = [
  // List of MPEG-DASH segments
  // ...
];
const results = [];

(async () => {
  for (const segment of segments) {
    const decrypted = await decryptSegment(segment, {
      keyId: '100b6c20940f779a4589152b57d2dacb',
      decryptSubsampleFn: (params) => {
        // Custom subsample handler
        // ...
        const subsample = params.data;
        const iv = params.iv;
        const key = 'eb676abbcb345e96bbcf616630f1a3da';
        const decipher = createDecipheriv('aes-128-ctr', key, iv);
        const decrypted = Buffer.concat([decipher.update(subsample), decipher.final()]);
        return decrypted;
      },
    });
    results.push(decrypted);
  }
})();

// Do something with results...

Shell-like syntax:

import { $ } from 'dempeg';

$`dempeg --key eb676abbcb345e96bbcf616630f1a3da:100b6c20940f779a4589152b57d2dacb ./input.mp4 ./output.mp4`;

CLI

dempeg --key eb676abbcb345e96bbcf616630f1a3da:100b6c20940f779a4589152b57d2dacb ./input.mp4 ./output.mp4
0.0.3

8 months ago

0.0.4

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago