昌邑做网站的公司,富顺做网站,深圳地区5g微波网站建设计划,广州致峰网站建设背景
好多开发者在对接大牛直播SDK#xff08;官方#xff09;的Windows平台RTMP推送时#xff0c;不熟悉摄像头调用#xff0c;实际上#xff0c;摄像头调用逻辑并不复杂#xff0c;以下是大概流程#xff1a;
首先调用我们sdk接口获取摄像头个数#xff0c;调用接口…背景
好多开发者在对接大牛直播SDK官方的Windows平台RTMP推送时不熟悉摄像头调用实际上摄像头调用逻辑并不复杂以下是大概流程
首先调用我们sdk接口获取摄像头个数调用接口是GetVideoCaptureDeviceNumber()接着需要获取每个摄像头的id和name调用接口是GetVideoCaptureDeviceInfo()接下来针对某个指定的摄像头需要获取它的分辨率列表个数, 调用接口是:GetVideoCaptureDeviceCapabilityNumber()根据摄像头id和分辨率的index,获取实际的分辨率调用接口:GetVideoCaptureDeviceCapability()
对的比如一个摄像头有四个分辨率 1920*10801080*720640*480 320*240 调用GetVideoCaptureDeviceCapabilityNumber 拿到的值就是4想拿第一个index的分辨率就传入GetVideoCaptureDeviceCapability(id, 0, capability)。
接口对接
以C#设计为例接口设计如下 /** 获取摄像头数量* * pNumer: 返回设备数量* * 成功返回 NT_ERC_OK*/[DllImport(SmartPublisherSDK.dll)]public static extern UInt32 NT_PB_GetVideoCaptureDeviceNumber(ref Int32 pNumer);/** 返回摄像头设备信息* * device_index: 设备索引* device_name_utf8: 设备名称传NULL将不返回名称如果不是NULL的话, device_name_length必须大于等于256, 返回utf8编码的设备名称* device_name_length: 设备名称缓冲大小如果device_name_utf8是NULL则传入0, 否则必须大于等于256* device_unique_id_utf8: 设备唯一ID, 传NULL将不返回ID,如果不传NULL的话device_unique_id_length必须大于等于1024返回utf8编码的设备ID* device_unique_id_length: 设备唯一ID缓冲代销, 如果是device_unique_id_utf8NULL, 则传入0否则必须大于等于1024* * 成功返回 NT_ERC_OK*/[DllImport(SmartPublisherSDK.dll)]public static extern UInt32 NT_PB_GetVideoCaptureDeviceInfo(Int32 device_index,[MarshalAs(UnmanagedType.LPStr)] StringBuilder device_name_utf8,UInt32 device_name_length,[MarshalAs(UnmanagedType.LPStr)] StringBuilder device_unique_id_utf8,UInt32 device_unique_id_length);/** 返回摄像头能力数* * device_unique_id_utf8: 设备唯一id* capability_number: 返回的设备能力数* * 成功返回 NT_ERC_OK*/[DllImport(SmartPublisherSDK.dll)]public static extern UInt32 NT_PB_GetVideoCaptureDeviceCapabilityNumber([MarshalAs(UnmanagedType.LPStr)] String device_unique_id_utf8,ref Int32 capability_number);/** 返回摄像头能力* * device_unique_id_utf8: 设备唯一id* device_capability_index: 设备能力索引* capability: 设备能力* * 成功返回 NT_ERC_OK*/[DllImport(SmartPublisherSDK.dll, EntryPoint NT_PB_GetVideoCaptureDeviceCapability, CallingConvention CallingConvention.StdCall)]public static extern UInt32 NT_PB_GetVideoCaptureDeviceCapability([MarshalAs(UnmanagedType.LPStr)] String device_unique_id_utf8,Int32 device_capability_index,ref NT_PB_VideoCaptureCapability capability);
调用逻辑如下 private void FillCameraInfo(){int device_number 0;if (NTBaseCodeDefine.NT_ERC_OK ! NTSmartPublisherSDK.NT_PB_GetVideoCaptureDeviceNumber(ref device_number)){return;}if (device_number 1){return;}cameras_.Clear();for (int i 0; i device_number; i){CameraInfo info new CameraInfo();info.capabilities_ new ListNT_PB_VideoCaptureCapability();StringBuilder name new StringBuilder(256);StringBuilder id new StringBuilder(1024);if (NTBaseCodeDefine.NT_ERC_OK ! NTSmartPublisherSDK.NT_PB_GetVideoCaptureDeviceInfo(i,name, 256,id, 1024)){continue;}info.name_ name.ToString();info.id_ id.ToString();int capability_number 0;if (NTBaseCodeDefine.NT_ERC_OK ! NTSmartPublisherSDK.NT_PB_GetVideoCaptureDeviceCapabilityNumber(id.ToString(), ref capability_number)){continue;}bool is_failed false;for (int j 0; j capability_number; j){NT_PB_VideoCaptureCapability capability new NT_PB_VideoCaptureCapability();if (NTBaseCodeDefine.NT_ERC_OK ! NTSmartPublisherSDK.NT_PB_GetVideoCaptureDeviceCapability(id.ToString(), j, ref capability)){is_failed true;break;}info.capabilities_.Add(capability);}if (!is_failed){cameras_.Add(info);}}}
在此之前需要设置是采集摄像头还是屏幕或者窗口 /*定义Video源选项*/public enum NT_PB_E_VIDEO_OPTION : uint{NT_PB_E_VIDEO_OPTION_NO_VIDEO 0x0,NT_PB_E_VIDEO_OPTION_SCREEN 0x1, // 采集屏幕NT_PB_E_VIDEO_OPTION_CAMERA 0x2, // 摄像头采集NT_PB_E_VIDEO_OPTION_LAYER 0x3, // 视频合并比如桌面叠加摄像头等NT_PB_E_VIDEO_OPTION_ENCODED_DATA 0x4, // 已经编码的视频数据目前支持H264NT_PB_E_VIDEO_OPTION_WINDOW 0x5, // 采集窗口}
更详细的集成参考参见Windows平台RTMP直播推送集成简要说明_乐学吧-CSDN博客