forked from stephen-webmad/mjpeg-restream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulated_camera.php
More file actions
105 lines (91 loc) · 3.05 KB
/
simulated_camera.php
File metadata and controls
105 lines (91 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/* *********************************************************************
*
* MJPG-ReStreamer, MJPG-Reverse-Proxy written in PHP
*
* (c) 2015 Stephen Price / Webmad, http://www.webmad.co.nz
* (c) 2022 Tom Stöveken
*
* This PHP script connects to a MJPG/MJPEG camera stream, extracts just
* the pictures and retransmits them as a MJPG-stream
*
* In contrast to common HTTP(s) reverse-proxies this script just passes
* the MJPEG stream and prevents accessing the upstream camera details
* and settings.
*
* ********************************************************************/
/**********************************************************************/
ini_set('output_buffering', 0);
ini_set('zlib.output_compression', 0);
//the boundary can be configured here.
$boundaryOut = "MyMultipartBoundaryDoNotStumble";
set_time_limit(10);
//send headers
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: Sat, 01 Jan 2000 01:00:00 GMT');
header('Connection: close');
header('Script-Info: MJPG-ReStreamer');
header('X-Accel-Buffering: no');
header("Content-Type: multipart/x-mixed-replace; boundary=$boundaryOut");
echo "--$boundaryOut\r\n";
flush();
/******************************************************************************
Description.: Output image to stream
Input Value.: $img is JPEG encoded image
Return Value: -
******************************************************************************/
function OutputImage($img) {
global $boundaryOut;
echo "Content-Type: image/jpeg\r\n".
"Content-Length: ".strlen($img)."\r\n".
"X-Timestamp: ".number_format(microtime(true), 6, '.', '')."\r\n".
"\r\n".
$img.
"\r\n--$boundaryOut\r\n";
flush();
ob_flush();
while (@ob_end_flush());
}
/******************************************************************************
Description.: Convert string to Image
Input Value.: $str is the message to write, linebreaks are not supported
$background is JPEG encoded background image
Return Value: JPEG encoded image data
******************************************************************************/
function TextToImage($str, $background=NULL) {
if( !is_null($background) ) {
$img = imagecreatefromstring($background);
$bgc = imagecolorallocate($img, 255, 255, 255);
imagefilledrectangle($img, 10, 10, 640-10, 50, $bgc);
} else {
$img = imagecreatetruecolor(640, 480);
$bgc = imagecolorallocate($img, 255, 255, 255);
imagefilledrectangle($img, 10, 10, 640-10, 480-10, $bgc);
}
$tc = imagecolorallocate($img, 0, 0, 0);
imagestring($img, 1, 20, 20, $str, $tc);
ob_start();
imagejpeg($img, NULL, -1);
$imgstr = ob_get_contents();
ob_end_clean();
return $imgstr;
}
//Generate MJPEG stream as test pattern
$img = TextToImage("MJPG-ReStreamer");
$img = imagecreatefromstring($img);
while(true) {
imageline($img,
rand(0,640),
rand(0,480),
rand(0,640),
rand(0,480),
imagecolorallocate($img, rand(0,255), rand(0,255), rand(0,255)));
ob_start();
imagejpeg($img, NULL, -1);
$imgstr = ob_get_contents();
ob_end_clean();
OutputImage($imgstr);
usleep(100*1000);
}
?>