@amazon/vinyl-transmux 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1150 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +1130 -0
- package/dist/index.js.map +7 -0
- package/dist/types/current/aac/adts.d.ts +38 -0
- package/dist/types/current/aac/adts.d.ts.map +1 -0
- package/dist/types/current/aac/adts.js +63 -0
- package/dist/types/current/index.d.ts +7 -0
- package/dist/types/current/index.d.ts.map +1 -0
- package/dist/types/current/index.js +6 -0
- package/dist/types/current/mp4/mp4.d.ts +70 -0
- package/dist/types/current/mp4/mp4.d.ts.map +1 -0
- package/dist/types/current/mp4/mp4.js +338 -0
- package/dist/types/current/mpegts/mpegts.d.ts +68 -0
- package/dist/types/current/mpegts/mpegts.d.ts.map +1 -0
- package/dist/types/current/mpegts/mpegts.js +202 -0
- package/dist/types/current/transmux/sampleEntry.d.ts +25 -0
- package/dist/types/current/transmux/sampleEntry.d.ts.map +1 -0
- package/dist/types/current/transmux/sampleEntry.js +114 -0
- package/dist/types/current/transmux/transmux.d.ts +17 -0
- package/dist/types/current/transmux/transmux.d.ts.map +1 -0
- package/dist/types/current/transmux/transmux.js +568 -0
- package/dist/types/current/tsconfig.tsbuildinfo +1 -0
- package/dist/types/ts3.7/aac/adts.d.ts +38 -0
- package/dist/types/ts3.7/index.d.ts +7 -0
- package/dist/types/ts3.7/mp4/mp4.d.ts +70 -0
- package/dist/types/ts3.7/mpegts/mpegts.d.ts +68 -0
- package/dist/types/ts3.7/transmux/sampleEntry.d.ts +25 -0
- package/dist/types/ts3.7/transmux/transmux.d.ts +17 -0
- package/dist/types/ts4.1/aac/adts.d.ts +38 -0
- package/dist/types/ts4.1/index.d.ts +7 -0
- package/dist/types/ts4.1/mp4/mp4.d.ts +70 -0
- package/dist/types/ts4.1/mpegts/mpegts.d.ts +68 -0
- package/dist/types/ts4.1/transmux/sampleEntry.d.ts +25 -0
- package/dist/types/ts4.1/transmux/transmux.d.ts +17 -0
- package/dist/types/ts4.7/aac/adts.d.ts +38 -0
- package/dist/types/ts4.7/index.d.ts +7 -0
- package/dist/types/ts4.7/mp4/mp4.d.ts +70 -0
- package/dist/types/ts4.7/mpegts/mpegts.d.ts +68 -0
- package/dist/types/ts4.7/transmux/sampleEntry.d.ts +25 -0
- package/dist/types/ts4.7/transmux/transmux.d.ts +17 -0
- package/docs/TRANSMUX.md +131 -0
- package/package.json +82 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Codec-specific MP4 sample entry builders for AAC and H.264.
|
|
7
|
+
*
|
|
8
|
+
* These produce the sample entry boxes (mp4a, avc1) that are placed inside
|
|
9
|
+
* the generic stsd box built by the mp4 layer.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { BufferWriter } from '@amazon/vinyl-util';
|
|
14
|
+
import { box, fullBox } from '../mp4/mp4';
|
|
15
|
+
/** 72 dpi in 16.16 fixed point. */
|
|
16
|
+
const RESOLUTION_72_DPI = 0x00480000;
|
|
17
|
+
/** ESDS object type indication for AAC (ISO 14496-3). */
|
|
18
|
+
const OBJECT_TYPE_AAC = 0x40;
|
|
19
|
+
/** ESDS stream type for audio: (0x05 << 2) | 0x01. */
|
|
20
|
+
const STREAM_TYPE_AUDIO = 0x15;
|
|
21
|
+
/**
|
|
22
|
+
* Builds an mp4a sample entry box for AAC audio.
|
|
23
|
+
*/
|
|
24
|
+
export function mp4aSampleEntry(config) {
|
|
25
|
+
const writer = new BufferWriter(28);
|
|
26
|
+
// 6 bytes reserved
|
|
27
|
+
for (let i = 0; i < 6; i++)
|
|
28
|
+
writer.writeUint8(0);
|
|
29
|
+
writer.writeUint16(1); // data_reference_index
|
|
30
|
+
// 8 bytes reserved
|
|
31
|
+
for (let i = 0; i < 8; i++)
|
|
32
|
+
writer.writeUint8(0);
|
|
33
|
+
writer.writeUint16(config.channelConfiguration);
|
|
34
|
+
writer.writeUint16(16); // sample_size
|
|
35
|
+
writer.writeUint16(0); // pre_defined
|
|
36
|
+
writer.writeUint16(0); // reserved
|
|
37
|
+
writer.writeUint32(config.sampleRate << 16); // sample_rate (16.16)
|
|
38
|
+
return box('mp4a', writer.toUint8Array(), esds(config));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Builds an avc1 sample entry box for H.264 video.
|
|
42
|
+
*/
|
|
43
|
+
export function avc1SampleEntry(config) {
|
|
44
|
+
const writer = new BufferWriter(78);
|
|
45
|
+
// 6 bytes reserved
|
|
46
|
+
for (let i = 0; i < 6; i++)
|
|
47
|
+
writer.writeUint8(0);
|
|
48
|
+
writer.writeUint16(1); // data_reference_index
|
|
49
|
+
// 16 bytes pre_defined + reserved
|
|
50
|
+
for (let i = 0; i < 16; i++)
|
|
51
|
+
writer.writeUint8(0);
|
|
52
|
+
writer.writeUint16(config.width);
|
|
53
|
+
writer.writeUint16(config.height);
|
|
54
|
+
writer.writeUint32(RESOLUTION_72_DPI);
|
|
55
|
+
writer.writeUint32(RESOLUTION_72_DPI);
|
|
56
|
+
writer.writeUint32(0); // reserved
|
|
57
|
+
writer.writeUint16(1); // frame_count
|
|
58
|
+
// 32 bytes compressorname
|
|
59
|
+
for (let i = 0; i < 32; i++)
|
|
60
|
+
writer.writeUint8(0);
|
|
61
|
+
writer.writeUint16(0x0018); // depth = 24
|
|
62
|
+
writer.writeInt16(-1); // pre_defined
|
|
63
|
+
return box('avc1', writer.toUint8Array(), avcC(config));
|
|
64
|
+
}
|
|
65
|
+
function esds(config) {
|
|
66
|
+
const asc = config.audioSpecificConfig;
|
|
67
|
+
// DecoderSpecificInfo (tag 0x05)
|
|
68
|
+
const dsi = new BufferWriter(2 + asc.byteLength);
|
|
69
|
+
dsi.writeUint8(0x05);
|
|
70
|
+
dsi.writeUint8(asc.byteLength);
|
|
71
|
+
dsi.writeBytes(asc);
|
|
72
|
+
// DecoderConfigDescriptor (tag 0x04)
|
|
73
|
+
const dcd = new BufferWriter(2 + 13 + dsi.position);
|
|
74
|
+
dcd.writeUint8(0x04);
|
|
75
|
+
dcd.writeUint8(13 + dsi.position);
|
|
76
|
+
dcd.writeUint8(OBJECT_TYPE_AAC);
|
|
77
|
+
dcd.writeUint8(STREAM_TYPE_AUDIO);
|
|
78
|
+
dcd.writeUint8(0); // bufferSizeDB (3 bytes)
|
|
79
|
+
dcd.writeUint8(0);
|
|
80
|
+
dcd.writeUint8(0);
|
|
81
|
+
dcd.writeUint32(0); // maxBitrate
|
|
82
|
+
dcd.writeUint32(0); // avgBitrate
|
|
83
|
+
dcd.writeBytes(dsi.toUint8Array());
|
|
84
|
+
// SLConfigDescriptor (tag 0x06)
|
|
85
|
+
const slc = new BufferWriter(3);
|
|
86
|
+
slc.writeUint8(0x06);
|
|
87
|
+
slc.writeUint8(1);
|
|
88
|
+
slc.writeUint8(0x02); // predefined = 2
|
|
89
|
+
// ES_Descriptor (tag 0x03)
|
|
90
|
+
const esPayloadSize = 3 + dcd.position + slc.position;
|
|
91
|
+
const es = new BufferWriter(2 + esPayloadSize);
|
|
92
|
+
es.writeUint8(0x03);
|
|
93
|
+
es.writeUint8(esPayloadSize);
|
|
94
|
+
es.writeUint16(1); // ES_ID
|
|
95
|
+
es.writeUint8(0); // flags
|
|
96
|
+
es.writeBytes(dcd.toUint8Array());
|
|
97
|
+
es.writeBytes(slc.toUint8Array());
|
|
98
|
+
return fullBox('esds', 0, 0, es.toUint8Array());
|
|
99
|
+
}
|
|
100
|
+
function avcC(config) {
|
|
101
|
+
const writer = new BufferWriter(11 + config.sps.byteLength + config.pps.byteLength);
|
|
102
|
+
writer.writeUint8(1); // configurationVersion
|
|
103
|
+
writer.writeUint8(config.profileIdc);
|
|
104
|
+
writer.writeUint8(config.profileCompatibility);
|
|
105
|
+
writer.writeUint8(config.levelIdc);
|
|
106
|
+
writer.writeUint8(3); // lengthSizeMinusOne = 3 (4 bytes)
|
|
107
|
+
writer.writeUint8(0xe1); // numOfSequenceParameterSets = 1
|
|
108
|
+
writer.writeUint16(config.sps.byteLength);
|
|
109
|
+
writer.writeBytes(config.sps);
|
|
110
|
+
writer.writeUint8(1); // numOfPictureParameterSets
|
|
111
|
+
writer.writeUint16(config.pps.byteLength);
|
|
112
|
+
writer.writeBytes(config.pps);
|
|
113
|
+
return box('avcC', writer.toUint8Array());
|
|
114
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface TransmuxResult {
|
|
2
|
+
/** The initialization segment (ftyp + moov). Always present. */
|
|
3
|
+
readonly initSegment: ArrayBuffer;
|
|
4
|
+
/** The media segment (moof + mdat). */
|
|
5
|
+
readonly mediaSegment: ArrayBuffer;
|
|
6
|
+
/** Duration of this segment in seconds. */
|
|
7
|
+
readonly duration: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a stateful transmuxer instance. Call `transmux()` for each HLS
|
|
11
|
+
* segment in order. The init segment is always returned (cached after first
|
|
12
|
+
* call).
|
|
13
|
+
*/
|
|
14
|
+
export declare function createTransmuxer(): {
|
|
15
|
+
transmux: (data: ArrayBuffer) => TransmuxResult;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=transmux.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transmux.d.ts","sourceRoot":"","sources":["../../../../src/transmux/transmux.ts"],"names":[],"mappings":"AA+CA,MAAM,WAAW,cAAc;IAC3B,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAA;IACjC,uCAAuC;IACvC,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAA;IAClC,2CAA2C;IAC3C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC5B;AAWD;;;;GAIG;AACH,wBAAgB,gBAAgB;qBAUF,WAAW;EACxC"}
|