ONVIF Scanner show Snapshot
parent
d1e17479bb
commit
c21ec0d1b9
|
@ -1,3 +1,6 @@
|
|||
const fs = require('fs');
|
||||
const treekill = require('tree-kill');
|
||||
const spawn = require('child_process').spawn;
|
||||
module.exports = (s,config,lang) => {
|
||||
const cameraDestroy = function(e,p){
|
||||
if(
|
||||
|
@ -82,7 +85,75 @@ module.exports = (s,config,lang) => {
|
|||
}
|
||||
}
|
||||
}
|
||||
const createSnapshot = (options) => {
|
||||
const url = options.url
|
||||
const streamDir = options.streamDir || s.dir.streams
|
||||
const inputOptions = options.input || []
|
||||
const outputOptions = options.output || []
|
||||
return new Promise((resolve,reject) => {
|
||||
if(!url){
|
||||
resolve(null);
|
||||
return
|
||||
}
|
||||
const temporaryImageFile = streamDir + s.gid(5) + '.jpg'
|
||||
const ffmpegCmd = s.splitForFFPMEG(`-loglevel warning -re -probesize 100000 -analyzeduration 100000 ${inputOptions.join(' ')} -i "${url}" ${outputOptions.join(' ')} -f image2 -an -vf "fps=1" -vframes 1 "${temporaryImageFile}"`)
|
||||
const snapProcess = spawn('ffmpeg',ffmpegCmd,{detached: true})
|
||||
snapProcess.stderr.on('data',function(data){
|
||||
// s.debugLog(data.toString())
|
||||
})
|
||||
snapProcess.on('close',async function(data){
|
||||
clearTimeout(snapProcessTimeout)
|
||||
fs.readFile(temporaryImageFile,(err,imageBuffer) => {
|
||||
try{
|
||||
s.file('delete',temporaryImageFile)
|
||||
}catch(err){
|
||||
|
||||
}
|
||||
if(err){
|
||||
s.debugLog(err)
|
||||
}
|
||||
resolve(imageBuffer)
|
||||
})
|
||||
})
|
||||
var snapProcessTimeout = setTimeout(function(){
|
||||
var pid = snapProcess.pid
|
||||
if(s.isWin){
|
||||
spawn("taskkill", ["/pid", pid, '/t'])
|
||||
}else{
|
||||
process.kill(-pid, 'SIGTERM')
|
||||
}
|
||||
setTimeout(function(){
|
||||
if(s.isWin === false){
|
||||
treekill(pid)
|
||||
}else{
|
||||
snapProcess.kill()
|
||||
}
|
||||
fs.readFile(temporaryImageFile,(err,imageBuffer) => {
|
||||
try{
|
||||
s.file('delete',temporaryImageFile)
|
||||
}catch(err){
|
||||
|
||||
}
|
||||
if(err){
|
||||
s.debugLog(err)
|
||||
}
|
||||
resolve(imageBuffer)
|
||||
})
|
||||
},10000)
|
||||
},30000)
|
||||
})
|
||||
}
|
||||
const addCredentialsToStreamLink = (options) => {
|
||||
const streamUrl = options.url
|
||||
const username = options.username
|
||||
const password = options.password
|
||||
const urlParts = streamUrl.split('://')
|
||||
urlParts[0] = 'http'
|
||||
return ['rtsp','://',`${username}:${password}@`,urlParts[1]].join('')
|
||||
}
|
||||
return {
|
||||
cameraDestroy: cameraDestroy
|
||||
cameraDestroy: cameraDestroy,
|
||||
createSnapshot: createSnapshot,
|
||||
addCredentialsToStreamLink: addCredentialsToStreamLink,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@ var os = require('os');
|
|||
var exec = require('child_process').exec;
|
||||
var onvif = require("node-onvif");
|
||||
module.exports = function(s,config,lang,app,io){
|
||||
const {
|
||||
createSnapshot,
|
||||
addCredentialsToStreamLink,
|
||||
} = require('./monitor/utils.js')(s,config,lang)
|
||||
const activeProbes = {}
|
||||
const runFFprobe = (url,auth,callback) => {
|
||||
var endData = {ok: false}
|
||||
|
@ -114,7 +118,15 @@ module.exports = function(s,config,lang,app,io){
|
|||
uri: stream.data.GetStreamUriResponse.MediaUri.Uri
|
||||
}
|
||||
responseList.push(cameraResponse)
|
||||
if(foundCameraCallback)foundCameraCallback(Object.assign(cameraResponse,{f: 'onvif'}))
|
||||
const imageSnap = (await createSnapshot({
|
||||
output: ['-s 400x400'],
|
||||
url: addCredentialsToStreamLink({
|
||||
username: onvifUsername,
|
||||
password: onvifPassword,
|
||||
url: stream.data.GetStreamUriResponse.MediaUri.Uri
|
||||
}),
|
||||
})).toString('base64');
|
||||
if(foundCameraCallback)foundCameraCallback(Object.assign(cameraResponse,{f: 'onvif', snapShot: imageSnap}))
|
||||
}catch(err){
|
||||
const searchError = (find) => {
|
||||
return s.stringContains(find,err.message,true)
|
||||
|
|
|
@ -24,6 +24,7 @@ $(document).ready(function(e){
|
|||
streamUrl = options.uri
|
||||
}
|
||||
$('#onvif_probe .output_data').append(`<tr onvif_row="${tempID}">
|
||||
<td><img style="max-width:100px" src="${options.snapShot ? 'data:image/png;base64,' + options.snapShot : placeholder.getData(placeholder.plcimg({text: ' ', fsize: 25, bgcolor:'#1462a5'}))}"></td>
|
||||
<td><a ${options.error ? `target="_blank" href="http${options.port == 443 ? 's' : ''}://${options.ip}:${options.port}"` : ''} class="btn btn-sm btn-primary ${options.error ? '' : 'copy'}"> <i class="fa fa-${options.error ? 'link' : 'copy'}"></i> </a></td>
|
||||
<td class="ip">${options.ip}</td>
|
||||
<td class="port">${options.port}</td>
|
||||
|
|
Loading…
Reference in New Issue