Skip to content

Commit

Permalink
Merge pull request #334 from SPACEX-2022/origin_master
Browse files Browse the repository at this point in the history
feat: Add a transparent background configuration item
  • Loading branch information
drawcall committed Mar 29, 2023
2 parents 3a75e43 + 24b29dd commit c21bc6a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/en/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| fps | None | number (default 30) | Video frame rate |
| outputDir | dir | string | Video output path |
| cacheDir | None | string | Cache directory |
| transparent | None | boolean (default false) | Whether to enable transparent background (used to generate transparent channel video) |
| output | out | string | Output file name (not required, no need to fill in in FFCenter mode) |
| parallel | frames | number (default 5) | parallel rendering |
| highWaterMark | size | string (default 1mb) | node.js [highWaterMark](http://nodejs.cn/api/stream/buffering.html) |
Expand Down
1 change: 1 addition & 0 deletions docs/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| fps | rfps | number (默认30) | 视频帧频 |
| outputDir | dir | string | 视频输出路径 |
| cacheDir || string | 缓存目录 |
| transparent || boolean (默认false) | 是否启用透明背景(用于生成透明通道视频) |
| output | out | string | 输出文件名(非必须, 在FFCenter模式下不需要填写) |
| parallel | frames | number (默认5) | 并行渲染 |
| highWaterMark | size | string (默认1mb) | node.js [highWaterMark](http://nodejs.cn/api/stream/buffering.html) |
Expand Down
1 change: 1 addition & 0 deletions lib/conf/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Conf {
this.copyByDefaultVal(conf, 'antialias', false);
this.copyByDefaultVal(conf, 'audioLoop', true);
this.copyByDefaultVal(conf, 'ffmpeglog', false);
this.copyByDefaultVal(conf, 'transparent', false);
this.copyByDefaultVal(conf, 'ext', 'mp4');
this.copyByDefaultVal(conf, 'preset', 'medium');
this.copyByDefaultVal(conf, 'cacheFormat', 'raw');
Expand Down
18 changes: 13 additions & 5 deletions lib/creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,29 @@ class FFCreator extends FFCon {
this.resetSize();
const width = this.getConf('width');
const height = this.getConf('height');
const transparent = this.getConf('transparent');
const render = this.getConf('render');
const clarity = this.getConf('clarity');
const antialias = this.getConf('antialias');
const useGL = render !== 'canvas';
const key = `${this.type}_${render}`;
settings.PRECISION_FRAGMENT = `${clarity}p`;

const appOptions = {
useGL,
antialias,
};
// If set to transparent, override the default background color configuration
if (transparent) {
appOptions.transparent = true;
} else {
appOptions.backgroundColor = 0x000000;
}

const app = Pool.get(
key,
() =>
new Application(width, height, {
backgroundColor: 0x000000,
useGL,
antialias,
}),
new Application(width, height, appOptions),
);
app.renderer.resize(width, height);
this.display = app.stage;
Expand Down

0 comments on commit c21bc6a

Please sign in to comment.