Constructor
new Recorder(_optionsopt)
- Source:
Name | Type | Default | Description |
---|---|---|---|
_options ? |
RecorderOptions |
{}
|
Example
import Recorder, { OnRequestCapture } from "@scenjs/recorder";
import Scene from "scenejs";
const scene = new Scene();
const recorder = new Recorder();
recorder.setAnimator(scene);
recorder.setCapturing("png", (e: OnRequestCapture) => {
scene.setTime(e.time, true);
// html to image
return htmlToImage(element);
});
recorder.record().then(data => {
const url = URL.createObjectURL(new Blob(
[data.buffer],
{ type: 'video/mp4' },
));
video.setAttribute("src", url);
recorder.destroy();
});
Methods
setFetchFile(fetchFile)
- Source:
Set up a function to import files. Defaults to fetchData from `@ffmpeg/ffmpeg`
Name | Type | Description |
---|---|---|
fetchFile |
(data: FileType) => Promise<Uint8Array | null> |
setCapturing(imageType, capturing)
- Source:
Set the function to get the image to be captured per frame.
Name | Type | Description |
---|---|---|
imageType |
"jpeg" | "png" | image extension of the file |
capturing |
(e: OnRequestCapture) => Promise<FileType> | FileType | A function that returns the image to be captured per frame. |
setAnimator(animator)
- Source:
Set the animator to record.
Name | Type | Description |
---|---|---|
animator |
AnimatorLike | Partial<AnimatorOptions> |
(async) recordMedia(mediaInfo, optionsopt) → {Promise<Uint8Array>}
Start audio processing.
Name | Type | Description |
---|---|---|
mediaInfo |
MediaSceneInfo | media info |
options ? |
RenderMediaInfoOptions | media info options |
Returns:
- Type
- Promise<Uint8Array>
(async) record(optionsopt) → {Promise<Uint8Array>}
Start capturing and video processing.
Name | Type | Default | Description |
---|---|---|---|
options ? |
RenderVideoOptions & RecordInfoOptions |
{}
|
record options |
Returns:
- Type
- Promise<Uint8Array>
getRecordInfo(options)
Get the information to be recorded through options.
Name | Type | Description |
---|---|---|
options |
RecordInfoOptions |
getAudioFile() → {Uint8Array}
Get the result of audio processing.
Returns:
- Type
- Uint8Array
exit()
Quit ffmpeg.
destroy()
Remove the recorder and ffmpeg instance.
trigger<Name extends keyof Events>(eventName, paramopt) → {boolean}
- Source:
- Overrides:
Fires an event to call listeners.
Name | Type | Default | Description |
---|---|---|---|
eventName |
Name | ... | Event name | |
param ? |
TargetParam<any> | ... |
{}
|
Event parameter |
trigger<Name extends keyof Events, Param = Events[Name]>(eventName) → {boolean}
Name | Type | Description |
---|---|---|
eventName |
extends TargetParam<Param> ? Name : never |
trigger<Name extends keyof Events, Param = Events[Name]>(eventName, param) → {boolean}
Name | Type | Description |
---|---|---|
eventName |
Name | |
param |
TargetParam<Param> |
Example
import EventEmitter from "@scena/event-emitter";
const emitter = new EventEmitter();
emitter.on("a", e => {
});
emitter.emit("a", {
a: 1,
});
Returns:
If false, stop the event.
- Type
- boolean
once<Name extends keyof Events & string, Param = Events[Name]>(eventName, listeneropt) → {Promise<OnEvent<Param, this>>}
- Source:
- Inherited From:
Add a disposable listener and Use promise to the registered event.
Name | Type | Description |
---|---|---|
eventName |
Name | Name of the event to be added |
listener ? |
EventListener<Param, this> | disposable listener function of the event to be added |
Example
import EventEmitter from "@scena/event-emitter";
cosnt emitter = new EventEmitter();
// Add a disposable listener in "a" event
emitter.once("a", () => {
});
// Use Promise
emitter.once("a").then(e => {
});
Returns:
- Type
- Promise<OnEvent<Param, this>>
on(eventName, listeneropt) → {this}
- Source:
- Inherited From:
Add a listener to the registered event.
Name | Type | Description |
---|---|---|
eventName |
string | object | ... | Name of the event to be added |
listener ? |
EventListener<Events[any], this> | ... | listener function of the event to be added |
on<Name extends keyof Events, Param = Events[Name]>(eventName, listener) → {this}
Name | Type | Description |
---|---|---|
eventName |
Name | |
listener |
EventListener<Param, this> |
on(events) → {this}
Name | Type | Description |
---|---|---|
events |
EventHash<Events, this> |
Example
import EventEmitter from "@scena/event-emitter";
cosnt emitter = new EventEmitter();
// Add listener in "a" event
emitter.on("a", () => {
});
// Add listeners
emitter.on({
a: () => {},
b: () => {},
});
Returns:
- Type
- this
off(eventNameopt, listeneropt) → {this}
- Source:
- Inherited From:
Remove listeners registered in the event target.
Name | Type | Description |
---|---|---|
eventName ? |
string | object | ... | Name of the event to be removed |
listener ? |
EventListener<Events[any], this> | ... | listener function of the event to be removed |
off<Name extends keyof Events, Param = Events[Name]>(eventName, listener) → {this}
Name | Type | Description |
---|---|---|
eventName ? |
Name | |
listener ? |
EventListener<Param, this> |
off(events) → {this}
Name | Type | Description |
---|---|---|
events |
EventHash<Events, this> |
Example
import EventEmitter from "@scena/event-emitter";
cosnt emitter = new EventEmitter();
// Remove all listeners.
emitter.off();
// Remove all listeners in "A" event.
emitter.off("a");
// Remove "listener" listener in "a" event.
emitter.off("a", listener);
Returns:
- Type
- this
emit(eventName, paramopt) → {boolean}
- Source:
- Inherited From:
Fires an event to call listeners.
Name | Type | Default | Description |
---|---|---|---|
eventName |
string | ... | Event name | |
param ? |
TargetParam<any> | ... |
{}
|
Event parameter |
emit<Name extends keyof Events, Param = Events[Name]>(eventName) → {boolean}
Name | Type | Description |
---|---|---|
eventName |
extends Param ? Name : never |
emit<Name extends keyof Events, Param = Events[Name]>(eventName, param) → {boolean}
Name | Type | Description |
---|---|---|
eventName |
Name | |
param |
TargetParam<Param> |
Example
import EventEmitter from "@scena/event-emitter";
const emitter = new EventEmitter();
emitter.on("a", e => {
});
emitter.emit("a", {
a: 1,
});
Returns:
If false, stop the event.
- Type
- boolean
Type Definitions
FileType
- Source:
Type:
- string | Buffer | File | Blob | null
OnCapture
- Source:
Properties:
Type:
- TSInterface
OnCaptureStart
- Source:
Properties:
Type:
- TSInterface
OnProcess
- Source:
Properties:
Type:
- TSInterface
OnProcessAudioStart
- Source:
Properties:
Type:
- TSInterface
OnRequestCapture
- Source:
Properties:
Type:
- TSInterface
RecorderOptions
- Source:
Properties:
Type:
- TSInterface
RecordInfoOptions
- Source:
Properties:
iteration
optional
Default Value: 0
iteration?:
number
Input iterationCount of the Scene set by the user himself
Type:
- TSInterface
RenderMediaInfoOptions
- Source:
Properties:
Type:
- TSInterface
RenderVideoOptions
- Source:
Properties:
codec
optional
Default Value: "libx264"
codec?:
string
Codec to encode video If you don't set it up, it's the default (mp4: libx264, webm: libvpx-vp9)
bitrate
optional
Default Value: "4096k"
bitrate?:
string
Bitrate of video (the higher the bit rate, the clearer the video quality)
cpuUsed
optional
Default Value: 8
cpuUsed?:
number
Number of cpus to use for ffmpeg video or audio processing
Type:
- TSInterface
Events
capture
The event is fired when frame capturing is in progress.
Type | Description |
---|---|
Recorder.OnCapture | Parameters for the `capture` event |
captureEnd
The event is fired when capture ends.
captureStart
The event is fired when capture starts.
Type | Description |
---|---|
Recorder.OnCaptureStart | Parameters for the `captureStart` event |
processAudio
The event is fired when audio processing is in progress.
Type | Description |
---|---|
Recorder.OnProcess | Parameters for the `processAudio` event |
processAudioEnd
The event is fired when audio process ends.
processAudioStart
The event is fired when audio process starts.
Type | Description |
---|---|
Recorder.OnProcessAudioStart | Parameters for the `processAudioStart` event |
processVideo
The event is fired when frame video processing is in progress.
Type | Description |
---|---|
Recorder.OnProcess | Parameters for the `processVideo` event |
processVideoEnd
The event is fired when process video ends
processVideoStart
The event is fired when process video starts.
Type | Description |
---|---|
Recorder.OnProcessVideoStart | Parameters for the `processVideoStart` event |