// This module is responsible for capturing videos

'use strict';

const config = require('config');
const PiCamera = require('pi-camera');
const myCamera = new PiCamera({
  mode: 'video',
  output: process.argv[2],
  width: config.get('camera.videoWidth'),
  height: config.get('camera.videoHeight'),
  timeout: config.get('camera.videoTimeout'),
  nopreview: true,
});

process.on('message', (message) => {
  if (message.cmd === 'set') {
    myCamera.config = Object.assign(myCamera.config, message.set);
  }
  else if (message.cmd === 'capture') {
    myCamera.record()
      .then((result) => process.send({
        response: 'success',
        result,
        error: null,
      }))
      .catch((error) => process.send({
        response: 'failure',
        error,
      }));
  }
});

@@ -540,24 +540,49 @@
 capture') %7B%0A
+    setTimeout(() =%3E %7B%0A  
     myCamera
@@ -591,16 +591,18 @@
 ecord()%0A
+  
       .t
@@ -632,32 +632,34 @@
 .send(%7B%0A        
+ 
+ 
 response: 'succe
@@ -671,16 +671,18 @@
         
+  
 result,%0A
@@ -685,24 +685,26 @@
 lt,%0A        
+ 
+ 
 error: null,
@@ -704,16 +704,18 @@
 : null,%0A
+  
       %7D)
@@ -722,16 +722,18 @@
 )%0A      
+  
 .catch((
@@ -749,32 +749,34 @@
  process.send(%7B%0A
+  
         response
@@ -792,24 +792,26 @@
 e',%0A        
+  
 error,%0A     
@@ -815,13 +815,28 @@
     
+ 
+ 
 %7D));%0A
+    %7D, 500);%0A
   %7D%0A

Add minor delay to video capture. Hopefully this helps the camera moduel keep up.