熟悉EasyNVR產品的盆友們應該都知道,EasyNVR主要完成的是RTSP視頻流到RTMP/HLS/Flv的轉碼,並提供了一套api和一個可視化管理平臺來便於調用。同時支持ONVIF協議進行雲臺控制。總結一下就是,想用EasyNVR必須有RTSP協議的支持!想進行雲臺控制必須有ONVIF的支持!固然,rtsp轉碼到rtmp這個操做也能夠自行實現,例如最廣泛的就是Red5 + ffmpeg,只是須要本身手擼一個管理後端,這個工做量你們掂量。而使用Onvif協議最重要的應用就是對設備進行PTZ雲臺控制,PTZ控制包含轉動、變焦等。web
此篇博文主要討論經常使用的轉動和變焦(也就是放大縮小)後端
要進行設備PTZ控制,咱們首先須要獲取到設備的Device Service Address和此設備的用戶名密碼,這兩個流程和獲取流地址同樣。api
獲取設備的能力,而且能夠獲取到Media和PTZ的URI,使用這兩個URL能夠進行流和PTZ操做,這裏若是PTZ URI獲取不到意味着這個設備沒法支持PTZ控制安全
_tds__GetCapabilities* capabilities = soap_new__tds__GetCapabilities(proxyDevice, -1); tt__CapabilityCategory* category = new tt__CapabilityCategory; capabilities->Category = category; *(capabilities->Category) = tt__CapabilityCategory__All; _tds__GetCapabilitiesResponse* response = soap_new__tds__GetCapabilitiesResponse(proxyDevice, -1); if (SOAP_OK == proxyDevice->GetCapabilities(capabilities, response)) { if (response->Capabilities) { //Media URI: response->Capabilities->Media->XAddr; //PTZ URI: response->Capabilities->PTZ->XAddr; } }
使用上一步獲取到的Media URI獲取設備的Media Profile服務器
_trt__GetProfiles* getProfiles = soap_new__trt__GetProfiles(proxyMedia, -1); _trt__GetProfilesResponse* response = soap_new__trt__GetProfilesResponse(proxyMedia, -1); if (SOAP_OK == proxyMedia->GetProfiles(getProfiles, response)) { int size = response->__sizeProfiles; for (int i = 0; i < size; ++i) { if (response->Profiles[i]) { //Media Profile Token: response->Profiles[i]->token; //通常設備包含多個Profile Token,包含主碼流、子碼流、第三碼流 } } }
使用獲取的Media URI和Media Profile Token進行PTZ控制,這裏只考慮ContinuousMove,須要在中止的時候發送中止命令。網絡
_tptz__ContinuousMove* continuousMove = soap_new__tptz__ContinuousMove(ptzProxy, -1); _tptz__ContinuousMoveResponse* response = soap_new__tptz__ContinuousMoveResponse(ptzProxy, -1); continuousMove->ProfileToken = const_cast<char *>(profile.c_str()); tt__PTZSpeed* velocity = soap_new_tt__PTZSpeed(ptzProxy, -1); continuousMove->Velocity = velocity; tt__Vector2D* panTilt = soap_new_tt__Vector2D(ptzProxy, -1); continuousMove->Velocity->PanTilt = panTilt; continuousMove->Velocity->PanTilt->space = "http://www.onvif.org/ver10/tptz/PanTiltSpaces/VelocityGenericSpace"; tt__Vector1D* zoom = soap_new_tt__Vector1D(ptzProxy, -1); continuousMove->Velocity->Zoom = zoom; switch (command) { case LEFT: continuousMove->Velocity->PanTilt->x = -((float)speed / 10); continuousMove->Velocity->PanTilt->y = 0; break; case RIGHT: continuousMove->Velocity->PanTilt->x = ((float)speed / 10); continuousMove->Velocity->PanTilt->y = 0; break; case UP: continuousMove->Velocity->PanTilt->x = 0; continuousMove->Velocity->PanTilt->y = ((float)speed / 10); break; case DOWN: continuousMove->Velocity->PanTilt->x = 0; continuousMove->Velocity->PanTilt->y = -((float)speed / 10); break; case ZOOMIN: continuousMove->Velocity->Zoom->x = ((float)speed / 10); break; case ZOOMOUT: continuousMove->Velocity->Zoom->x = -((float)speed / 10); break; default: break; } if (ptzProxy->ContinuousMove(continuousMove, response) == SOAP_OK) //轉動成功
_tptz__Stop* stop = soap_new__tptz__Stop(ptzProxy, -1); _tptz__StopResponse* response = soap_new__tptz__StopResponse(ptzProxy, -1); stop->ProfileToken = const_cast<char*>(profile.c_str()); bool* pantilt = new bool; stop->PanTilt = pantilt; *(stop->PanTilt) = true; bool* zoom = new bool; stop->Zoom = zoom; *(stop->Zoom) = true; if (SOAP_OK == ptzProxy->Stop(stop, response)) //中止成功
EasyNVR是一款擁有完整、自主、可控知識產權,同時又可以具有軟硬一體功能的安防互聯網化流媒體服務器,可以經過簡單的網絡攝像機通道配置,將傳統監控行業裏面的高清網絡攝像機IP Camera、NVR等具備RTSP、Onvif協議輸出的設備接入到EasyNVR,EasyNVR可以將這些視頻源的音視頻數據進行拉取,轉換爲RTMP/HLS,進行全平臺終端H5直播(Web、Android、iOS),而且EasyNVR可以將視頻源的直播數據對接到第三方CDN網絡,實現互聯網級別的直播分發。詳情可訪問EasyNVR官網:http://www.easynvr.comsvg