cleanup ffmpeg check and add ffbinary usability

- run npm install ffbinaries to use that downloader instead.
- ffmpeg-static and ffbinaries should get the same version just get them in a different way.
merge-requests/30/head
Moe 2018-09-29 13:09:24 -07:00
parent 9393c8caf7
commit 19a24f5f38
5 changed files with 133 additions and 63 deletions

View File

@ -45,7 +45,7 @@ if [ "$ffmpeginstall" = "y" ] || [ "$ffmpeginstall" = "Y" ]; then
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
sudo yum install ffmpeg ffmpeg-devel -y
else
sudo npm install ffmpeg-static@2.2.1
sudo npm install ffbinaries
fi
fi
echo "Shinobi - Do you want to Install Node.js?"

View File

@ -52,7 +52,7 @@ if [ "$ffmpeginstall" = "y" ] || [ "$ffmpeginstall" = "Y" ]; then
# Install ffmpeg and ffmpeg-devel
sudo zypper install -y ffmpeg ffmpeg-devel
else
sudo npm install ffmpeg-static@2.2.1
sudo npm install ffbinaries
fi
else
sudo zypper install -y ffmpeg ffmpeg-devel

View File

@ -64,7 +64,7 @@ if [ "$ffmpeginstall" = "y" ] || [ "$ffmpeginstall" = "Y" ]; then
echo "============="
fi
else
sudo npm install ffmpeg-static@2.2.1
sudo npm install ffbinaries
fi
fi
echo "============="

View File

@ -38,36 +38,37 @@ var lang = loadLib('language')(s,config)
//basic functions
loadLib('basic')(s,config)
//video processing engine
loadLib('ffmpeg')(s,config)
//database connection : mysql, sqlite3..
loadLib('sql')(s,config)
//working directories : videos, streams, fileBin..
loadLib('folders')(s,config)
//authenticator functions : API, dashboard login..
loadLib('auth')(s,config,lang)
//express web server with ejs
var app = loadLib('webServer')(s,config,lang,io)
//web server routes : page handling, streams..
loadLib('webServerPaths')(s,config,lang,app)
//websocket connection handlers : login and streams..
loadLib('socketio')(s,config,io)
//user and group functions
loadLib('user')(s,config)
//monitor/camera handlers
loadLib('monitor')(s,config,lang)
//notifiers : discord..
loadLib('notification')(s,config,lang)
//built-in detector functions : pam-diff..
loadLib('detector')(s,config)
//recording functions
loadLib('videos')(s,config)
//event functions : motion, object matrix handler
loadLib('events')(s,config,lang)
//plugins : websocket connected services..
loadLib('plugins')(s,config,lang)
//health : cpu and ram trackers..
loadLib('health')(s,config,lang,io)
//cluster module
loadLib('childNode')(s,config,lang,io)
//on-start actions
loadLib('startup')(s,config,lang)
loadLib('ffmpeg')(s,config,function(){
//database connection : mysql, sqlite3..
loadLib('sql')(s,config)
//working directories : videos, streams, fileBin..
loadLib('folders')(s,config)
//authenticator functions : API, dashboard login..
loadLib('auth')(s,config,lang)
//express web server with ejs
var app = loadLib('webServer')(s,config,lang,io)
//web server routes : page handling, streams..
loadLib('webServerPaths')(s,config,lang,app)
//websocket connection handlers : login and streams..
loadLib('socketio')(s,config,io)
//user and group functions
loadLib('user')(s,config)
//monitor/camera handlers
loadLib('monitor')(s,config,lang)
//notifiers : discord..
loadLib('notification')(s,config,lang)
//built-in detector functions : pam-diff..
loadLib('detector')(s,config)
//recording functions
loadLib('videos')(s,config)
//event functions : motion, object matrix handler
loadLib('events')(s,config,lang)
//plugins : websocket connected services..
loadLib('plugins')(s,config,lang)
//health : cpu and ram trackers..
loadLib('health')(s,config,lang,io)
//cluster module
loadLib('childNode')(s,config,lang,io)
//on-start actions
loadLib('startup')(s,config,lang)
})

View File

