@shun-js/remotion-server 0.6.5 → 0.6.6
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/package.json +2 -2
- package/server/util/feishu.js +1 -1
- package/server/util/renderer.js +50 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shun-js/remotion-server",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "remotion.cool server",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "uikoo9 <uikoo9@qq.com>",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"access": "public",
|
|
32
32
|
"registry": "https://registry.npmjs.org/"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "326e09eaf91c306ba1fc1cc128659fdfeeb14d0d"
|
|
35
35
|
}
|
package/server/util/feishu.js
CHANGED
package/server/util/renderer.js
CHANGED
|
@@ -11,6 +11,51 @@ const Logger = require('qiao-log');
|
|
|
11
11
|
const logOptions = require('../log-options.js')();
|
|
12
12
|
const logger = Logger(logOptions);
|
|
13
13
|
|
|
14
|
+
// 浏览器配置 - 使用固定的全局路径,避免每次重新下载
|
|
15
|
+
const BROWSER_EXECUTABLE_PATH = path.join(
|
|
16
|
+
'/home/ubuntu/remotions/browser',
|
|
17
|
+
'chrome-headless-shell',
|
|
18
|
+
'linux-arm64',
|
|
19
|
+
'chrome-headless-shell-linux-arm64',
|
|
20
|
+
'headless_shell',
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 初始化浏览器 - 如果全局浏览器不存在,从 node_modules 复制
|
|
25
|
+
*/
|
|
26
|
+
function ensureBrowserExists() {
|
|
27
|
+
const methodName = 'ensureBrowserExists';
|
|
28
|
+
|
|
29
|
+
// 如果全局浏览器已存在,直接返回
|
|
30
|
+
if (fs.existsSync(BROWSER_EXECUTABLE_PATH)) {
|
|
31
|
+
logger.info(methodName, 'Browser already exists at:', BROWSER_EXECUTABLE_PATH);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
logger.info(methodName, 'Global browser not found, attempting to copy from node_modules...');
|
|
36
|
+
|
|
37
|
+
// 查找 node_modules 中的浏览器
|
|
38
|
+
const nodeModulesBrowserPath = path.join(__dirname, '..', '..', 'node_modules', '.remotion', 'chrome-headless-shell');
|
|
39
|
+
|
|
40
|
+
if (fs.existsSync(nodeModulesBrowserPath)) {
|
|
41
|
+
// 创建目标目录
|
|
42
|
+
const globalBrowserDir = path.join('/home/ubuntu/remotions/browser');
|
|
43
|
+
fs.mkdirSync(globalBrowserDir, { recursive: true });
|
|
44
|
+
|
|
45
|
+
// 复制浏览器文件
|
|
46
|
+
logger.info(methodName, 'Copying browser from:', nodeModulesBrowserPath);
|
|
47
|
+
logger.info(methodName, 'Copying browser to:', globalBrowserDir);
|
|
48
|
+
|
|
49
|
+
fs.cpSync(nodeModulesBrowserPath, path.join(globalBrowserDir, 'chrome-headless-shell'), {
|
|
50
|
+
recursive: true,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
logger.info(methodName, 'Browser copied successfully to:', BROWSER_EXECUTABLE_PATH);
|
|
54
|
+
} else {
|
|
55
|
+
logger.warn(methodName, 'Browser not found in node_modules, will download on first use');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
14
59
|
/**
|
|
15
60
|
* 渲染 Remotion 视频
|
|
16
61
|
* @param {Object} options
|
|
@@ -28,6 +73,9 @@ exports.renderVideo = async ({ sourceCode, outputPath, width, height, fps }) =>
|
|
|
28
73
|
const entryPoint = path.join(tempDir, 'src', 'Root.jsx');
|
|
29
74
|
|
|
30
75
|
try {
|
|
76
|
+
// 0. 确保浏览器存在(首次运行时自动复制到全局目录)
|
|
77
|
+
ensureBrowserExists();
|
|
78
|
+
|
|
31
79
|
// 1. 创建临时项目结构
|
|
32
80
|
fs.mkdirSync(path.join(tempDir, 'src'), { recursive: true });
|
|
33
81
|
|
|
@@ -68,6 +116,7 @@ module.exports = {
|
|
|
68
116
|
serveUrl: bundleLocation,
|
|
69
117
|
id: 'MyComposition', // 默认 composition ID
|
|
70
118
|
inputProps: {},
|
|
119
|
+
browserExecutable: fs.existsSync(BROWSER_EXECUTABLE_PATH) ? BROWSER_EXECUTABLE_PATH : undefined,
|
|
71
120
|
});
|
|
72
121
|
|
|
73
122
|
// 7. 渲染视频
|
|
@@ -84,6 +133,7 @@ module.exports = {
|
|
|
84
133
|
codec: 'h264',
|
|
85
134
|
outputLocation: outputPath,
|
|
86
135
|
inputProps: {},
|
|
136
|
+
browserExecutable: fs.existsSync(BROWSER_EXECUTABLE_PATH) ? BROWSER_EXECUTABLE_PATH : undefined,
|
|
87
137
|
onProgress: ({ progress }) => {
|
|
88
138
|
if (progress % 0.1 < 0.01) {
|
|
89
139
|
// 每10%打印一次
|