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

@ludovicm67/mp4-tools

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ludovicm67/mp4-tools - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

10

CHANGELOG.md
# @ludovicm67/mp4-tools
## 0.2.0
### Minor Changes
- 654c7ae: Export a `fix` function that can be used to fix a chunk using the previous chunk.
### Patch Changes
- e441529: Improve the CLI for fixes, so that it supports working with the rest of the previous chunk.
## 0.1.1

@@ -4,0 +14,0 @@

12

cli/fix.js

@@ -5,3 +5,3 @@ // @ts-check

import { readFile } from 'node:fs/promises'
import { buildFile, parse } from '../index.js'
import { fix as fixMP4Chunk } from '../index.js'

@@ -29,12 +29,8 @@ /**

const prevChunk = await readFile(prevChunkPath)
const brokenChunk = await readFile(brokenChunkPath)
const prevChunk = /** @type {import('@ludovicm67/media-tools-utils').Buffer} */ (/** @type {unknown} */ (await readFile(prevChunkPath)))
const brokenChunk = /** @type {import('@ludovicm67/media-tools-utils').Buffer} */ (/** @type {unknown} */ (await readFile(brokenChunkPath)))
const parsedPrevChunk = parse(prevChunk)
const parsedBrokenChunk = parse(brokenChunk)
const filedata = fixMP4Chunk(prevChunk, brokenChunk, { debug })
const { filedata, rest } = buildFile(parsedBrokenChunk, parsedPrevChunk)
if (debug) {
console.log('Rest:', rest)
console.info(`\nWriting fixed chunk to file: '${outputPath}'`)

@@ -41,0 +37,0 @@ }

export function buildFile(data: MP4ParsedFile, context?: MP4ParsedFile | null): {
filedata: Buffer;
rest: Buffer;
rest: any;
};
export function parse(fileBuffer: Buffer): MP4ParsedFile;
export function parse(fileBuffer: any): MP4ParsedFile;
export function fix(prevChunk: any, brokenChunk: any, options: LibOptions | null): any;
/**

@@ -13,7 +14,7 @@ * Internal representation of a MP4 file.

*/
ftyp: Buffer;
ftyp: any;
/**
* The moov box.
*/
moov: Buffer;
moov: any;
/**

@@ -24,3 +25,3 @@ * The chunks of the file.

type: string;
data: Buffer;
data: any;
}>;

@@ -30,6 +31,13 @@ /**

*/
rest: Buffer;
rest: any;
};
export type LibOptions = {
/**
* Whether to enable debug mode or not.
*/
debug: boolean | null;
};
export { utils, Buffer };
export { readBoxSize, readBoxType } from "./lib/base.js";
export { parseFtypBox, parseMoovBox, parseMoofBox, parseMdatBox } from "./lib/boxes.js";
//# sourceMappingURL=index.d.ts.map

@@ -5,7 +5,7 @@ // @ts-check

import { Buffer, utils } from '@ludovicm67/media-tools-utils'
export { readBoxSize, readBoxType } from './lib/base.js'
export { parseFtypBox, parseMoovBox, parseMoofBox, parseMdatBox } from './lib/boxes.js'
export { Buffer, utils } from '@ludovicm67/media-tools-utils'
/**

@@ -15,6 +15,6 @@ * Internal representation of a MP4 file.

* @typedef {Object} MP4ParsedFile
* @property {Buffer} ftyp The ftyp box.
* @property {Buffer} moov The moov box.
* @property {Array<{ type: string, data: Buffer }>} chunks The chunks of the file.
* @property {Buffer} rest The rest of the file.
* @property {import('@ludovicm67/media-tools-utils').Buffer} ftyp The ftyp box.
* @property {import('@ludovicm67/media-tools-utils').Buffer} moov The moov box.
* @property {Array<{ type: string, data: import('@ludovicm67/media-tools-utils').Buffer }>} chunks The chunks of the file.
* @property {import('@ludovicm67/media-tools-utils').Buffer} rest The rest of the file.
*/

@@ -29,3 +29,3 @@

* @param {MP4ParsedFile?} [context={}] The context to use to build the file, usually the previous parsed chunk.
* @returns {{ filedata: Buffer, rest: Buffer }} The built file and the rest of the file.
* @returns {{ filedata: Buffer, rest: import('@ludovicm67/media-tools-utils').Buffer }} The built file and the rest of the file.
*/

