├── MIT-LICENSE.txt ├── README.md ├── Web ├── camera.html └── index.html ├── composer.json ├── start.php ├── start_web.php └── start_worker.php /MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2009-2015 walkor and contributors (see https://github.com/walkor/workerman/contributors) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # live-camera 2 | 网络摄像头-基于HTML5+Canvas+Websocket+[Workerman](http://www.workerman.net) 3 | 4 | ## 在线示例 5 | 6 | 提示:最好用火狐测试,谷歌浏览器升级了安全策略,谷歌浏览器只能在https下才能利用html5打开摄像头。 7 | 8 | 1、摄像头录制页面 http://www.workerman.net/demos/live-camera/camera.html 9 | 10 | 2、实时接收视频流页面 http://www.workerman.net/demos/live-camera/ 11 | 12 | 13 | ## 使用方法(linux 系统) 14 | 15 | 1、下载 或者 ```git clone https://github.com/walkor/live-camera``` 16 | 17 | 2、运行 ```composer install``` 18 | 19 | 3、运行 php start.php start -d 20 | 21 | 4、录制摄像的页面为 http://127.0.0.1:8088/camera.html 22 | 23 | 5、接收视频流的页面为 http://127.0.0.1:8088/ 24 | 25 | -------------------------------------------------------------------------------- /Web/camera.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | live cam 录像页面 5 | 6 | 7 | 8 |
9 | 提示:最好用火狐测试,谷歌浏览器升级了安全策略,谷歌浏览器只能在https下才能利用html5打开摄像头。 10 | 11 | 12 | 13 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | live cam 接收页面 5 | 6 | 7 | 8 |

如果显示空白,说明当前没有人在直播,点击这里直播 9 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "workerman/live-camera", 3 | "type" : "project", 4 | "keywords": ["web","camera"], 5 | "homepage": "http://www.workerman.net", 6 | "license" : "MIT", 7 | "require": { 8 | "workerman/workerman" : "~4.0.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /start.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright walkor 11 | * @link http://www.workerman.net/ 12 | * @license http://www.opensource.org/licenses/mit-license.php MIT License 13 | */ 14 | use \Workerman\Worker; 15 | use Workerman\Protocols\Http\Request; 16 | use Workerman\Protocols\Http\Response; 17 | use Workerman\Connection\TcpConnection; 18 | 19 | require_once __DIR__ . '/vendor/autoload.php'; 20 | 21 | // WebServer 22 | $web = new Worker("http://0.0.0.0:8088"); 23 | // WebServer数量 24 | $web->count = 2; 25 | $web->name = 'web'; 26 | 27 | define('WEBROOT', __DIR__ . DIRECTORY_SEPARATOR . 'Web'); 28 | 29 | $web->onMessage = function (TcpConnection $connection, Request $request) { 30 | $path = $request->path(); 31 | if ($path === '/') { 32 | $connection->send(exec_php_file(WEBROOT.'/index.html')); 33 | return; 34 | } 35 | $file = realpath(WEBROOT. $path); 36 | if (false === $file) { 37 | $connection->send(new Response(404, array(), '

404 Not Found

')); 38 | return; 39 | } 40 | // Security check! Very important!!! 41 | if (strpos($file, WEBROOT) !== 0) { 42 | $connection->send(new Response(400)); 43 | return; 44 | } 45 | if (\pathinfo($file, PATHINFO_EXTENSION) === 'php') { 46 | $connection->send(exec_php_file($file)); 47 | return; 48 | } 49 | 50 | $if_modified_since = $request->header('if-modified-since'); 51 | if (!empty($if_modified_since)) { 52 | // Check 304. 53 | $info = \stat($file); 54 | $modified_time = $info ? \date('D, d M Y H:i:s', $info['mtime']) . ' ' . \date_default_timezone_get() : ''; 55 | if ($modified_time === $if_modified_since) { 56 | $connection->send(new Response(304)); 57 | return; 58 | } 59 | } 60 | $connection->send((new Response())->withFile($file)); 61 | }; 62 | 63 | function exec_php_file($file) { 64 | \ob_start(); 65 | // Try to include php file. 66 | try { 67 | include $file; 68 | } catch (\Exception $e) { 69 | echo $e; 70 | } 71 | return \ob_get_clean(); 72 | } 73 | 74 | 75 | // 如果不是在根目录启动,则运行runAll方法 76 | if(!defined('GLOBAL_START')) 77 | { 78 | Worker::runAll(); 79 | } 80 | -------------------------------------------------------------------------------- /start_worker.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright walkor 11 | * @link http://www.workerman.net/ 12 | * @license http://www.opensource.org/licenses/mit-license.php MIT License 13 | */ 14 | use \Workerman\Worker; 15 | use \Workerman\Protocols\Websocket; 16 | 17 | require_once __DIR__ . '/vendor/autoload.php'; 18 | 19 | $recv_worker = new Worker('Websocket://0.0.0.0:8080'); 20 | $recv_worker->onWorkerStart = function($recv_worker) 21 | { 22 | $send_worker = new Worker('Websocket://0.0.0.0:8008'); 23 | $send_worker->onMessage = function($connection, $data) 24 | { 25 | }; 26 | $recv_worker->sendWorker = $send_worker; 27 | $send_worker->listen(); 28 | }; 29 | 30 | $recv_worker->onMessage = function($connection, $data)use($recv_worker) 31 | { 32 | foreach($recv_worker->sendWorker->connections as $send_connection) 33 | { 34 | //$send_connection->websocketType = "\x82"; 35 | $send_connection->send($data); 36 | } 37 | }; 38 | 39 | // 如果不是在根目录启动,则运行runAll方法 40 | if(!defined('GLOBAL_START')) 41 | { 42 | Worker::runAll(); 43 | } 44 | --------------------------------------------------------------------------------