Skip to content

Commit 931ebb1

Browse files
committed
doc: improve video thumbnail generating
1 parent f70ce3c commit 931ebb1

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

test/integration/modules/videorecorder/client/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ try {
3030
let videoRecorder = new VideoRecorder("vizzuCanvas", (data) => {
3131
let a = document.createElement("a")
3232
a.setAttribute("href", data)
33-
a.setAttribute("download", testCasesPath.replace("/", "__") + "__" + testName + ".webm")
33+
a.setAttribute("download", testCasesPath.replaceAll("/", "___") + "___" + testName + ".webm")
3434
a.click()
3535
window.result = { result: "OK" };
3636
document.title = "Finished";

test/integration/modules/videorecorder/generate.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const yargs = require("yargs");
22
const path = require("path");
3+
const fs = require('fs');
34

45
const pLimitReady = import("p-limit");
56
const AggregateErrorReady = import("aggregate-error");
@@ -12,6 +13,22 @@ const TestCasesConfig = require("../../modules/integration-test/test-case/test-c
1213
const TestCases = require("../../modules/integration-test/test-case/test-cases.js");
1314

1415

16+
function checkFileExist(path, timeout = 5000)
17+
{
18+
let totalTime = 0;
19+
let checkTime = 100;
20+
return new Promise((resolve, reject) => {
21+
const timer = setInterval(function() {
22+
totalTime += checkTime;
23+
let fileExists = fs.existsSync(path);
24+
if (fileExists || totalTime >= timeout) {
25+
clearInterval(timer);
26+
resolve(fileExists);
27+
}
28+
}, checkTime);
29+
});
30+
}
31+
1532
class VideoRecorder {
1633

1734
#pLimit;
@@ -59,6 +76,9 @@ class VideoRecorder {
5976

6077
#runVideoRecorder() {
6178
return new Promise((resolve, reject) => {
79+
fs.rmSync("generated", {
80+
force: true, recursive: true
81+
});
6282
this.#testCasesReady.then(testCases => {
6383
this.#testCases = testCases;
6484
if (testCases.filteredTestCases.length > 0) {
@@ -88,6 +108,11 @@ class VideoRecorder {
88108
vizzuUrl = "/" + path.relative(TestEnv.getWorkspacePath(), vizzuUrl);
89109
}
90110
let suitePath = "/" + path.relative(TestEnv.getWorkspacePath(), TestEnv.getTestSuitePath());
111+
let downloadedFile = path.relative(suitePath, path.dirname(testCase.testFile)).replaceAll("/", "___") + "___" + path.basename(testCase.testName) + ".webm";
112+
fs.rmSync(downloadedFile, {
113+
force: true,
114+
});
115+
let outputFile = "generated/" + downloadedFile.replaceAll("___", "/");
91116
browserChrome.getUrl("http://127.0.0.1:" + String(this.#workspaceHostServerPort)
92117
+ suitePath + "/modules/videorecorder/client/index.html"
93118
+ "?testSuitePath=" + suitePath
@@ -106,7 +131,15 @@ class VideoRecorder {
106131
} else {
107132
console.log("ERROR: " + testCase.testName + " " + result.description);
108133
}
109-
return resolve(result);
134+
checkFileExist(downloadedFile).then((fileExists) => {
135+
if (fileExists) {
136+
fs.mkdirSync(path.dirname(outputFile), { recursive: true });
137+
fs.renameSync(downloadedFile, outputFile)
138+
return resolve(result);
139+
} else {
140+
return reject("TimeoutError: Waiting for file to be downloaded");
141+
}
142+
});
110143
})
111144
}).catch(err => {
112145
let errMsg = err.toString();

test/integration/modules/videorecorder/resize.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ const fs = require('fs');
44
const child_process = require('child_process');
55

66

7+
const getAllFiles = function(dirPath, arrayOfFiles) {
8+
files = fs.readdirSync(dirPath)
9+
10+
arrayOfFiles = arrayOfFiles || []
11+
12+
files.forEach(function(file) {
13+
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
14+
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles)
15+
} else {
16+
arrayOfFiles.push(path.join(dirPath, "/", file))
17+
}
18+
})
19+
20+
return arrayOfFiles
21+
}
22+
23+
724
try {
825
var argv = yargs
926
.usage('Usage: $0 [options]')
@@ -19,16 +36,18 @@ try {
1936
.default('s', 320)
2037
.argv;
2138

22-
fs.mkdirSync(__dirname + '/resized', { recursive: true });
23-
let files = fs.readdirSync(__dirname);
39+
fs.rmSync(__dirname + '/resized', { force: true, recursive: true });
40+
let files = getAllFiles(__dirname + '/generated')
2441
files.forEach(file => {
25-
if (!fs.lstatSync(__dirname + '/' + file).isDirectory()) {
42+
if (!fs.lstatSync(file).isDirectory()) {
2643
if (path.extname(file) == '.webm') {
44+
outfile = file.replace("generated", "resized")
45+
fs.mkdirSync(path.dirname(outfile), { recursive: true });
2746
child_process.execSync(
28-
`ffmpeg -i ${file} -vf scale=${argv.size.toString()}:-1 -ss 00:00.01 ${__dirname}/resized/${file}`);
29-
mp4file = file.replace('.webm', '.mp4');
47+
`ffmpeg -i ${file} -vf scale=${argv.size.toString()}:-1 -ss 00:00.01 ${outfile}`);
48+
mp4file = outfile.replace('.webm', '.mp4');
3049
child_process.execSync(
31-
`ffmpeg -i ${file} -vf scale=${argv.size.toString()}:-1 -ss 00:00.01 ${__dirname}/resized/${mp4file}`);
50+
`ffmpeg -i ${file} -vf scale=${argv.size.toString()}:-1 -ss 00:00.01 ${mp4file}`);
3251
}
3352
}
3453
});

0 commit comments

Comments
 (0)