node-red-contrib-hik-media-buffer 1.1.104 → 1.1.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hik-media-buffer.js +10 -8
- package/package.json +1 -1
package/hik-media-buffer.js
CHANGED
|
@@ -103,6 +103,7 @@ module.exports = function(RED) {
|
|
|
103
103
|
const pad = (num) => String(num).padStart(2, '0');
|
|
104
104
|
const timeGoBack = new Date(referenceTime.getTime() - (10 * 1000)); // iniziamo 10 secondi prima dello scatto
|
|
105
105
|
|
|
106
|
+
// Generiamo il timestamp con T e Z MAIUSCOLE e SENZA due punti, esattamente come piace a Hikvision
|
|
106
107
|
const year = timeGoBack.getUTCFullYear();
|
|
107
108
|
const month = pad(timeGoBack.getUTCMonth() + 1);
|
|
108
109
|
const day = pad(timeGoBack.getUTCDate());
|
|
@@ -110,11 +111,10 @@ module.exports = function(RED) {
|
|
|
110
111
|
const minutes = pad(timeGoBack.getUTCMinutes());
|
|
111
112
|
const seconds = pad(timeGoBack.getUTCSeconds());
|
|
112
113
|
|
|
114
|
+
// Output pulito: 20260624T085731Z
|
|
113
115
|
const rtspTimestamp = `${year}${month}${day}T${hours}${minutes}${seconds}Z`;
|
|
114
116
|
|
|
115
117
|
node.status({fill:"yellow", shape:"dot", text:`Estrazione media Cam ${channelID}...`});
|
|
116
|
-
|
|
117
|
-
// Aspettiamo 5 secondi per dare all'NVR il tempo di scrivere i frame correnti sull'hard disk
|
|
118
118
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
119
119
|
|
|
120
120
|
let output = {
|
|
@@ -126,16 +126,18 @@ module.exports = function(RED) {
|
|
|
126
126
|
let fileDaCancellare = [];
|
|
127
127
|
|
|
128
128
|
try {
|
|
129
|
-
const trackId = parseInt(channelID) * 100 + 1;
|
|
129
|
+
const trackId = parseInt(channelID) * 100 + 1;
|
|
130
130
|
const fixedPath = path.join(baseStorage, `hik_v_${channelID}_${timestamp}.mp4`);
|
|
131
131
|
const fullImgPath = path.join(baseStorage, `img_${timestamp}.jpg`);
|
|
132
132
|
|
|
133
|
-
//
|
|
134
|
-
const archiveRtspUrl = `rtsp://${node.user}:${node.pass}@${node.host}:554/Streaming/
|
|
135
|
-
node.warn(`[DEBUG RTSP]
|
|
133
|
+
// Cambiamo leggermente l'endpoint usando /channels/ che è più tollerante sul TCP d'archivio
|
|
134
|
+
const archiveRtspUrl = `rtsp://${node.user}:${node.pass}@${node.host}:554/Streaming/channels/${channelID}01/?starttime=${rtspTimestamp}`;
|
|
135
|
+
node.warn(`[DEBUG RTSP] Tentativo TCP blindato su: ${archiveRtspUrl}`);
|
|
136
136
|
|
|
137
|
-
//
|
|
138
|
-
|
|
137
|
+
// -rtsp_transport tcp forza il tunnel stabile senza pacchetti persi
|
|
138
|
+
// -stimeout imposta il timeout interno della connessione a 20 secondi (in microsecondi)
|
|
139
|
+
// -fflags +genpts forza FFmpeg a ricostruire i timestamp mancanti ignorando i drop iniziali dell'NVR
|
|
140
|
+
const ffmpegRtspCmd = `ffmpeg -y -rtsp_transport tcp -stimeout 20000000 -i "${archiveRtspUrl}" -t 15 -fflags +genpts -c:v copy -c:a aac -movflags +faststart "${fixedPath}"`;
|
|
139
141
|
|
|
140
142
|
await new Promise((resolve) => {
|
|
141
143
|
exec(ffmpegRtspCmd, { timeout: 25000 }, (err) => {
|