From f2313f5ba3bd6cbc4f953b2d390e8fffc2ec88a5 Mon Sep 17 00:00:00 2001
From: Moe <github@m03.ca>
Date: Wed, 8 Aug 2018 21:40:34 -0700
Subject: [PATCH] Allow different fps, height, and width when using "Check for
 Motion First" with "Built-In"

---
 camera.js                        | 30 +++++++++++++++++++++++-------
 web/pages/blocks/monitoredit.ejs | 21 ++++++++++++++++++++-
 2 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/camera.js b/camera.js
index 04760e48..0093bc28 100644
--- a/camera.js
+++ b/camera.js
@@ -1804,18 +1804,35 @@ s.ffmpegCoProcessor = function(e){
     }
     //detector frames
     if(e.details.detector === '1'){
-        if(!e.details.detector_fps||e.details.detector_fps===''){e.details.detector_fps=2}
-        if(e.details.detector_scale_x&&e.details.detector_scale_x!==''&&e.details.detector_scale_y&&e.details.detector_scale_y!==''){x.dratio=' -s '+e.details.detector_scale_x+'x'+e.details.detector_scale_y}else{x.dratio=' -s 320x240'}
+        if(e.details.detector_fps && e.details.detector_fps !== ''){
+            x.detector_fps = e.details.detector_fps
+        }else{
+            x.detector_fps = '2'
+        }
+        if(e.details.detector_scale_x && e.details.detector_scale_x !== '' && e.details.detector_scale_y && e.details.detector_scale_y !== ''){
+            x.dratio=' -s '+e.details.detector_scale_x+'x'+e.details.detector_scale_y
+        }else{
+            x.dratio=' -s 320x240'
+        }
+        
         if(e.details.cust_detect&&e.details.cust_detect!==''){x.cust_detect+=e.details.cust_detect;}
         if(e.details.detector_pam==='1'){
-            x.pipe += ' -an -c:v pam -pix_fmt gray -f image2pipe -r '+e.details.detector_fps+x.cust_detect+x.dratio+' pipe:3'
+            x.pipe += ' -an -c:v pam -pix_fmt gray -f image2pipe -r '+x.detector_fps+x.cust_detect+x.dratio+' pipe:3'
             if(e.details.detector_use_detect_object === '1'){
+                if(e.details.detector_use_motion === '1'){
+                    if(e.details.detector_scale_x_object && e.details.detector_scale_x_object !== '' && e.details.detector_scale_y_object && e.details.detector_scale_y_object !== ''){
+                        x.dratio=' -s '+e.details.detector_scale_x_object+'x'+e.details.detector_scale_y_object
+                    }
+                    if(e.details.detector_fps_object && e.details.detector_fps_object !== ''){
+                        x.detector_fps = e.details.detector_fps_object
+                    }
+                }
                 //for object detection
                 x.pipe += s.createFFmpegMap(e,e.details.input_map_choices.detector)
-                x.pipe += ' -f singlejpeg -vf fps='+e.details.detector_fps+x.cust_detect+x.dratio+' pipe:4';
+                x.pipe += ' -f singlejpeg -vf fps='+x.detector_fps+x.cust_detect+x.dratio+' pipe:4';
             }
         }else{
-            x.pipe+=' -f singlejpeg -vf fps='+e.details.detector_fps+x.cust_detect+x.dratio+' pipe:3';
+            x.pipe+=' -f singlejpeg -vf fps='+x.detector_fps+x.cust_detect+x.dratio+' pipe:3';
         }
     }
     //snapshot frames
@@ -2519,8 +2536,7 @@ s.event = function(x,e,cn){
                         if(matrix)reviewedMatrix.push(matrix)
                     })
                     d.details.matrices = reviewedMatrix
-                }
-                if(d.details.matrices && d.details.matrices.length === 0 || filter.halt === true){
+                }else if(d.details.matrices && d.details.matrices.length === 0 || filter.halt === true){
                     return
                 }
             }
diff --git a/web/pages/blocks/monitoredit.ejs b/web/pages/blocks/monitoredit.ejs
index 1c607b3f..e40ff95e 100644
--- a/web/pages/blocks/monitoredit.ejs
+++ b/web/pages/blocks/monitoredit.ejs
@@ -1111,12 +1111,31 @@
                       </div>
                       <div class="form-group">
                         <label><div><span><%-lang['Check for Motion First']%></span></div>
-                            <div><select class="form-control" detail="detector_use_motion">
+                            <div><select class="form-control" detail="detector_use_motion" selector="h_det_mot_fir">
                                 <option value="0" selected><%-lang.No%></option>
                                 <option value="1"><%-lang.Yes%></option>
                             </select></div>
                         </label>
                       </div>
+                      <div class="h_det_pam_input h_det_pam_1">
+                          <div class="h_det_mot_fir_input h_det_mot_fir_1">
+                              <div class="form-group">
+                                <label><div><span><%-lang['Frame Rate']%></span></div>
+                                    <div><input class="form-control" type="number" min="1" detail="detector_fps_object" placeholder="2"></div>
+                                </label>
+                              </div>
+                              <div class="form-group">
+                                <label><div><span><%-lang['Width']%></span></div>
+                                    <div><input class="form-control" type="number" min="1" detail="detector_scale_x_object" placeholder="320"></div>
+                                </label>
+                              </div>
+                              <div class="form-group">
+                                <label><div><span><%-lang['Height']%></span></div>
+                                    <div><input class="form-control" type="number" min="1" detail="detector_scale_y_object" placeholder="240"></div>
+                                </label>
+                              </div>
+                          </div>
+                      </div>
                       <div class=" h_casc_input h_casc_1" style="display:none">
                           <div class="form-group-group orange shinobi-detector-opencv shinobi-detector-openalpr shinobi-detector_plug" style="display:none" section id="monSectionLisencePlateDetector">
                               <h4><%-lang['Lisence Plate Detector']%></h4>