-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
78 lines (64 loc) · 2.21 KB
/
index.js
File metadata and controls
78 lines (64 loc) · 2.21 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
67
68
69
70
71
72
73
74
75
'use strict';
const shell = require('shelljs');
const command = require('./lib/command')
let videoPath = 'video';
let distOriginPath = 'dist/origin';
let distTestPath = 'dist/test'
const getCropInfo=(path)=>{
return new Promise((resolve,reject)=>{
shell.exec(command.videoResolutionCommand(path),{silent:true},function (result,resolution){
let resolutionArray = resolution.split("x");
let width = resolutionArray[0];
let height = resolutionArray[1];
let startX = width/2-10;
let startY = height/2-10;
let crop = `20:20:${startX}:${startY}`
resolve(crop)
});
})
}
/**
* 获取视频帧数
* @param path
* @returns {Promise<any>}
*/
const getFrameCount=(path)=>{
return new Promise((resolve,reject)=>{
shell.exec(command.videoFrameCount(path),{silent:true},function (result,count){
resolve(count.replace('\n',''))
});
})
}
const exportFrameImages = (path,output,needResolution,selectFrame,crop)=>{
return new Promise((resolve,reject)=>{
let exportTest = command.exportFrameImage(path,output,needResolution,selectFrame,crop);
shell.exec(exportTest.replace("\n",""),{silent:true}, function (result,message) {
if(result==0){
resolve(`export ${path} frame images to ${output} success`)
}else{
resolve(`export ${path} frame images to ${output} failed ${message}`)
}
})
})
}
let startTime = Date.now();
(async ()=>{
let infoResults = await Promise.all([
getCropInfo(`${videoPath}/origin.mp4`),
getCropInfo(`${videoPath}/test.mp4`),
getFrameCount(`${videoPath}/origin.mp4`),
getFrameCount(`${videoPath}/test.mp4`)
]);
console.log(infoResults)
let originCrop = infoResults[0];
let testCrop = infoResults[1];
let originFrameCount = infoResults[2];
let testFrameCount = infoResults[3];
let useFrameCount = originFrameCount-testFrameCount;
let exprotResults = await Promise.all([
exportFrameImages(`${videoPath}/origin.mp4`,`${distOriginPath}/p%04d.bmp`,'100x100',null,originCrop),
exportFrameImages(`${videoPath}/test.mp4`,`${distTestPath}/${useFrameCount}-p%04d.bmp`,'100x100','eq(n,1)',testCrop)
])
console.log(exprotResults)
console.log('exprt use time:'+(Date.now()-startTime))
})();