-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerateVideoAnalysis.js
More file actions
66 lines (54 loc) · 1.86 KB
/
generateVideoAnalysis.js
File metadata and controls
66 lines (54 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const processVideoScript = require('./src/processVideoScript');
const fs = require('fs-extra');
const path = require('path');
const { withRetry } = require('./src/retry')
const dotenv = require('dotenv');
dotenv.config();
const videoDir = process.env.PROJECT_ROOT + '/data/sourceVideo/';
/**
* 判断文件是否为视频文件
* @param {string} filename 文件名
* @returns {boolean} 是否为视频文件
*/
function isVideoFile(filename) {
const videoExtensions = ['.mp4', '.avi', '.mov', '.wmv', '.mkv', '.flv', '.webm'];
const ext = path.extname(filename).toLowerCase();
return videoExtensions.includes(ext);
}
/**
* 主函数:处理目录中的所有视频文件
*/
async function main() {
try {
// 确保目录存在
if (!fs.existsSync(videoDir)) {
console.error(`错误: 视频目录不存在: ${videoDir}`);
process.exit(1);
}
// 读取目录中的所有文件
const files = await fs.readdir(videoDir);
// 过滤出视频文件
const videoFiles = files.filter(file => isVideoFile(file));
if (videoFiles.length === 0) {
console.log(`目录 ${videoDir} 中没有找到视频文件`);
return;
}
console.log(`在 ${videoDir} 目录中找到 ${videoFiles.length} 个视频文件`);
// 依次处理每个视频文件
for (const videoFile of videoFiles) {
const videoPath = path.join(videoDir, videoFile);
console.log(`处理视频文件: ${videoPath}`);
await withRetry(async () => {
await processVideoScript(videoPath);
},{errorPrefix: 'Gemini处理错误:'})
console.log(`完成处理: ${videoFile}`);
console.log('----------------------------');
}
console.log('所有视频处理完成!');
} catch (error) {
console.error('处理视频时出错:', error);
process.exit(1);
}
}
// 执行主函数
main();