Skip to content

Commit

Permalink
Merge branch 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinlic committed Dec 24, 2023
2 parents bbd0b63 + 1c03bad commit 1f52627
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 20 deletions.
10 changes: 5 additions & 5 deletions api/ChunkVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default class ChunkVideo extends VideoChunk {
async #synthesize() {
const page = await this.#acquirePage();
try {
const { url, content, width, height, fps, startTime, duration, pageWaitForOptions, pageViewport = {}, videoDecoderHardwareAcceleration } = this;
const { url, content, width, height, pageWaitForOptions, pageViewport = {} } = this;
// 监听页面实例发生的某些内部错误
page.on("error", err => this._emitError("Page error:\n" + err.stack));
// 监听页面是否崩溃,当内存不足或过载时可能会崩溃
Expand Down Expand Up @@ -210,10 +210,10 @@ export default class ChunkVideo extends VideoChunk {
page.on("frame", buffer => this.input(buffer));
// 启动捕获
await page.startScreencast({
fps,
startTime,
duration,
videoDecoderHardwareAcceleration,
fps: this.fps,
startTime: this.startTime,
duration: this.duration,
videoDecoderHardwareAcceleration: this.videoDecoderHardwareAcceleration,
autostart: this.autostartRender
});
// 监听并等待录制完成
Expand Down
10 changes: 5 additions & 5 deletions api/SingleVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default class SingleVideo extends Synthesizer {
async #synthesize() {
const page = await this.#acquirePage();
try {
const { url, content, width, height, fps, startTime, duration, pageWaitForOptions, pageViewport = {}, videoDecoderHardwareAcceleration } = this;
const { url, content, width, height, pageWaitForOptions, pageViewport = {} } = this;
// 监听页面实例发生的某些内部错误
page.on("error", err => this._emitError("Page error:\n" + err.stack));
// 监听页面是否崩溃,当内存不足或过载时可能会崩溃
Expand Down Expand Up @@ -202,10 +202,10 @@ export default class SingleVideo extends Synthesizer {
page.on("frame", buffer => this.input(buffer));
// 启动捕获
await page.startScreencast({
fps,
startTime,
duration,
videoDecoderHardwareAcceleration,
fps: this.fps,
startTime: this.startTime,
duration: this.duration,
videoDecoderHardwareAcceleration: this.videoDecoderHardwareAcceleration,
autostart: this.autostartRender
});
// 监听并等待录制完成
Expand Down
29 changes: 28 additions & 1 deletion api/WebVideoCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,34 @@ export default class WebVideoCreator {
/**
* 配置引擎
*
* @param {globalConfig} config - 配置对象
* @param {Object} config - 配置对象
* @param {string} config.mp4Encoder - 全局MP4格式的视频编码器,默认使用libx264软编码器,建议根据您的硬件选用合适的硬编码器加速合成
* @param {string} config.webmEncoder - 全局WEBM格式的视频编码器,默认使用libvpx软编码器,建议根据您的硬件选用合适的硬编码器加速合成
* @param {string} config.audioEncoder - 全局音频编码器,建议采用默认的aac编码器
* @param {boolean} config.browserUseGPU - 浏览器GPU加速开关,建议开启提高渲染性能,如果您没有GPU设备或遭遇了诡异的渲染问题则可以关闭它
* @param {boolean} config.browserUseAngle - 浏览器是否使用Angle作为渲染后端,建议开启增强渲染跨平台兼容性和性能
* @param {string} config.browserExecutablePath - 浏览器可执行文件路径,设置后将禁用内部的浏览器,建议您默认使用内部的浏览器以确保功能完整性
* @param {number} config.numBrowserMin - 资源池可并行的最小浏览器实例数量
* @param {number} config.numBrowserMax - 资源池可并行的最大浏览器实例数量
* @param {number} config.numPageMin - 浏览器实例可并行的最小页面实例数量
* @param {number} conifg.numPageMax - 浏览器实例可并行的最大页面实例数量
* @param {boolean} config.debug - 开启后将输出一些WVC的调试日志
* @param {boolean} config.browserDebug - 浏览器Debug开关,开启后将输出浏览器的运行日志,如果您想看页面的日志,请设置视频参数的consoleLog为true,而不是这个
* @param {boolean} config.ffmpegDebug - FFmpeg Debug开关,开启后将输出每一条执行的ffmpeg命令
* @param {boolean} config.allowUnsafeContext - 是否允许不安全的上下文,默认禁用,开启后能够导航到不安全的URL,但由于不安全上下文限制,将无法在页面中使用动态图像和内嵌视频
* @param {boolean} config.compatibleRenderingMode - 兼容渲染模式,如果您使用MacOS请开启他,这将导致渲染效率降低40%,启用后将禁用HeadlessExperimental.beginFrame API调用改为普通的Page.screenshot
* @param {string} config.browserVersion - 指定WVC使用的Chrome浏览器版本
* @param {boolean} config.browserHeadless - 浏览器无头开关,建议保持开启,如果关闭请确保开启兼容渲染模式否则无法渲染,仅用于调试画面
* @param {boolean} config.browserFrameRateLimit - 浏览器帧率限制开关,默认开启,关闭帧率限制可以提高渲染效率并支持高于60fps的动画,但这会关闭GPU垂直同步可能导致画面撕裂或其它问题
* @param {string} config.ffmpegExecutablePath - ffmpeg可执行文件路径,设置后将禁用内部的ffmpeg-static,建议您默认使用内部的FFmpeg以确保功能完整性
* @param {string} conifg.ffprobeExecutablePath - ffprobe可执行文件路径,设置后将禁用内部的ffprobe-static,建议您默认使用内部的ffprobe以确保功能完整性
* @param {string} config.frameFormat - 帧图格式(jpeg/png),建议使用jpeg,png捕获较为耗时
* @param {number} config.frameQuality - 捕获帧图质量(0-100),仅frameFormat为jpeg时有效
* @param {number} config.beginFrameTimeout - BeginFrame捕获图像超时时间(毫秒)
* @param {boolean} config.browserDisableDevShm - 是否禁用浏览器使用共享内存,当/dev/shm分区较小时建议开启此选项
* @param {number} config.browserLaunchTimeout - 浏览器启动超时时间(毫秒),设置等待浏览器启动超时时间
* @param {number} config.browserProtocolTimeout - 浏览器协议通信超时时间(毫秒),设置CDP协议通信超时时间
* @param {string} config.userAgent - 访问页面时的用户UA
*/
config(config = {}) {
for (let key in globalConfig) {
Expand Down
1 change: 1 addition & 0 deletions core/Synthesizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export default class Synthesizer extends EventEmitter {
assert(this.isReady(), "Synthesizer status is not READY, please reset the synthesizer: synthesizer.reset()");
this.#setState(Synthesizer.STATE.SYNTHESIZING);
this._startupTime = _.defaultTo(this._startupTime, performance.now());
this._targetFrameCount = util.durationToFrameCount(this.duration, this.fps);
(async () => {
await fs.ensureDir(path.dirname(this.outputPath));
await fs.ensureDir(this.tmpDirPath);
Expand Down
20 changes: 12 additions & 8 deletions lib/global-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default {
* 浏览器Debug开关
*
* 开启后将输出浏览器的运行日志
* 如果你想看页面的日志,请设置视频参数的consoleLog为true,而不是这个
* 如果您想看页面的日志,请设置视频参数的consoleLog为true,而不是这个
*
* @type {boolean}
*/
Expand Down Expand Up @@ -88,6 +88,8 @@ export default {
* 浏览器是否使用Angle作为渲染后端
*
* 建议开启增强渲染跨平台兼容性和性能
*
* @type {boolean}
*/
browserUseAngle: true,

Expand All @@ -112,7 +114,7 @@ export default {
*
* 设置等待浏览器启动超时时间
*
* @type {string}
* @type {number}
*/
browserLaunchTimeout: 30000,

Expand All @@ -121,7 +123,7 @@ export default {
*
* 设置CDP协议通信超时时间
*
* @type {string}
* @type {number}
*/
browserProtocolTimeout: 180000,

Expand All @@ -147,42 +149,44 @@ export default {
compatibleRenderingMode: false,

/**
* 资源池最小浏览器实例数量
* 资源池可并行的最小浏览器实例数量
*
* @type {number}
*/
numBrowserMin: 1,

/**
* 资源池最大浏览器实例数量
* 资源池可并行的最大浏览器实例数量
*
* @type {number}
*/
numBrowserMax: 5,

/**
* 浏览器实例最小页面实例数量
* 浏览器实例可并行的最小页面实例数量
*
* @type {number}
*/
numPageMin: 1,

/**
* 浏览器实例最大页面实例数量
* 浏览器实例可并行的最大页面实例数量
*
* @type {number}
*/
numPageMax: 5,

/**
* 访问页面时的用户UA
*
* @type {string}
*/
userAgent: null,

/**
* 捕获帧图质量(0-100)
*
* 仅jpeg有效
* 仅frameFormat为jpeg时有效
*
* @type {number}
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web-video-creator",
"version": "0.0.31",
"version": "0.0.32",
"description": "A framework for creating videos based on Node.js + Puppeteer + FFmpeg.",
"type": "module",
"main": "index.js",
Expand Down

0 comments on commit 1f52627

Please sign in to comment.