Skip to content
This repository was archived by the owner on Jun 18, 2022. It is now read-only.

Commit a541cd3

Browse files
author
Cédric Verstraeten
committed
add extra video check if valid, causes the motion detection screen to crash.
1 parent 6c606ba commit a541cd3

File tree

4 files changed

+51
-41
lines changed

4 files changed

+51
-41
lines changed

app/Http/Controllers/ImageController.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,25 @@ public function getLatestSequence()
107107

108108
if($videosFound)
109109
{
110-
if(count($images) > 1)
110+
for($i = count($images) - 1; $i >= 0; $i--)
111111
{
112-
$lastMedia = $images[count($images)-1];
113-
if($lastMedia['type'] === 'video')
112+
$media = $images[$i];
113+
114+
// We will use getID4 to check if media this.
115+
$getID3 = new \getID3;
116+
$mediaInfo = $getID3->analyze($media['local_src']);
117+
118+
if($media['type'] === 'image' ||
119+
($media['type'] === 'video' && $mediaInfo['playtime_seconds'])
120+
)
121+
{
122+
break;
123+
}
124+
else // If a video but not valid, remove it!
114125
{
115126
array_pop($images);
116127
}
117128
}
118-
else
119-
{
120-
$images = $this->imageHandler->getSecondLatestSequence();
121-
}
122129
}
123130

124131
return Response::json($images);

app/Http/Repositories/ImageHandler/ImageFileSystemHandler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ public function getImagesSequenceFromDay($day, $page, $maximumTimeBetween)
442442
$object = [
443443
'time' => $image->getTime(),
444444
'src' => $path,
445+
'local_src' => $systemPath,
445446
'metadata' => $this->filesystem->getMetadata($image)
446447
];
447448

