-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mp4-muxer and move mp4-wasm to its own encoder
- Loading branch information
Showing
6 changed files
with
185 additions
and
102 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import MP4Wasm from "./mp4.embed.js"; // mp4-wasm | ||
|
||
import Encoder from "./Encoder.js"; | ||
|
||
let mp4wasm; | ||
|
||
class MP4WasmEncoder extends Encoder { | ||
static supportedExtensions = ["mp4"]; | ||
static supportedTargets = ["in-browser"]; | ||
|
||
static defaultOptions = { | ||
extension: MP4WasmEncoder.supportedExtensions[0], | ||
groupOfPictures: 20, | ||
flushFrequency: 10, | ||
}; | ||
|
||
get frameMethod() { | ||
return "bitmap"; | ||
} | ||
|
||
constructor(options) { | ||
super({ ...MP4WasmEncoder.defaultOptions, ...options }); | ||
} | ||
|
||
async init(options) { | ||
super.init(options); | ||
|
||
mp4wasm ||= await MP4Wasm(); // { wasmBinary } | ||
console.log(mp4wasm); | ||
|
||
this.encoder = mp4wasm.createWebCodecsEncoder({ | ||
// codec: "avc1.420034", // Baseline 4.2 | ||
codec: "avc1.4d0034", // Main 5.2 | ||
width: this.width, | ||
height: this.height, | ||
fps: this.frameRate, | ||
encoderOptions: { | ||
framerate: this.frameRate, | ||
...this.encoderOptions, | ||
}, | ||
}); | ||
} | ||
|
||
async encode(frame) { | ||
await this.encoder.addFrame(frame); | ||
} | ||
|
||
async stop() { | ||
let buffer = await this.encoder.end(); | ||
|
||
return buffer; | ||
} | ||
|
||
async dispose() { | ||
this.encoder = null; | ||
} | ||
} | ||
|
||
export default MP4WasmEncoder; |
Oops, something went wrong.