libav-wasm 0.1.10 → 0.3.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/README.md CHANGED
@@ -1,3 +1,61 @@
1
+ # LibAV WASM
2
+
3
+ This library can be used to remux from MKV -> MP4, it could technically do any remux but i haven't had the need for it, create an issue if you'd like it.
4
+
5
+ [src/test.ts](https://github.com/Banou26/libav-wasm/blob/main/src/test.ts)
6
+ Contains a full example of a MKV video player
7
+
8
+ Basic usage
9
+ ```ts
10
+ const remuxer = await makeRemuxer({
11
+ // the path at which the wasm file is getting served
12
+ publicPath: new URL('/dist/', new URL(import.meta.url).origin).toString(),
13
+ // url of the worker file of libavWASM
14
+ workerUrl: new URL('../build/worker.js', import.meta.url).toString(),
15
+ // reads are done in 2.5mb chunks
16
+ bufferSize: 2_500_000,
17
+ // byte length of the video file
18
+ length: contentLength,
19
+ // fetch returning a ReadableStream
20
+ getStream: async (offset, size) =>
21
+ fetch(
22
+ VIDEO_URL,
23
+ {
24
+ headers: {
25
+ Range: `bytes=${offset}-${size ? Math.min(offset + size, contentLength) - 1 : ''}`
26
+ }
27
+ }
28
+ ).then(res => res.body)
29
+ ,
30
+ // callback where you'll receive the subtitle chunks
31
+ subtitle: (title, language, subtitle) => {
32
+ // console.log('SUBTITLE HEADER', title, language, subtitle)
33
+ },
34
+ // callback where you'll receive the attachments
35
+ attachment: (filename: string, mimetype: string, buffer: ArrayBuffer) => {
36
+ // console.log('attachment', filename, mimetype, buffer)
37
+ }
38
+ })
39
+
40
+ // Returns a chunk that looks like {
41
+ // isHeader: boolean,
42
+ // offset: number,
43
+ // buffer: Uint8Array,
44
+ // pos: number,
45
+ // pts: number, // timestamp
46
+ // duration: number
47
+ // }
48
+ // buffer can be appended to the MediaSource API(MSE API)
49
+ const chunk = await remuxer.read()
50
+
51
+ // allows you to seek to timestamp and start reading from there
52
+ await remuxer.seek(number)
53
+
54
+ await remuxer.read()
55
+ ```
56
+
57
+
58
+
1
59
  ## Intellisense
2
60
  To have C++ autocompletion, put a ffmpeg repo clone folder in the root
3
61
  `git clone https://github.com/FFmpeg/FFmpeg` & `git clone https://github.com/emscripten-core/emscripten`
@@ -10,8 +68,5 @@ To have C++ autocompletion, put a ffmpeg repo clone folder in the root
10
68
  - Thumbnail extraction
11
69
 
12
70
 
13
-
14
-
15
-
16
71
  <!-- https://www.ffmpeg.org/doxygen/trunk/remuxing_8c-example.html -->
17
72
  <!-- https://github.com/leandromoreira/ffmpeg-libav-tutorial -->
package/build/index.d.ts CHANGED
@@ -1,23 +1,12 @@
1
- import { SEEK_FLAG, SEEK_WHENCE_FLAG } from './utils';
2
- export { SEEK_FLAG, SEEK_WHENCE_FLAG };
3
1
  export type MakeTransmuxerOptions = {
4
2
  /** Path that will be used to locate the .wasm file imported from the worker */
5
3
  publicPath: string;
6
4
  /** Path that will be used to locate the javascript worker file */
7
5
  workerUrl: string;
8
6
  workerOptions?: WorkerOptions;
9
- read: (offset: number, size: number) => Promise<ArrayBuffer>;
10
- seek: (currentOffset: number, offset: number, whence: SEEK_WHENCE_FLAG) => Promise<number>;
7
+ getStream: (offset: number, size?: number) => Promise<ReadableStream<Uint8Array>>;
11
8
  subtitle: (title: string, language: string, data: string) => Promise<void> | void;
12
9
  attachment: (filename: string, mimetype: string, buffer: ArrayBuffer) => Promise<void> | void;
13
- write: (params: {
14
- isHeader: boolean;
15
- offset: number;
16
- buffer: Uint8Array;
17
- pos: number;
18
- pts: number;
19
- duration: number;
20
- }) => Promise<void> | void;
21
10
  length: number;
22
11
  bufferSize: number;
23
12
  };
@@ -40,6 +29,8 @@ export type MediaInfo = {
40
29
  formatName: string;
41
30
  mimeType: string;
42
31
  duration: number;
32
+ video_mime_type: string;
33
+ audio_mime_type: string;
43
34
  };
44
35
  export type Chunk = {
45
36
  isHeader: boolean;
@@ -49,10 +40,10 @@ export type Chunk = {
49
40
  duration: number;
50
41
  pos: number;
51
42
  };
52
- export declare const makeTransmuxer: ({ publicPath, workerUrl, workerOptions, read: _read, seek: _seek, write: _write, attachment, subtitle: _subtitle, length, bufferSize }: MakeTransmuxerOptions) => Promise<{
53
- init: () => Promise<void>;
54
- destroy: (destroyWorker?: boolean) => Promise<void> | undefined;
55
- process: (timeToProcess: number) => Promise<Chunk[]>;
43
+ export declare const makeRemuxer: ({ publicPath, workerUrl, workerOptions, randomRead: _randomRead, getStream: _getStream, write: _write, attachment, subtitle: _subtitle, length, bufferSize }: MakeTransmuxerOptions) => Promise<{
44
+ init: () => Promise<Chunk | undefined>;
45
+ destroy: (destroyWorker?: boolean) => void;
46
+ read: () => Promise<Chunk | undefined>;
56
47
  seek: (time: number) => Promise<void>;
57
48
  getInfo: () => Promise<{
58
49
  input: MediaInfo;