@@ -538,6 +539,7 @@ public function getImagesSequenceFromDayAndStartTime($day, $page, $starttime, $m
538539
$object = [
539540
'time' => $image->getTime(),
540541
'src' => $path,
542+
'local_src' => $systemPath,
541543
'metadata' => $this->filesystem->getMetadata($image)
542544
];
543545

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
"type": "project",
77
"require": {
88
"php": ">=5.6.4",
9+
"cedricve/lockfile": "1.0.1",
10+
"cedricve/simpleauth": "1.2.2",
11+
"intervention/image": "dev-master",
12+
"james-heinrich/getid3": "^1.9",
913
"laravel/framework": "5.4.*",
1014
"laravel/tinker": "~1.0",
11-
"intervention/image": "dev-master",
12-
"cedricve/simpleauth": "1.2.2",
13-
"cedricve/lockfile": "1.0.1",
14-
"linfo/linfo": "^3.0",
15-
"laravelcollective/html": "~5.0"
15+
"laravelcollective/html": "~5.0",
16+
"linfo/linfo": "^3.0"
1617
},
1718
"require-dev": {
1819
"fzaninotto/faker": "~1.4",

public/js/app/controllers/dashboard_heatmap.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Dashboard Heatmap:
2+
* Dashboard Heatmap:
33
* Shows an heatmap which is draw
4-
* on a canvas
4+
* on a canvas
55
**/
66

77
define(["heatmap"], function(heatmap)
@@ -18,21 +18,21 @@ define(["heatmap"], function(heatmap)
1818
self.config = config;
1919
self.fps = config.fps;
2020
self.radius = (config.radius) ? config.radius * 100 : 250;
21-
21+
2222
// create heatmap
2323
self.heatmapInstance = heatmap.create({
2424
container: document.querySelector('.heatmap'),
2525
maxOpacity: 0.5,
2626
minOpacity: 0
2727
});
28-
28+
2929
$(window).resize(function()
3030
{
3131
self.resize();
3232
self.draw();
3333
});
34-
35-
// Wait 300 ms before executing
34+
35+
// Wait 300 ms before executing
3636
setTimeout(self.config.callback, 300);
3737
},
3838
changeRadius: function(radius)
@@ -43,7 +43,7 @@ define(["heatmap"], function(heatmap)
4343
redraw: function()
4444
{
4545
self = this;
46-
46+
4747
$.get(self.config.url,function(data)
4848
{
4949
$.get(self.config.urlSequence,function(images)
@@ -75,7 +75,7 @@ define(["heatmap"], function(heatmap)
7575
{
7676
var canvas = $(".heatmap canvas").get(0);
7777
var ctx = canvas.getContext("2d");
78-
78+
7979
var x = canvas.width / 2;
8080
var y = canvas.height / 2;
8181
ctx.font = '20px Arial';
@@ -110,16 +110,16 @@ define(["heatmap"], function(heatmap)
110110
context.drawImage(video, 0, 0, canvas.width(), canvas.height());
111111
var data = canvas.get(0).toDataURL();
112112
canvas.css({
113-
"background-image": "url("+data+")",
114-
"background-size": "100% 100%",
113+
"background-image": "url("+data+")",
114+
"background-size": "100% 100%",
115115
"background-repeat": "no-repeat",
116116
});
117117

118118
video.pause();
119119
callback();
120120
});
121121
}
122-
else
122+
else if(this.images.length)
123123
{
124124
var image = this.images[this.images.length-1];
125125
var img = new Image();
@@ -130,22 +130,22 @@ define(["heatmap"], function(heatmap)
130130
self.latestImage.width = this.width;
131131
self.latestImage.height = this.height;
132132
canvas.css({
133-
"background": "url('"+image.src+"')",
134-
"background-size": "100% 100%",
133+
"background": "url('"+image.src+"')",
134+
"background-size": "100% 100%",
135135
"background-repeat": "no-repeat",
136136
});
137137
canvas.attr("height", canvas.width()/2);
138-
$(".heatmap").css({"height": canvas.height()});
138+
$(".heatmap").css({"height": canvas.height()});
139139
callback();
140140
};
141141
}
142-
142+
143143
this.heatmapInstance._renderer.setDimensions(canvas.width(),canvas.height());
144144
},
145145
setRegions: function(data)
146146
{
147147
this.regions = [];
148-
148+
149149
for(var i =0; i < data.length; i++)
150150
{
151151
var regionCoordinates = data[i].regionCoordinates.split("-");
@@ -170,11 +170,11 @@ define(["heatmap"], function(heatmap)
170170
region.end.y = parseInt(regionCoordinates[3]);
171171
region.changes = parseInt(data[i].numberOfChanges);
172172
region.average = parseInt(data[i].numberOfChanges) / ((region.end.x - region.start.x) * (region.end.y - region.start.y));
173-
173+
174174
this.regions.push(region);
175175
}
176176
}
177-
177+
178178
return data;
179179
},
180180
calculate: function(regions)
@@ -183,18 +183,18 @@ define(["heatmap"], function(heatmap)
183183
var width = 640;
184184
var height = 360;
185185
var dataPoints = [];
186-
186+
187187
var originalWidth = this.latestImage.width;
188188
var originalHeight = this.latestImage.height;
189-
189+
190190
var canvas = $(".heatmap canvas");
191191
var currentWidth = canvas.width();
192192
var currentHeight = canvas.height();
193-
193+
194194
// scale x- and y-coordinates
195195
var dx = currentWidth / originalWidth;
196196
var dy = currentHeight / originalHeight;
197-
197+
198198
for(var i = 0; i < regions.length; i++)
199199
{
200200
max = Math.max(max, regions[i].average);
@@ -204,24 +204,24 @@ define(["heatmap"], function(heatmap)
204204
value: regions[i].average,
205205
radius: regions[i].average * this.radius,
206206
};
207-
207+
208208
dataPoints.push(point);
209209
}
210-
211-
var data = {
212-
max: max,
210+
211+
var data = {
212+
max: max,
213213
data: dataPoints
214214
};
215-
215+
216216
return data;
217217
},
218218
resize: function()
219219
{
220220
var canvas = $(".heatmap canvas");
221221
canvas.attr("width", $(".heatmap").width());
222222
canvas.attr("height", canvas.width()/2);
223-
$(".heatmap").css({"height": canvas.width()});
223+
$(".heatmap").css({"height": canvas.width()});
224224
$(".heatmap").css({"height": canvas.height()});
225225
}
226226
};
227-
});
227+
});

0 commit comments

Comments
 (0)