"#{$transcode}std{access=http{mime={$this->mime}},mux=ts{use-key-frames},dst=*:{$this->getPort()}/{$this->path}}";
$vlc_ifs = "-I http --http-host=0.0.0.0 --http-port {$this->getHttpPort()} -I telnet --telnet-port {$this->getTelnetPort()} --telnet-password ".TLPWD; if(VLC_USE_LOG) $vlc_logs = "--extraintf=http:logger --file-logging --log-verbose 0 --logfile {$this->getLogFile()}"; else $vlc_logs = '--extraintf=http'; //$vlc_shell = VLCBIN." --rtsp-tcp --ffmpeg-hw --http-reconnect --http-continuous --sout-keep ".VLCD." $vlc_ifs --repeat --loop --network-caching ".VLCNETCACHE." --sout-mux-caching ".VLCSOUTCACHE." $vlc_vlm --pidfile {$this->getPidFile()} $vlc_logs \n"; $vlc_shell = VLCBIN." --rtsp-tcp ".VLCD." $vlc_ifs --repeat --loop --live-caching ".VLC_LIVE_CACHE." --network-caching ".VLCNETCACHE." --sout-mux-caching ".VLCSOUTCACHE." --sout-ts-dts-delay 400 $vlc_vlm --pidfile {$this->getPidFile()} $vlc_logs "; if($this->isValgrind()){ $vlc_shell = "valgrind -v --trace-children=yes --log-file={$this->getValgrindFile()} --error-limit=no --leak-check=full $vlc_shell"; }
return "#std{access=file{append},mux=ts{use-key-frames},dst=$filePath.avi}";
$this->execute("new {$this->cam} broadcast enabled loop");
$command = "control {$this->cam} $command";
abstract class AbstractFactory { private static $instance = null; /** * @var array */ private $commands; /** * @return AbstractFactory */ public static function getInstance(){ if(self::$instance == null) self::$instance = new static; return self::$instance; } /** * permanentCommand * @param ICommand $command */ protected function addPermanentCommand(ICommand $command){ $this->commands[] = $command; } /** * @param ISystem $system */ protected function addCommands(ISystem $system){ foreach($this->commands as $command) $system->addPermanentCommand($command); } //todo buildSystem method /** * @return ISystem */ public function createSystem(){ return System::getInstance(); } /** * @return array of Users */ public function createUsers(){ return array(AbstractFactory::getInstance()->createUser(1)); } /** * @param int $id * @return IUser */ public function createUser($id) { return new User($id); } /** * @param IUser $user * @return IDVR */ public function createDvr(IUser $user) { $dvr = new Dvr($user); $cams = $this->createCams($dvr); //new+add foreach($cams as $cam){ /** @var $cam Cam */ $dvr->addCam($cam); } $daemons = $this->createDaemons($dvr); foreach($daemons as $daemon){ /** @var $daemon Daemon */ $dvr->addDaemon($daemon); } return $dvr; } /** * @param DVR $dvr * @return array of Cams */ abstract protected function createCams(DVR $dvr); /** * @param DVR $dvr * @return array of Daemons */ abstract protected function createDaemons(DVR $dvr); /** * @param IDVR $dvr * @param ICamSettings $cs * @return ICam */ public function createCam(IDVR $dvr, ICamSettings $cs) { return new Cam($dvr, $cs); } /** * @param $from * @param $to * @return MoveToNfsCommand */ public function createMoveToNfsCommand($from, $to){ return new MoveToNfsCommand($from, $to); } /** * @param ICam $cam * @return ICamStream */ abstract public function createStream(ICam $cam); }
public function start() { $this->log(__FUNCTION__); $this->startDaemons(); $this->startCams(); }
<?php /** * Created by PhpStorm. * User: calc * Date: 16.06.14 * Time: 10:56 */ namespace system2; /** * Class BBFactory * @package system2 */ class BBFactory extends AbstractFactory { /** * @return ISystem */ public function createSystem() { $system = parent::createSystem(); $e = new BBLogMotionEvent(Motion::EVENT_MOTION_START); $system->addEventHandler($e); $e = new BBLogMotionEvent(Motion::EVENT_MOTION_STOP); $system->addEventHandler($e); $e = new BBLogMotionEvent(Motion::EVENT_MOTION_DETECTED); $system->addEventHandler($e); $e = new BBLogMotionEvent(Motion::EVENT_CAMERA_LOSS); $system->addEventHandler($e); $recMotionEvent = new BBRecMotionEvent(Motion::EVENT_MOTION_START); $system->addEventHandler($recMotionEvent); $recMotionEvent = new BBRecMotionEvent(Motion::EVENT_MOTION_STOP); $system->addEventHandler($recMotionEvent); // 30 update //$system->addPermanentCommand(new RotateRecCommand()); $this->addPermanentCommand(new RotateRecCommand()); $this->addCommands($system); return $system; } /** * @param DVR $dvr * @return array of Daemons */ protected function createDaemons(DVR $dvr) { $vlc = new Vlc($dvr); $this->addPermanentCommand(new BBDaemonWatchdog($vlc)); // , mtn $cams = $dvr->getCamIDs(); $ids = array(); foreach($cams as $id){ $cam = $dvr->getCam($id); $cs = $cam->getSettings(); /** @var $cs BBCamSettings */ if($cs->mtn) $ids[] = $id; } $motion = new Motion($dvr, $ids); if(count($cams)) $this->addPermanentCommand(new BBDaemonWatchdog($motion)); return array($vlc, $motion); } /** * @return array */ public function createUsers() { $users = array(); $db = \Database::getInstance(); $q = "select id from users where banned=0"; $r = $db->query($q); while(($row = $r->fetch_row())){ try{ $users[] = AbstractFactory::getInstance()->createUser($row[0]); } catch(\Exception $e){ Log::getInstance()->put($e->getCode().' '.$e->getMessage()."\n".$e->getTraceAsString()."\n", __CLASS__, Log::ERROR); } } return $users; } /** * @param DVR $dvr * @return array */ protected function createCams(DVR $dvr){ $db = \Database::getInstance(); $q = mysql::getQuery(mysql::CAM_SETTINGS, array('{dvr_id}' => $dvr->getID())); $r = $db->query($q); $cams = array(); while(($row = $r->fetch_object('system2\BBCamSettings')) != null){ /** @var BBCamSettings $row */ //$dvr->addCam(new BBCam($this, $row)); $cam = $this->createCam($dvr, $row); $cams[] = $cam; // Motion , $timelapse = new BBArchiveTimelapseCommand($cam); $this->addPermanentCommand($timelapse); } return $cams; } /** * @param ICam $cam * @return ICamStream */ public function createStream(ICam $cam) { $stream = new Streams($cam); $cs = $cam->getSettings(); /** @var $cs BBCamSettings */ $motion = new MotionStream($cam, $cs); $motion->setEnabled($cs->live && $cs->mtn); $stream->addStream($motion); $live = new BBLiveStream($cam); $live->setTestInputCommand(new BBTestInputFailSaveCommand($cam, $live)); $live->setEnabled($cs->live); $stream->addStream($live); $hls = new HLSVlcStream($cam, $live); $hls->setEnabled($cs->live); $stream->addStream($hls); //$this->streams[] = new FlvVlcReStream($this, $live); //nginx rtmp stream //$this->streams[] = new RtmpVlcReStream($this, $live); $rec = new BBRecStream($cam, $live); $rec->setEnabled($cs->live && $cs->rec); $rec->setTestInputCommand(new BBTestInputFailSaveCommand($cam, $rec)); $stream->addStream($rec); $mtn = new BBRecStream($cam, $live, TIME_LOCK_RECORD, Path::MOTION); $mtn->setEnabled($cs->live && $cs->mtn && BBRecMotionEvent::isMotion($cam)); $mtn->setTestInputCommand(new BBTestInputFailSaveCommand($cam, $mtn)); $stream->addStream($mtn, Path::MOTION); //motion flv stream $flv = new UrlFlvVlcStream($cam, "http://localhost:".(MOTION_STREAM_PORT + $cam->getID())); $flv->setEnabled($cs->live); $stream->addStream($flv); return $stream; } }
# Command to be executed when an event starts. (default: none) # An event starts at first motion detected after a period of no motion defined by event_gap on_event_start php ~/dvr/bin/system2/main.php event {user_id} {cam_id} motion_start 0 "%Y-%m-%d %T" # Command to be executed when an event ends after a period of no motion # (default: none). The period of no motion is defined by option event_gap. on_event_end php ~/dvr/bin/system2/main.php event {user_id} {cam_id} motion_stop 0 "%Y-%m-%d %T" # Command to be executed when a picture (.ppm|.jpg) is saved (default: none) # To give the filename as an argument to a command append it with %f ; on_picture_save value # Command to be executed when a motion frame is detected (default: none) ; on_motion_detected php ~/dvr/bin/system2/main.php event {user_id} {cam_id} motion_detected 0 "%Y-%m-%d %T" # Command to be executed when motion in a predefined area is detected # Check option 'area_detect'. (default: none) ; on_area_detected value # Command to be executed when a movie file (.mpg|.avi) is created. (default: none) # To give the filename as an argument to a command append it with %f ; on_movie_start value # Command to be executed when a movie file (.mpg|.avi) is closed. (default: none) # To give the filename as an argument to a command append it with %f ; on_movie_end value # Command to be executed when a camera can't be opened or if it is lost # NOTE: There is situations when motion don't detect a lost camera! # It depends on the driver, some drivers dosn't detect a lost camera at all # Some hangs the motion thread. Some even hangs the PC! (default: none) on_camera_lost php ~/dvr/bin/system2/main.php event {user_id} {cam_id} motion_camera_lost 0 "%Y-%m-%d %T"
$this->executeCommands(); $this->executePermanentCommands();
Source: https://habr.com/ru/post/234139/
All Articles