diff --git a/source/Desktop.zip b/source/Desktop.zip new file mode 100644 index 0000000000000000000000000000000000000000..3dd08359f9a9dee1bf0ecc92da618df92106499b Binary files /dev/null and b/source/Desktop.zip differ diff --git a/source/ffmpeg-5.1-essentials_build.zip b/source/ffmpeg-5.1-essentials_build.zip new file mode 100644 index 0000000000000000000000000000000000000000..864e49124dc6292ef2e751266837dec9ca80c79d Binary files /dev/null and b/source/ffmpeg-5.1-essentials_build.zip differ diff --git a/src/consoleInput/README.md b/src/consoleInput/README.md new file mode 100644 index 0000000000000000000000000000000000000000..78c41cbe2c7b8af4b1c036d299c3b191e91f3756 --- /dev/null +++ b/src/consoleInput/README.md @@ -0,0 +1,28 @@ +## consoleInput + +### example +```javascript +const consoleInput = require('@jyeontu/console-input'); +const config = [ + { + name:'videoPath', + tip:'请输入视频路径(如./video/1.mp4):', + configTip:'视频路径: ' + }, + { + name:'saveFilePath', + tip:'请输入截图保存路径(如./img/): ', + configTip:'截图保存路径:' + }, + { + name:'cutNums', + tip:'请输入需要截取图片数量(如30),注意:数量应该小于视频时间秒数: ', + configTip:'截取图片数量:' + } +] +const test = new consoleInput(config); +let res = test.askInput(); +res.then(res=>{ + console.log(res); +}) +``` \ No newline at end of file diff --git a/src/consoleInput/consoleInput.js b/src/consoleInput/consoleInput.js new file mode 100644 index 0000000000000000000000000000000000000000..e1caa33dec38c9f7dd2da40699c4b24b88fc1055 --- /dev/null +++ b/src/consoleInput/consoleInput.js @@ -0,0 +1,72 @@ +const readline = require('readline'); + +var myConsole = (text,color='indigo') => { + const colorMap = { + black: "\033[30m " + text + " \033[0m", + red: "\033[31m " + text + " \033[0m", + green: "\033[32m " + text + " \033[0m", + yellow: "\033[33m " + text + " \033[0m", + blue: "\033[34m " + text + " \033[0m", + popurse: "\033[35m " + text + " \033[0m", + indigo: "\033[36m " + text + " \033[0m", + white: "\033[37m " + text + " \033[0m" + }; + console.log(colorMap[color]); +} + +class consoleInput{ + constructor(config = []){ + this.init(config); + } + init(config){ + this.config = config; + const inputVal = {}; + this.config.map(item=>{ + inputVal[item.name] = ''; + }); + this.inputVal = inputVal; + this.readline = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + this.question = this.rlPromisify(this.readline.question.bind(this.readline)); + } + rlPromisify(fn) { + return async (...args) => { + return new Promise(resolve => fn(...args, resolve)); + }; + }; + askForReset = async() => { + myConsole('≡'.repeat(50)); + myConsole('≡'.repeat(18) + ' 确认输入信息 ' + '≡'.repeat(18)); + myConsole('≡'.repeat(50)); + this.config.map(item=>{ + myConsole(item.configTip + this.inputVal[item.name],'popurse'); + }) + const res = await this.question('请确认输入信息(Y/N): '); + if(res.trim() == 'y' || res.trim() == 'Y'){ + this.readline.close(); + return this.inputVal; + }else if(res.trim() == 'n' || res.trim() == 'N'){ + myConsole('≡'.repeat(50)); + myConsole('≡'.repeat(20) + ' 重新输入 ' + '≡'.repeat(20)); + myConsole('≡'.repeat(50)); + return this.askInput(0); + }else{ + return this.askForReset(); + } + }; + askInput = async (ind = 0)=>{ + if(ind == this.config.length) return this.askForReset(); + const res = await this.question(this.config[ind].tip); + if(res.trim().length == 0) return this.askInput(ind); + else{ + this.inputVal[this.config[ind].name] = res.trim(); + return this.askInput(ind+1); + } + }; + +} + +// export default consoleInput; +module.exports = consoleInput; \ No newline at end of file diff --git a/src/consoleInput/index.js b/src/consoleInput/index.js new file mode 100644 index 0000000000000000000000000000000000000000..f8d29cdec1e57846a4ec5d9a3fa5482ad10192a3 --- /dev/null +++ b/src/consoleInput/index.js @@ -0,0 +1,25 @@ +const consoleInput = require('./consoleInput'); +// const config = [ +// { +// name:'videoPath', +// tip:'请输入视频路径(如./video/1.mp4):', +// configTip:'视频路径: ' +// }, +// { +// name:'saveFilePath', +// tip:'请输入截图保存路径(如./img/): ', +// configTip:'截图保存路径:' +// }, +// { +// name:'cutNums', +// tip:'请输入需要截取图片数量(如30),注意:数量应该小于视频时间秒数: ', +// configTip:'截取图片数量:' +// } +// ] +// const test = new consoleInput(config); +// let res = test.askInput(); +// res.then(res=>{ +// console.log(res); +// }) +// export default consoleInput; +module.exports = consoleInput; \ No newline at end of file diff --git a/src/consoleInput/package.json b/src/consoleInput/package.json new file mode 100644 index 0000000000000000000000000000000000000000..da0fa57d4f187887d4f460dc43b797afd5995863 --- /dev/null +++ b/src/consoleInput/package.json @@ -0,0 +1,17 @@ +{ + "name": "@jyeontu/console-input", + "version": "1.0.1", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "readline" + ], + "author": "jyeontu", + "license": "ISC", + "description": "node控制台输入配置", + "dependencies": { + "readline": "^1.3.0" + } +} diff --git a/src/getVideoFrame/README.md b/src/getVideoFrame/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c30b974afc20b35117bb4e55bcb8ec48ae7e3353 --- /dev/null +++ b/src/getVideoFrame/README.md @@ -0,0 +1,14 @@ +## getVideoImg +node + ffmpeg截取视频指定帧图片。 +### 准备 +#### 安装ffmpeg +首先我们应该要先在电脑上安装好ffmpeg。 +官方下载地址:[https://ffmpeg.org/download.html](https://ffmpeg.org/download.html)\ +也可以直接解压根目录下的source文件夹中的->**ffmpeg-5.1-essentials_build.zip**\ +下载后并配置好环境变量之后即可继续往下。 + +#### 依赖下载 +npm install + +#### 工具使用 +安装完依赖后可以直接执行`node index.js`,安装步骤操作即可。 \ No newline at end of file diff --git a/src/getVideoFrame/getVideoFrame.js b/src/getVideoFrame/getVideoFrame.js new file mode 100644 index 0000000000000000000000000000000000000000..236213eefe5cffa89d798a86199c5fe88b268794 --- /dev/null +++ b/src/getVideoFrame/getVideoFrame.js @@ -0,0 +1,70 @@ +const ffmpeg = require('ffmpeg'); +const path = require('path'); +const cp = require('child_process'); +const { getVideoDurationInSeconds } = require('get-video-duration'); + +const defaultConfig = [ + { + name:'videoPath', + tip:'请输入视频路径(如./video/1.mp4):', + configTip:'视频路径: ' + }, + { + name:'saveFilePath', + tip:'请输入截图保存路径(如./img/): ', + configTip:'截图保存路径:' + }, + { + name:'cutNums', + tip:'请输入需要截取图片数量(如30),注意:数量应该小于视频时间秒数: ', + configTip:'截取图片数量:' + } +]; + +const changTimeFormat = (seconds)=>{ + seconds = parseInt(seconds); + let h = Math.floor(seconds / 3600); + h = h > 9 ? h : '0' + h; + seconds %= 3600; + let m = Math.floor(seconds / 60); + m = m > 9 ? m : '0' + m; + seconds %= 60; + seconds = seconds > 9 ? seconds : '0' + seconds; + return h + ':' + m + ':' + seconds; +}; + +const execJpg = (videoPath , saveFilePath, timeArr, index )=>{ + let ind = index + 1; + ind = ind > 9 ? ind : '0' + ind; + const str = `ffmpeg -ss ${timeArr[index]} -i ${videoPath} -y -f image2 -t 0.001 ${saveFilePath + ind}.jpg`; + cp.exec(str,(err)=>{ + if(err) console.log(err); + console.log(`${saveFilePath + ind}.jpg success...`); + if(index < timeArr.length - 1){ + execJpg(videoPath , saveFilePath, timeArr, index + 1 ) + } + }) +}; +const countSplitPoint = (duration,cutNums = 30) => { + console.log('duration',duration); + let realNums = cutNums; + if(realNums > duration) realNums = parseInt(duration); + console.log('realNums',realNums); + const step = Math.floor(duration / realNums); + let start = 0; + const res = []; + while(realNums--){ + res.push(changTimeFormat(start)); + start += step; + } + return res; +}; + +const getVideoFrame = (config = defaultConfig)=>{ + getVideoDurationInSeconds(config.videoPath).then(res=>{ + const timeArr = countSplitPoint(res,config.cutNums); + execJpg(config.videoPath , config.saveFilePath, timeArr, 0 ); + }); +}; + +module.exports = getVideoFrame; \ No newline at end of file diff --git a/src/getVideoFrame/img/01.jpg b/src/getVideoFrame/img/01.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a6f0b647f9c1f76ee8cce175d76d678b3d77c48a Binary files /dev/null and b/src/getVideoFrame/img/01.jpg differ diff --git a/src/getVideoFrame/img/02.jpg b/src/getVideoFrame/img/02.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2f7aa1df9c71aa395cd42e5353785296cb53020f Binary files /dev/null and b/src/getVideoFrame/img/02.jpg differ diff --git a/src/getVideoFrame/img/03.jpg b/src/getVideoFrame/img/03.jpg new file mode 100644 index 0000000000000000000000000000000000000000..23913c5a268eb5c4b5905ef302a19f19706fdaa1 Binary files /dev/null and b/src/getVideoFrame/img/03.jpg differ diff --git a/src/getVideoFrame/img/04.jpg b/src/getVideoFrame/img/04.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a6cc99c57a76e70065c17091b74014d1259d849f Binary files /dev/null and b/src/getVideoFrame/img/04.jpg differ diff --git a/src/getVideoFrame/img/05.jpg b/src/getVideoFrame/img/05.jpg new file mode 100644 index 0000000000000000000000000000000000000000..79eeca1bf80de112ac1f082ede2f169e0dd9edee Binary files /dev/null and b/src/getVideoFrame/img/05.jpg differ diff --git a/src/getVideoFrame/img/06.jpg b/src/getVideoFrame/img/06.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1f5c4e7dd5a94b528ae5becdfceccf020952c560 Binary files /dev/null and b/src/getVideoFrame/img/06.jpg differ diff --git a/src/getVideoFrame/img/07.jpg b/src/getVideoFrame/img/07.jpg new file mode 100644 index 0000000000000000000000000000000000000000..09a61c91725322317fdaae1e15f858618aa6abad Binary files /dev/null and b/src/getVideoFrame/img/07.jpg differ diff --git a/src/getVideoFrame/img/08.jpg b/src/getVideoFrame/img/08.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2de0110db87cf2c74334958f8afc9f87f572ef38 Binary files /dev/null and b/src/getVideoFrame/img/08.jpg differ diff --git a/src/getVideoFrame/img/09.jpg b/src/getVideoFrame/img/09.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2f6ac91e33f9b5cdad88ef26d6781ec72c00e277 Binary files /dev/null and b/src/getVideoFrame/img/09.jpg differ diff --git a/src/getVideoFrame/img/10.jpg b/src/getVideoFrame/img/10.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f2730fb80caaf80b47c668034def9a5ac08515ce Binary files /dev/null and b/src/getVideoFrame/img/10.jpg differ diff --git a/src/getVideoFrame/img/11.jpg b/src/getVideoFrame/img/11.jpg new file mode 100644 index 0000000000000000000000000000000000000000..153291a142444a055f88d6a4cd7379263e70b3f5 Binary files /dev/null and b/src/getVideoFrame/img/11.jpg differ diff --git a/src/getVideoFrame/img/12.jpg b/src/getVideoFrame/img/12.jpg new file mode 100644 index 0000000000000000000000000000000000000000..88b22fd54c1f2bc5e6d6282fd1e772a6bf31bbd1 Binary files /dev/null and b/src/getVideoFrame/img/12.jpg differ diff --git a/src/getVideoFrame/index.js b/src/getVideoFrame/index.js new file mode 100644 index 0000000000000000000000000000000000000000..390408d98186690a46c13534bd19f8f9477e0d86 --- /dev/null +++ b/src/getVideoFrame/index.js @@ -0,0 +1,25 @@ +const consoleInput = require('@jyeontu/console-input'); +const getVideoFrame = require('./getVideoFrame'); + +const config = [ + { + name:'videoPath', + tip:'请输入视频路径(如./video/1.mp4):', + configTip:'视频路径: ' + }, + { + name:'saveFilePath', + tip:'请输入截图保存路径(如./img/): ', + configTip:'截图保存路径:' + }, + { + name:'cutNums', + tip:'请输入需要截取图片数量(如30),注意:数量应该小于视频时间秒数: ', + configTip:'截取图片数量:' + } +]; +const getInput = new consoleInput(config); +let res = getInput.askInput(); +res.then(res=>{ + getVideoFrame(res); +}); \ No newline at end of file diff --git a/src/getVideoFrame/package.json b/src/getVideoFrame/package.json new file mode 100644 index 0000000000000000000000000000000000000000..e64fcba2a292c98f3f16d9d7b050b9f5cca2d387 --- /dev/null +++ b/src/getVideoFrame/package.json @@ -0,0 +1,17 @@ +{ + "name": "@jyeontu/get-video-frame", + "description": "node + ffmpeg截取视频指定帧图片。", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@jyeontu/console-input": "^1.0.1", + "child_process": "^1.0.2", + "ffmpeg": "^0.0.4" + } +} diff --git a/src/getVideoFrame/video/1.mp4 b/src/getVideoFrame/video/1.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..93c0b8ac05b5ccf9e88f3e5a5be173d11b5c3015 Binary files /dev/null and b/src/getVideoFrame/video/1.mp4 differ diff --git a/src/imgConcat/README.md b/src/imgConcat/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3396769bb92df42572cf4f4c9ec34b80ee3a24e0 --- /dev/null +++ b/src/imgConcat/README.md @@ -0,0 +1,17 @@ +## getVideoImg +node + ffmpeg截取视频指定帧图片。 +### 准备 +#### 安装ffmpeg +首先我们应该要先在电脑上安装好ffmpeg。 +官方下载地址:[https://ffmpeg.org/download.html](https://ffmpeg.org/download.html)/ +下载后并配置好环境变量之后即可继续往下。 +#### 依赖下载 +- ffmpeg +```shell +npm install ffmpeg +``` +- child_process +```shell +npm install child_process +``` +#### 工具使用 \ No newline at end of file diff --git a/src/imgConcat/img/01.jpg b/src/imgConcat/img/01.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a6f0b647f9c1f76ee8cce175d76d678b3d77c48a Binary files /dev/null and b/src/imgConcat/img/01.jpg differ diff --git a/src/imgConcat/img/02.jpg b/src/imgConcat/img/02.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2f7aa1df9c71aa395cd42e5353785296cb53020f Binary files /dev/null and b/src/imgConcat/img/02.jpg differ diff --git a/src/imgConcat/img/03.jpg b/src/imgConcat/img/03.jpg new file mode 100644 index 0000000000000000000000000000000000000000..23913c5a268eb5c4b5905ef302a19f19706fdaa1 Binary files /dev/null and b/src/imgConcat/img/03.jpg differ diff --git a/src/imgConcat/img/04.jpg b/src/imgConcat/img/04.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a6cc99c57a76e70065c17091b74014d1259d849f Binary files /dev/null and b/src/imgConcat/img/04.jpg differ diff --git a/src/imgConcat/img/05.jpg b/src/imgConcat/img/05.jpg new file mode 100644 index 0000000000000000000000000000000000000000..79eeca1bf80de112ac1f082ede2f169e0dd9edee Binary files /dev/null and b/src/imgConcat/img/05.jpg differ diff --git a/src/imgConcat/img/06.jpg b/src/imgConcat/img/06.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1f5c4e7dd5a94b528ae5becdfceccf020952c560 Binary files /dev/null and b/src/imgConcat/img/06.jpg differ diff --git a/src/imgConcat/img/07.jpg b/src/imgConcat/img/07.jpg new file mode 100644 index 0000000000000000000000000000000000000000..09a61c91725322317fdaae1e15f858618aa6abad Binary files /dev/null and b/src/imgConcat/img/07.jpg differ diff --git a/src/imgConcat/img/08.jpg b/src/imgConcat/img/08.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2de0110db87cf2c74334958f8afc9f87f572ef38 Binary files /dev/null and b/src/imgConcat/img/08.jpg differ diff --git a/src/imgConcat/img/09.jpg b/src/imgConcat/img/09.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2f6ac91e33f9b5cdad88ef26d6781ec72c00e277 Binary files /dev/null and b/src/imgConcat/img/09.jpg differ diff --git a/src/imgConcat/img/10.jpg b/src/imgConcat/img/10.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f2730fb80caaf80b47c668034def9a5ac08515ce Binary files /dev/null and b/src/imgConcat/img/10.jpg differ diff --git a/src/imgConcat/img/11.jpg b/src/imgConcat/img/11.jpg new file mode 100644 index 0000000000000000000000000000000000000000..153291a142444a055f88d6a4cd7379263e70b3f5 Binary files /dev/null and b/src/imgConcat/img/11.jpg differ diff --git a/src/imgConcat/img/12.jpg b/src/imgConcat/img/12.jpg new file mode 100644 index 0000000000000000000000000000000000000000..88b22fd54c1f2bc5e6d6282fd1e772a6bf31bbd1 Binary files /dev/null and b/src/imgConcat/img/12.jpg differ diff --git a/src/imgConcat/imgConcat.js b/src/imgConcat/imgConcat.js new file mode 100644 index 0000000000000000000000000000000000000000..fd96d1da0938d6c2eb08f7e7cf64d0468f9c78db --- /dev/null +++ b/src/imgConcat/imgConcat.js @@ -0,0 +1,31 @@ +const gm = require('gm'); +const fs = require('fs'); +const path = require('path'); + +const folderPath = './img'; +const targetFolder = './longImg'; + + +function collapse (left,right,target,flag = true) { + return new Promise((r) => { + gm(left).append(right,flag).write(target, err => { + if(err) console.log(err); + r(); + }) + }) + } +(async function () { + let fileList = fs.readdirSync(folderPath); + fileList.sort((a, b) => { + return path.basename(a) - path.basename(b); + }) + let targetFilePath = path.join(targetFolder, fileList[0]); + for (let index = 1; index < fileList.length; index++) { + let leftFile = path.join(folderPath, fileList[index - 1]); + let rightFile = path.join(folderPath, fileList[index]); + console.log(`正在拼接${index}/${fileList.length}`); + await collapse(index == 1 ? leftFile : targetFilePath,rightFile,targetFilePath,false); + } + console.log(`拼接完成,图片路径为${targetFilePath}`); + process.exit(0); +})(); \ No newline at end of file diff --git a/src/imgConcat/longImg/01.jpg b/src/imgConcat/longImg/01.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2e091345d5b9853a94be7d66883a22b43d905c99 Binary files /dev/null and b/src/imgConcat/longImg/01.jpg differ