java获取大华摄像头的rtsp地址和ip
时间: 2023-05-18 12:02:26 浏览: 190
通过RTSP协议捕获大华摄像机视频
5星 · 资源好评率100%
可以通过以下代码获取大华摄像头的rtsp地址和ip:
```java
import com.dahua.netsdk.linux.callback.fRealDataCallBackEx;
import com.dahua.netsdk.linux.structs.NET_DVR_DEVICEINFO_V30;
import com.dahua.netsdk.linux.structs.NET_DVR_PREVIEWINFO;
import com.dahua.netsdk.linux.structs.NET_DVR_STREAM_INFO;
import com.dahua.netsdk.linux.structs.NET_DVR_STREAM_MODE;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
public class DahuaCamera {
private static final String IP_ADDRESS = "192.168.1.64";
private static final String USERNAME = "admin";
private static final String PASSWORD = "admin123";
private static final int CHANNEL = 1;
private static final int STREAM_TYPE = 0;
private static final int CONNECT_TIMEOUT = 5000;
private static final int RECONNECT_INTERVAL = 5000;
private static final int REALPLAY_TYPE = 0;
private static final int DISPLAY_TYPE = 1;
private static final int BUFFER_SIZE = 1024 * 1024;
private static NativeLong lUserID = new NativeLong(-1);
private static NativeLong lRealPlayHandle = new NativeLong(-1);
private static fRealDataCallBackEx cbRealData = new fRealDataCallBackEx() {
@Override
public void invoke(NativeLong lRealHandle, int dwDataType, Pointer pBuffer, int dwBufSize, Pointer pUser) {
// do nothing
}
};
public static void main(String[] args) {
NET_DVR_DEVICEINFO_V30 deviceInfo = new NET_DVR_DEVICEINFO_V30();
lUserID = HCNetSDK.INSTANCE.NET_DVR_Login_V30(IP_ADDRESS, (short) 8000, USERNAME, PASSWORD, deviceInfo);
if (lUserID.longValue() == -1) {
System.out.println("Login failed: " + HCNetSDK.INSTANCE.NET_DVR_GetLastError());
return;
}
NET_DVR_PREVIEWINFO previewInfo = new NET_DVR_PREVIEWINFO();
previewInfo.lChannel = new NativeLong(CHANNEL);
previewInfo.dwStreamType = STREAM_TYPE;
previewInfo.dwLinkMode = 0;
previewInfo.bBlocked = true;
previewInfo.hHwnd = null;
NET_DVR_STREAM_INFO streamInfo = new NET_DVR_STREAM_INFO();
streamInfo.dwSize = streamInfo.size();
streamInfo.dwStreamID = new NativeLong(1);
streamInfo.dwField = 1;
streamInfo.dwChannel = new NativeLong(CHANNEL);
NET_DVR_STREAM_MODE streamMode = new NET_DVR_STREAM_MODE();
streamMode.dwSize = streamMode.size();
streamMode.byGetStreamType = 0;
streamMode.byRes1 = 0;
streamMode.byRes2 = 0;
streamMode.union = new NET_DVR_STREAM_MODE._union();
streamMode.union.getStream = streamInfo;
IntByReference error = new IntByReference();
lRealPlayHandle = HCNetSDK.INSTANCE.NET_DVR_RealPlay_V40(lUserID, previewInfo, cbRealData, null);
if (lRealPlayHandle.longValue() == -1) {
System.out.println("RealPlay failed: " + HCNetSDK.INSTANCE.NET_DVR_GetLastError());
return;
}
byte[] sOutBuffer = new byte[BUFFER_SIZE];
IntByReference pInt = new IntByReference(0);
if (!HCNetSDK.INSTANCE.NET_DVR_GetCurrentStreamURL(lRealPlayHandle, sOutBuffer, BUFFER_SIZE, pInt)) {
System.out.println("GetCurrentStreamURL failed: " + HCNetSDK.INSTANCE.NET_DVR_GetLastError());
return;
}
String rtspUrl = new String(sOutBuffer, 0, pInt.getValue());
System.out.println("RTSP URL: " + rtspUrl);
HCNetSDK.INSTANCE.NET_DVR_StopRealPlay(lRealPlayHandle);
HCNetSDK.INSTANCE.NET_DVR_Logout(lUserID);
}
}
```
其中,IP_ADDRESS、USERNAME、PASSWORD、CHANNEL、STREAM_TYPE 分别代表大华摄像头的IP地址、用户名、密码、通道号和码流类型。运行该代码后,会输出大华摄像头的RTSP地址。
阅读全文