Windows平台RTMP推送摄像头对接介绍
生活随笔
收集整理的這篇文章主要介紹了
Windows平台RTMP推送摄像头对接介绍
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
背景
好多開發者在對接大牛直播SDK(官方)的Windows平臺RTMP推送時,不熟悉攝像頭調用,實際上,攝像頭調用邏輯并不復雜,以下是大概流程:
對的,比如一個攝像頭有四個分辨率?(1920*1080,1080*720,640*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 List<NT_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博客
總結
以上是生活随笔為你收集整理的Windows平台RTMP推送摄像头对接介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【学术相关】李沐:如何把近十页的论文读成
- 下一篇: 【Python】一行python代码利用