@@ -91,3 +91,3 @@ export const buildFile = (data, context) => {

*
* @param {Buffer} fileBuffer The file to parse as a Buffer.
* @param {import('@ludovicm67/media-tools-utils').Buffer} fileBuffer The file to parse as a Buffer.
* @returns {MP4ParsedFile} The parsed file.

@@ -144,1 +144,37 @@ */

}
/**
* @typedef {Object} LibOptions
* @property {boolean?} debug Whether to enable debug mode or not.
*/
/**
* Fix a MP4 file using the previous chunk.
* The previous chunk should be a sane chunk.
* It should be the one that is right before the broken chunk.
*
* @param {import('@ludovicm67/media-tools-utils').Buffer} prevChunk Content of the previous (sane) chunk.
* @param {import('@ludovicm67/media-tools-utils').Buffer} brokenChunk Content of the broken chunk.
* @param {LibOptions?} options Options.
* @returns {import('@ludovicm67/media-tools-utils').Buffer} The fixed chunk.
*/
export const fix = (prevChunk, brokenChunk, options) => {
const { debug } = options || {}
const parsedPrevChunk = parse(prevChunk)
const prevChunkRest = parsedPrevChunk.rest || Buffer.from([])
const brokenChunkMerge = Buffer.concat([prevChunkRest, brokenChunk])
const parsedBrokenChunk = parse(brokenChunkMerge)
const { filedata, rest } = buildFile(parsedBrokenChunk, parsedPrevChunk)
if (debug) {
console.log('Rest:', rest)
}
return filedata
}
export {
utils,
Buffer
}

@@ -1,3 +0,3 @@

export function readBoxSize(buffer: Buffer, index: number): number;
export function readBoxType(buffer: Buffer, index: number): string;
export function readBoxSize(buffer: any, index: number): number;
export function readBoxType(buffer: any, index: number): string;
//# sourceMappingURL=base.d.ts.map

@@ -6,3 +6,3 @@ // @ts-check

*
* @param {Buffer} buffer The buffer to read from.
* @param {import('@ludovicm67/media-tools-utils').Buffer} buffer The buffer to read from.
* @param {number} index The index at which to start reading.

@@ -29,3 +29,3 @@ * @returns {number} The size of the box.

*
* @param {Buffer} buffer The buffer to read from.
* @param {import('@ludovicm67/media-tools-utils').Buffer} buffer The buffer to read from.
* @param {number} index The index at which to start reading.

@@ -32,0 +32,0 @@ * @returns {string} The type of the box.

@@ -1,5 +0,5 @@

export function parseFtypBox(buffer: Buffer, index: number, size: number): FtypBox;
export function parseMoovBox(buffer: Buffer, index: number, size: number): MoovBox;
export function parseMdatBox(_buffer: Buffer, index: number, size: number): MdatBox;
export function parseMoofBox(buffer: Buffer, index: number, size: number): MoofBox;
export function parseFtypBox(buffer: any, index: number, size: number): FtypBox;
export function parseMoovBox(buffer: any, index: number, size: number): MoovBox;
export function parseMdatBox(_buffer: any, index: number, size: number): MdatBox;
export function parseMoofBox(buffer: any, index: number, size: number): MoofBox;
export type FtypBox = {

@@ -6,0 +6,0 @@ /**

@@ -15,3 +15,3 @@ // @ts-check

*
* @param {Buffer} buffer The buffer to read from.
* @param {import('@ludovicm67/media-tools-utils').Buffer} buffer The buffer to read from.
* @param {number} index The index at which to start reading.

@@ -58,3 +58,3 @@ * @param {number} size The size of the box.

*
* @param {Buffer} buffer The buffer to read from.
* @param {import('@ludovicm67/media-tools-utils').Buffer} buffer The buffer to read from.
* @param {number} index The index at which to start reading.

@@ -91,3 +91,3 @@ * @param {number} size The size of the box.

*
* @param {Buffer} _buffer The buffer to read from.
* @param {import('@ludovicm67/media-tools-utils').Buffer} _buffer The buffer to read from.
* @param {number} index The index at which to start reading.

@@ -116,3 +116,3 @@ * @param {number} size The size of the box.

*
* @param {Buffer} buffer The buffer to read from.
* @param {import('@ludovicm67/media-tools-utils').Buffer} buffer The buffer to read from.
* @param {number} index The index at which to start reading.

@@ -119,0 +119,0 @@ * @param {number} size The size of the box.

{
"name": "@ludovicm67/mp4-tools",
"version": "0.1.1",
"version": "0.2.0",
"description": "MP4 tools",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -13,2 +13,3 @@ # MP4 tools

- `utils.blobToArrayBuffer`: a function to convert a Blob to an ArrayBuffer
- `fix`: the function to use to fix a chunk by using the previous one

@@ -15,0 +16,0 @@ ## MP4 structure

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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