Skip to content

Commit a24524e

Browse files
committed
Release v1.07: Add MPEG2 video codec support.
1 parent 726feee commit a24524e

File tree

4 files changed

+53
-17
lines changed

4 files changed

+53
-17
lines changed

README.md

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,30 @@ or
2323
$ yarn add @codedread/bitjs
2424
```
2525

26-
## bitjs.archive
26+
### Using in Node
27+
28+
This module is an ES Module, which should work as expected in other projects using ES Modules. However,
29+
if you are using a project that uses CommonJs modules, it's a little tricker to use. One valid example
30+
of this is if a TypeScript project compiles to CommonJS, it will try to turn imports into require()
31+
statements, which will break. The fix for this (unfortunately) is to update your tsconfig.json:
32+
33+
```json
34+
"moduleResolution": "Node16",
35+
```
36+
37+
and use a Dynamic Import:
38+
39+
```javascript
40+
const { getFullMIMEString } = await import('@codedread/bitjs');
41+
```
42+
43+
## Packages
44+
45+
### bitjs.archive
2746

2847
This package includes objects for unarchiving binary data in popular archive formats (zip, rar, tar) providing unzip, unrar and untar capabilities via JavaScript in the browser. A prototype version of a compressor that creates Zip files is also present. The decompression/compression actually happens inside a Web Worker.
2948

30-
### Decompressing
49+
#### Decompressing
3150

3251
```javascript
3352
import { Unzipper } from './bitjs/archive/decompress.js';
@@ -69,7 +88,7 @@ unzipper.update(anArrayBufferWithMoreBytes);
6988
unzipper.update(anArrayBufferWithYetMoreBytes);
7089
```
7190

72-
### Compressing
91+
#### Compressing
7392

7493
The Zipper only supports creating zip files without compression (story only) for now. The interface
7594
is pretty straightforward and there is no event-based / streaming API.
@@ -95,7 +114,7 @@ const zippedArrayBuffer = await zipper.start(
95114
true /* isLastFile */);
96115
```
97116

98-
## bitjs.codecs
117+
### bitjs.codecs
99118

100119
This package includes code for dealing with media files (audio/video). It is useful for deriving
101120
ISO RFC6381 MIME type strings, including the codec information. Currently supports a limited subset
@@ -121,7 +140,7 @@ exec(cmd, (error, stdout) => {
121140
});
122141
```
123142

124-
## bitjs.file
143+
### bitjs.file
125144

126145
This package includes code for dealing with files. It includes a sniffer which detects the type of file, given an ArrayBuffer.
127146

@@ -130,7 +149,7 @@ import { findMimeType } from './bitjs/file/sniffer.js';
130149
const mimeType = findMimeType(someArrayBuffer);
131150
```
132151

133-
## bitjs.image
152+
### bitjs.image
134153

135154
This package includes code for dealing with binary images. It includes a module for converting WebP images into alternative raster graphics formats (PNG/JPG).
136155

@@ -145,7 +164,7 @@ convertWebPtoPNG(webpBuffer).then(pngBuf => {
145164
});
146165
```
147166

148-
## bitjs.io
167+
### bitjs.io
149168

150169
This package includes stream objects for reading and writing binary data at the bit and byte level: BitStream, ByteStream.
151170

@@ -156,12 +175,6 @@ const crc = bstream.readBits(12); // read in 12 bits as CRC, advancing the point
156175
const flagbits = bstream.peekBits(6); // look ahead at next 6 bits, but do not advance the pointer
157176
```
158177

159-
# Other Tests
160-
161-
Those that haven't been ported to mocha/chai/nodejs.
162-
163-
* [bitjs.archive tests](https://codedread.github.io/bitjs/tests/archive-test.html)
164-
165178
## Reference
166179

167180
* [UnRar](http://codedread.github.io/bitjs/docs/unrar.html): A work-in-progress description of the RAR file format.

codecs/codecs.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
*/
2828

2929
/**
30-
* @typedef ProbeFormat ffprobe -show_format -print_format json. Only the fields we care about.
30+
* @typedef ProbeFormat Only the fields we care about from the following command:
31+
* ffprobe -show_format -show_streams -v quiet -print_format json -i file.mp4
3132
* @property {string} filename
3233
* @property {string} format_name
3334
* @property {string} duration Number of seconds, as a string like "473.506367".
@@ -123,7 +124,7 @@ export function getFullMIMEString(info) {
123124
case 'opus': codecFrags.add('opus'); break;
124125
default:
125126
throw `Could not handle codec_name ${stream.codec_name}, ` +
126-
`codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` +
127+
`codec_tag_string ${stream.codec_tag_string} for file ${info.format.filename} yet. ` +
127128
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
128129
}
129130
break;
@@ -141,9 +142,10 @@ export function getFullMIMEString(info) {
141142
switch (stream.codec_name) {
142143
case 'h264': codecFrags.add(getAVC1CodecString(stream)); break;
143144
case 'vp9': codecFrags.add(getVP09CodecString(stream)); break;
145+
case 'mpeg2video': codecFrags.add('mpeg2video'); break;
144146
default:
145147
throw `Could not handle codec_name ${stream.codec_name}, ` +
146-
`codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` +
148+
`codec_tag_string ${stream.codec_tag_string} for file ${info.format.filename} yet. ` +
147149
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
148150

149151
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codedread/bitjs",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "Binary Tools for JavaScript",
55
"homepage": "https://github.com/codedread/bitjs",
66
"author": "Jeff Schiller",

tests/codecs.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,25 @@ describe('codecs test suite', () => {
354354
.and.equals('audio/webm; codecs="opus"');
355355
});
356356
});
357+
358+
describe('MPEG2', () => {
359+
/** @type {ProbeInfo} */
360+
let info;
361+
362+
beforeEach(() => {
363+
info = {
364+
format: { format_name: 'matroska,webm' },
365+
streams: [{
366+
codec_type: 'video',
367+
codec_name: 'mpeg2video',
368+
}],
369+
};
370+
});
371+
372+
it('detects mpeg2video', () => {
373+
expect(getFullMIMEString(info))
374+
.to.be.a('string')
375+
.and.equals('video/webm; codecs="mpeg2video"');
376+
});
377+
});
357378
});

0 commit comments

Comments
 (0)