Skip to content

Commit a9ec63b

Browse files
committed
reverted to web demux fork
1 parent eff3cc9 commit a9ec63b

File tree

10 files changed

+592
-15
lines changed

10 files changed

+592
-15
lines changed

package-lock.json

Lines changed: 1 addition & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
"vitest-canvas-mock": "^0.3.3"
4747
},
4848
"dependencies": {
49-
"mp4-muxer": "^5.1.3",
50-
"web-demuxer": "1.0.5"
49+
"mp4-muxer": "^5.1.3"
5150
},
5251
"peerDependencies": {
5352
"pixi-filters": ">=6.0.0",
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* c8 ignore start */
2+
import type { WebAVPacket, WebAVStream } from './types';
3+
4+
let Module: any; // TODO: rm any
5+
6+
self.postMessage({
7+
type: 'FFmpegWorkerLoaded',
8+
});
9+
10+
self.addEventListener('message', async function (e) {
11+
const { type, data = {}, msgId } = e.data;
12+
13+
try {
14+
if (type === 'LoadWASM') {
15+
const { wasmLoaderPath } = data || {};
16+
17+
const ModuleLoader = await import(/* @vite-ignore */ wasmLoaderPath);
18+
Module = await ModuleLoader.default();
19+
} else if (type === 'GetAVStream') {
20+
const { file, streamType, streamIndex } = data;
21+
const result = Module.getAVStream(file, streamType, streamIndex);
22+
23+
self.postMessage(
24+
{
25+
type,
26+
msgId,
27+
result,
28+
},
29+
[result.codecpar.extradata.buffer],
30+
);
31+
} else if (type === 'GetAVStreams') {
32+
const { file } = data;
33+
const result = Module.getAVStreams(file);
34+
35+
self.postMessage(
36+
{
37+
type,
38+
msgId,
39+
result,
40+
},
41+
result.map((stream: WebAVStream) => stream.codecpar.extradata.buffer),
42+
);
43+
} else if (type === 'GetAVPacket') {
44+
const { file, time, streamType, streamIndex } = data;
45+
const result = Module.getAVPacket(file, time, streamType, streamIndex);
46+
47+
self.postMessage(
48+
{
49+
type,
50+
msgId,
51+
result,
52+
},
53+
[result.data.buffer],
54+
);
55+
} else if (type === 'GetAVPackets') {
56+
const { file, time } = data;
57+
const result = Module.getAVPackets(file, time);
58+
59+
self.postMessage(
60+
{
61+
type,
62+
msgId,
63+
result,
64+
},
65+
result.map((packet: WebAVPacket) => packet.data.buffer),
66+
);
67+
} else if (type === 'ReadAVPacket') {
68+
const { file, start, end, streamType, streamIndex } = data;
69+
const result = Module.readAVPacket(msgId, file, start, end, streamType, streamIndex);
70+
71+
self.postMessage({
72+
type,
73+
msgId,
74+
result,
75+
});
76+
}
77+
} catch (e) {
78+
self.postMessage({
79+
type,
80+
msgId,
81+
errMsg: e instanceof Error ? e.message : 'Unknown Error',
82+
});
83+
}
84+
});

src/clips/video/demuxer/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type { WebAVStream, WebAVPacket, WebAVCodecParameters } from './types';
2+
export { AVMediaType } from './types';
3+
export { WebDemuxer as Demuxer } from './web-demuxer';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* c8 ignore start */
2+
/**
3+
* sync with ffmpeg libavutil/avutil.h
4+
*/
5+
export enum AVMediaType {
6+
AVMEDIA_TYPE_UNKNOWN = -1, ///< Usually treated as AVMEDIA_TYPE_DATA
7+
AVMEDIA_TYPE_VIDEO,
8+
AVMEDIA_TYPE_AUDIO,
9+
AVMEDIA_TYPE_DATA, ///< Opaque data information usually continuous
10+
AVMEDIA_TYPE_SUBTITLE,
11+
AVMEDIA_TYPE_ATTACHMENT, ///< Opaque data information usually sparse
12+
AVMEDIA_TYPE_NB,
13+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* c8 ignore start */
2+
/**
3+
* sync with web-demuxer.h
4+
*/
5+
import type { AVMediaType } from './avutil';
6+
7+
export interface WebAVCodecParameters {
8+
codec_type: AVMediaType;
9+
codec_id: number;
10+
codec_string: string;
11+
format: number;
12+
profile: number;
13+
level: number;
14+
width: number;
15+
height: number;
16+
channels: number;
17+
sample_rate: number;
18+
extradata_size: number;
19+
extradata: Uint8Array;
20+
}
21+
22+
export interface WebAVStream {
23+
index: number;
24+
id: number;
25+
start_time: number;
26+
duration: number;
27+
nb_frames: number;
28+
codecpar: WebAVCodecParameters;
29+
}
30+
31+
export interface WebAVPacket {
32+
keyframe: 0 | 1;
33+
timestamp: number;
34+
duration: number;
35+
size: number;
36+
data: Uint8Array;
37+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* c8 ignore start */
2+
import type { AVMediaType } from './avutil';
3+
4+
export enum FFMpegWorkerMessageType {
5+
FFmpegWorkerLoaded = 'FFmpegWorkerLoaded',
6+
WASMRuntimeInitialized = 'WASMRuntimeInitialized',
7+
LoadWASM = 'LoadWASM',
8+
GetAVPacket = 'GetAVPacket',
9+
GetAVPackets = 'GetAVPackets',
10+
GetAVStream = 'GetAVStream',
11+
GetAVStreams = 'GetAVStreams',
12+
ReadAVPacket = 'ReadAVPacket',
13+
AVPacketStream = 'AVPacketStream',
14+
ReadNextAVPacket = 'ReadNextAVPacket',
15+
StopReadAVPacket = 'StopReadAVPacket',
16+
}
17+
18+
export type FFMpegWorkerMessageData =
19+
| GetAVPacketMessageData
20+
| GetAVPacketsMessageData
21+
| GetAVStreamMessageData
22+
| GetAVStreamsMessageData
23+
| ReadAVPacketMessageData
24+
| LoadWASMMessageData;
25+
26+
export interface GetAVStreamMessageData {
27+
file: File;
28+
streamType: AVMediaType;
29+
streamIndex: number;
30+
}
31+
32+
export interface GetAVStreamsMessageData {
33+
file: File;
34+
}
35+
36+
export interface GetAVPacketMessageData {
37+
file: File;
38+
time: number;
39+
streamType: AVMediaType;
40+
streamIndex: number;
41+
}
42+
43+
export interface GetAVPacketsMessageData {
44+
file: File;
45+
time: number;
46+
}
47+
48+
export interface ReadAVPacketMessageData {
49+
file: File;
50+
start: number;
51+
end: number;
52+
streamType: AVMediaType;
53+
streamIndex: number;
54+
}
55+
56+
export interface LoadWASMMessageData {
57+
wasmLoaderPath: string;
58+
}
59+
60+
export interface FFMpegWorkerMessage {
61+
type: FFMpegWorkerMessageType;
62+
data: FFMpegWorkerMessageData;
63+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './avutil';
2+
export * from './ffmpeg-worker-message';
3+
export * from './demuxer';

0 commit comments

Comments
 (0)