熟悉EasyNVR产品的盆友们应该都知道,EasyNVR主要完成的是RTSP视频流到RTMP/HLS/Flv的转码,并提供了一套api和一个可视化管理平台来便于调用。同时支持ONVIF协议进行云台控制。总结一下就是,想用EasyNVR必须有RTSP协议的支持!想进行云台控制必须有ONVIF的支持!当然,rtsp转码到rtmp这个操作也可以自行实现,例如最普遍的就是Red5 + ffmpeg,只是需要自己手撸一个管理后端,这个工作量大家掂量。而使用Onvif协议最重要的应用就是对设备进行PTZ云台控制,PTZ控制包含转动、变焦等。
此篇博文主要讨论常用的转动和变焦(也就是放大缩小)
要进行设备PTZ控制,我们首先需要获取到设备的Device Service Address和此设备的用户名密码,这两个流程和获取流地址一样。
获取设备的能力,并且可以获取到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(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(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.com