我正在尝试观看文件 Chokidar。文件夹中的 Mp4 文件。我正在尝试使用创建缩略图观看文件夹。但我的代码挂了。它卡住了。我等了十分钟,但我没有收到错误,而且我的代码工作得更少。再说一次,我还要等十分钟。但没有任何改变。
代码:
let fs = require('fs');
var chokidar = require('chokidar');
const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
const ffmpeg = require('fluent-ffmpeg');
ffmpeg.setFfmpegPath(ffmpegInstaller.path)
var counter = 0
var Mywatcher = chokidar.watch('Z:\\WatchFolder', {ignored: /^\./, persistent: true, usePolling: true});
Mywatcher
.on('add', function(path) {
worder = '.mp4'
if(path.includes(worder)){
counter = counter + 1
console.log('added' + counter)
ffmpeg({ source: path })
.on('filenames', (filenames) => {
console.log('Created file names', filenames);
})
.on('end', () => {
console.log('Job done');
})
.on('error', (err) => {
console.log('Error', err);
})
.takeScreenshots({
filename: counter +'.jpg',
timemarks: [ 2 ],
}, 'public/images/thumbnail/');
}
})
.on('change', function(path) {console.log('File', path, 'has been changed');})
.on('unlink', function(path) {
})
.on('error', function(error) {console.error('Error happened', error);})
第一个结果:完成了 1300 个缩略图。但尚未创建。缩略图的文件夹是空的。我的代码卡住了。
added13023
Created file names [ '13023.jpg' ]
added13024
Created file names [ '13024.jpg' ]
added13025
Created file names [ '13025.jpg' ]
added13026
Created file names [ '13026.jpg' ]
added13027
Created file names [ '13027.jpg' ]
added13028
Created file names [ '13028.jpg' ]
added13029
Created file names [ '13029.jpg' ]
added13030
Created file names [ '13030.jpg' ]
added13031
Created file names [ '13031.jpg' ]
added13032
Created file names [ '13032.jpg' ]
added13033
Created file names [ '13033.jpg' ]
added13034
Created file names [ '13034.jpg' ]
added13035
Created file names [ '13035.jpg' ]
added13036
Created file names [ '13036.jpg' ]
我再次尝试,我写了'nodemon start'和结果:
Created file names [ '13026.jpg' ]
added13027
Created file names [ '13027.jpg' ]
added13028
Created file names [ '13028.jpg' ]
added13029
Created file names [ '13029.jpg' ]
added13030
Created file names [ '13030.jpg' ]
added13031
Created file names [ '13031.jpg' ]
added13032
Created file names [ '13032.jpg' ]
added13033
Created file names [ '13033.jpg' ]
added13034
Created file names [ '13034.jpg' ]
added13035
Created file names [ '13035.jpg' ]
added13036
Created file names [ '13036.jpg' ]
added13037
Created file names [ '13037.jpg' ]
我该如何解决?谢谢大家。问候。