@ -1,36 +1,101 @@
var fs = require('fs');
var spawn = require('child_process').spawn;
var execSync = require('child_process').execSync;
module.exports = function(s,config){
var staticFFmpeg = false;
try{
staticFFmpeg = require('ffmpeg-static').path;
if (!fs.existsSync(staticFFmpeg)) {
staticFFmpeg = false
console.log('"ffmpeg-static" from NPM has failed to provide a compatible library or has been corrupted.')
console.log('You may need to install FFmpeg manually or you can try running "npm uninstall ffmpeg-static && npm install ffmpeg-static".')
module.exports = function(s,config,callback){
var downloadingFfmpeg = false;
var completeFfmpegCheck = function(){
//ffmpeg version
try{
s.ffmpegVersion = execSync(config.ffmpegDir+" -version").toString().split('Copyright')[0].replace('ffmpeg version','').trim()
console.log('FFMPEG version : '+s.ffmpegVersion)
if(s.ffmpegVersion.indexOf(': 2.')>-1){
s.systemLog('FFMPEG is too old : '+s.ffmpegVersion+', Needed : 3.2+',err)
throw (new Error())
}
}catch(err){
console.log('No FFmpeg found.')
// process.exit()
}
callback()
}
//check local ffmpeg
var windowsFfmpegCheck = function(failback){
if (s.isWin && fs.existsSync(s.mainDirectory+'/ffmpeg/ffmpeg.exe')) {
config.ffmpegDir = s.mainDirectory+'/ffmpeg/ffmpeg.exe'
}else{
failback()
}
}
//check local ffmpeg
var unixFfmpegCheck = function(failback){
if(s.isWin === false){
if (fs.existsSync('/usr/bin/ffmpeg')) {
config.ffmpegDir = '/usr/bin/ffmpeg'
}else{
if (fs.existsSync('/usr/local/bin/ffmpeg')) {
config.ffmpegDir = '/usr/local/bin/ffmpeg'
}else{
failback()
}
}
}else{
failback()
}
}
//check node module : ffmpeg-static
var ffmpegStaticCheck = function(failback){
try{
var staticFFmpeg = require('ffmpeg-static').path;
if (!fs.existsSync(staticFFmpeg)) {
console.log('"ffmpeg-static" from NPM has failed to provide a compatible library or has been corrupted.')
console.log('Run "npm uninstall ffmpeg-static" to remove it.')
console.log('Run "npm install ffbinaries" to get a different static FFmpeg downloader.')
}else{
config.ffmpegDir = staticFFmpeg
}
}catch(err){
console.log('No "ffmpeg-static".')
}
}
//check node module : ffbinaries
var ffbinaryCheck = function(failback){
try{
ffbinaries = require('ffbinaries')
var ffbinaryDir = s.mainDirectory + '/ffmpeg/'
var downloadFFmpeg = function(){
downloadingFfmpeg = true
console.log('ffbinaries : Downloading FFmpeg. Please Wait...');
ffbinaries.downloadBinaries(['ffmpeg', 'ffprobe'], {
destination: ffbinaryDir,
version : '3.4'
},function () {
config.ffmpegDir = ffbinaryDir + 'ffmpeg'
console.log('ffbinaries : FFmpeg Downloaded.');
completeFfmpegCheck()
})
}
if (!fs.existsSync(ffbinaryDir + 'ffmpeg')) {
downloadFFmpeg()
}else{
config.ffmpegDir = ffbinaryDir + 'ffmpeg'
}
}catch(err){
console.log('No "ffbinaries". Continuing.')
console.log('Run "npm install ffbinaries" to get this static FFmpeg downloader.')
failback()
}
}catch(err){
staticFFmpeg = false;
console.log('No Static FFmpeg. Continuing.')
}
//ffmpeg location
if(!config.ffmpegDir){
if(staticFFmpeg !== false){
config.ffmpegDir = staticFFmpeg
}else{
if(s.isWin===true){
config.ffmpegDir = s.mainDirectory+'/ffmpeg/ffmpeg.exe'
}else{
config.ffmpegDir = 'ffmpeg'
}
}
}
//ffmpeg version
s.ffmpegVersion=execSync(config.ffmpegDir+" -version").toString().split('Copyright')[0].replace('ffmpeg version','').trim()
console.log('FFMPEG version : '+s.ffmpegVersion)
if(s.ffmpegVersion.indexOf(': 2.')>-1){
s.systemLog('FFMPEG is too old : '+s.ffmpegVersion+', Needed : 3.2+',err)
throw (new Error())
windowsFfmpegCheck(function(){
unixFfmpegCheck(function(){
ffbinaryCheck(function(){
ffmpegStaticCheck(function(){
console.log('No FFmpeg found.')
})
})
})
})
}
s.splitForFFPMEG = function (ffmpegCommandAsString) {
//this function ignores spaces inside quotes.
@ -782,4 +847,8 @@ module.exports = function(s,config){
x.ffmpegCommandString = s.splitForFFPMEG(x.ffmpegCommandString.replace(/\s+/g,' ').trim())
return spawn(config.ffmpegDir,x.ffmpegCommandString,{detached: true,stdio:x.stdioPipes});
}
if(downloadingFfmpeg === false){
//not downloading ffmpeg
completeFfmpegCheck()
}
}