Git Product home page Git Product logo

pyhikvision's Introduction

pyhikvision [一闪一闪亮晶晶,star一下好心情]

GitHub release python platform

  • 支持Linux,Windows下32位及64位系统
  • 针对官方接口文档中的基础类型做了Python映射,可以简化接口出入参编写复杂度
  • example中实现了海康威视设备用户登录,视频实时预览等基础功能,可供参考

注:该库融入了面向对象的概念,理论上理解本库后,对于后期迭代维护复杂度会大大降低

新变动

  • 视频预览使用tk代替win32gui,解决未响应及跨平台问题
  • 移除PC系统类型配置
  • 32/64位系统自动区分特定变量类型

分支 feature/rennbon 有rstp的实现,加了点异步能提升一些性能

配套理解sdk二次开发原理

提示

macOS开发推荐

虚拟工具:https://www.parallels.cn/pd/general/ 可以直接安装Linux和windows,且可以独立到应用级别,非常适合海康威视开发,比云服务器或者docker好用

海康威视资源下载

官方资源:https://open.hikvision.com/download/5cda567cf47ae80dd41a54b3?type=10 网盘:https://pan.baidu.com/s/1xe3wXH7CYIswPgx59y4XWg 提取码:oqd5

pyhikvision最新对应SDK版本如下:

开发环境初始化

1. venv(推荐,PyCharm直接启动即可)

2. conda环境 (需要安装conda,下载请跳转至https://anaconda.org/anaconda/conda)

packages.yml中prefix为conda env目录下子环境设置,需要结合自身系统环境修改

conda env create  -f .\packages.yml

快速启动

local_config.ini配置(主目录下config.ini修改为local_config.ini即可)

注意windows目录分隔符

[DEFAULT]
SDKPath: .dll或.so的根目录,会遍历加载,填根SDK目录即可
User: 摄像头访问用户名,需要在海康威视图形界面上自己配置
Password: 摄像头访问密码,需要在海康威视图形界面上自己配置
Port: 摄像头端口
IP: 摄像头ip

example启动方式

cd example
python xxx.py

SDK配置相关

Linux SDK加载107问题解决方案

  1. 将SDK动态库路径加入到LD_LIBRARY_PATH环境变量
# 修改系统预加载项,增加一行export
vim ~/.bashrc
export  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:{官方动态库MakeAll所对应的Linux中的绝对路径}:{官方动态库MakeAll/HCNetSDKCom/在Linux中的绝对路径}
source ~/.bashrc

  1. 在/etc/ld.so/conf下增加sdk路径
# 查看配置信息
cat /etc/ld.so.conf
# 如果有以下Include,建议在ld.so.conf.d下新建文件设置,这样隔离比较干净
include ld.so.conf.d/*.conf
# 切换到指定目录
cd /etc/ld.so.conf.d

vim hikvsdk.conf
# 加入以下2个路径
{官方动态库MakeAll所对应的Linux中的绝对路径}
{官方动态库MakeAll/HCNetSDKCom/在Linux中的绝对路径}

# 保存完后执行以下命令重新加载系统.so配置
ldconfig

注意:

{官方动态库MakeAll所对应的Linux中的绝对路径} {官方动态库MakeAll/HCNetSDKCom/在Linux中的绝对路径} 相对应的系统路径需要加最后需要加"/",因为该库Python的加载逻辑中没有拼接"/" 如:

/opt/hkws/lib/
/opt/hkws/lib/HCNetSDKCom/

维护及联系:

加入讨论群,记得标注 "hksdk",欢迎star支持

  1. 微信群(请加 WB343688972 好友或者扫码加好友, 按照指引进群)

  2. QQ群(901635269)

pyhikvision's People

Contributors

allen0125 avatar rennbon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyhikvision's Issues

error code 29

When I ran sdk_state.py on Ubuntu, I got this error:

loop[2] find 2 mac and 2 ip
ERROR:root:NET_DVR_Login_V40 用户登录失败: the error code is 29
ERROR:root:common_start 失败: the error code is29
ERROR:root:初始化Adapter失败

Then I initialize NET_DVR_Init, and call NET_DVR_SetLogToFile to print the following logs

[2020-05-19 20:39:27.347][INF] The COM:HCCoreBase ver is 1.0.0.3, 2019_10_29. Async:1.
[2020-05-19 20:39:27.347][INF] The COM:Core ver is 6.1.4.17, 2020_03_31. Async:1.
[2020-05-19 20:39:27.347][INF] This HCNetSDK ver is 6.1.4.17 Ver 2020_03_31.
[2020-05-19 20:39:27.349][INF] Login dev 192.168.31.214:8008.
[2020-05-19 20:39:27.352][INF] Private connect 192.168.31.214:8008 sock=37 this=0x6dc8f684 cmd=0x10000 port=56650
[2020-05-19 20:39:27.352][INF] LogonDev1 in[192.168.31.214:8008]
[2020-05-19 20:39:27.352][ERR] CCoreGlobalCtrlBase::LoadDSo, HPR_LoadDSo Failed, Path[libcrypto.so] syserror[115]
[2020-05-19 20:39:27.352][ERR] Load BASE_DLL_LIBEAY failed[syserr: 115]
[2020-05-19 20:39:27.352][ERR] CoreBase_CreateSSLTrans,CSSLTrans::LoadSSLLib
[2020-05-19 20:39:27.352][ERR] CHIKEncrypt::GenerateRSAKey, CoreBase_CreateSSLTrans FAILED, error[156]
[2020-05-19 20:39:27.352][ERR] CRSAKey::CreateRSAKey, GenerateRSAKey Failed
[2020-05-19 20:39:27.352][ERR] CRSAKey::Start, CreateRSAKey Failed
[2020-05-19 20:39:27.352][ERR] CCoreGlobalCtrlBase::GetRSAEncrypt, CRSAKey Start Failed
[2020-05-19 20:39:27.352][ERR] Interim_GenerateRSAKey, GetRSAEncrypt Failed
[2020-05-19 20:39:27.352][ERR] general public key error
[2020-05-19 20:39:27.355][ERR] LogonDev1[192.168.31.214]
[2020-05-19 20:39:27.355][ERR] [192.168.31.214:8008]PRO_LoginHikDevice fail[err=29].
[2020-05-19 20:39:27.355][ERR] CMemberMgrBase::AllocIndex2, MemberStart Failed, iIndex[0]

hikvision

which camera product was used in this project?

Linux 无法登录

旧版6.0 sdk 会出错误 41
新旧6.1 sdk 会出错误 29

经查可能是 sdk 位置问题, 执行 NET_DVR_SetSDKInitCfg 后正常, 如下

无标题

请检查

Q: example script to get events from video intercoms

hey @Rennbon or @allen0125

im not a developer, is it possible to have some example.py file for getting events from a videointercom system based on this SDK
so somekind of loop to get events like :

event type: COMM_ALARM_V30:

ALARMINFO_V30_ALARMTYPE_MOTION_DETECTION

event type: COMM_ALARM_VIDEO_INTERCOM:

VIDEO_INTERCOM_ALARM_ALARMTYPE_DOORBELL_RINGING
VIDEO_INTERCOM_ALARM_ALARMTYPE_DISMISS_INCOMING_CALL
VIDEO_INTERCOM_ALARM_ALARMTYPE_TAMPERING_ALARM

event type: COMM_UPLOAD_VIDEO_INTERCOM_EVENT:

VIDEO_INTERCOM_EVENT_EVENTTYPE_UNLOCK_LOG
VIDEO_INTERCOM_EVENT_EVENTTYPE_ILLEGAL_CARD_SWIPING_EVENT

much appreciated!!

Custom Dev Question

Hi,
I am new here and not a developer.
I came across this while looking for a solution for our business.
We are looking for a solution to:

  1. Capture Images from our CCTV system at specific times and upload to our Google Drive.
  2. Capture Videos at specific intervals for 10 sec clips and upload to our Google Drive.
    Is this something that you can develop for us as a solution?
    Thanks,
    Sumit

callback error

When I ran face_captured.py on Ubuntu, I got this:

Traceback (most recent call last):
  File "face_captured.py", line 33, in <module>
    data = adapter.setup_alarm_chan_v31(callbacks.msg_callback_v31(face_captured_cb), None)
TypeError: argument must be callable or integer function address

Also instant_preview.py

Traceback (most recent call last):
  File "face_captured.py", line 33, in <module>
    data = adapter.setup_alarm_chan_v31(callbacks.msg_callback_v31(face_captured_cb), None)
TypeError: argument must be callable or integer function address

Any idea what went wrong?

Thanks,

PS. I'm forking to translate it into English. Hope it's ok with you.

example/instant_preview2.py 不显示

Login successful,the userId is  0
start preview 成功 0
[2023-11-08 17:45:01.953][0x00004be4][DEBUG]- [SYSTRANS_Create] [59] [Version is:Baseline2.5.4.8, build20191204]
[2023-11-08 17:45:01.959][0x00004be4][ERROR]- [ST_HeaderInfo] [43] [Media header is:
494D4B48010200000400000100000000000000000000000081000000000000000000000000000000]
[2023-11-08 17:45:01.968][0x00004be4][INFO ]- [SYSTRANS_Create] [103] [Handle request!]
[2023-11-08 17:45:01.976][0x00004be4][INFO ]- [CTransformProxy::InitDemux] [581] [parser pointer request!]
[2023-11-08 17:45:01.981][0x00004be4][INFO ]- [CRTPDemux::InitDemux] [342] [new m_pFrameBuffer]
[2023-11-08 17:45:01.986][0x00004be4][INFO ]- [CRTPDemux::InitDemux] [343] [new m_pCopyFrame]
[2023-11-08 17:45:01.995][0x00004be4][INFO ]- [CRTPDemux::InitDemux] [344] [new m_pAudioBuff]
[2023-11-08 17:45:02.001][0x00004be4][INFO ]- [CMPEG2PSPack::InitPack] [150] [new PSPack m_pFrameBuffer]
callback 1
[2023-11-08 17:45:02.012][0x000059a8][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393879590], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393879590], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:02.093][0x000059a8][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [0]]
[2023-11-08 17:45:02.115][0x000059a8][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393879590], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393879590], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:02.140][0x000059a8][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [0]]
[2023-11-08 17:45:02.155][0x000059a8][WARN ]- [CRTPDemux::ProcessVideoFrame] [3068] [Pre-conditions not met, I frame has not been obtained!
]
[2023-11-08 17:45:02.168][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393883100], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393883100], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:02.197][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [39]]
[2023-11-08 17:45:02.212][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393883100], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393883100], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:02.248][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [39]]
[2023-11-08 17:45:02.274][0x00001218][WARN ]- [CRTPDemux::ProcessVideoFrame] [3068] [Pre-conditions not met, I frame has not been obtained!
]
[2023-11-08 17:45:02.293][0x00001218][DEBUG]- [CRTPDemux::InputData] [808] [Private frame Timestamp is [94]]
get_port success
set_stream_open_mode success
open_stream success
playM4_play success
[2023-11-08 17:45:03.349][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393886700], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393886700], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.363][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [79]]
[2023-11-08 17:45:03.368][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393886700], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393886700], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.383][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [79]]
[2023-11-08 17:45:03.390][0x00001218][WARN ]- [CRTPDemux::ProcessVideoFrame] [3068] [Pre-conditions not met, I frame has not been obtained!
]
[2023-11-08 17:45:03.397][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393890390], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393890390], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.413][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [120]]
[2023-11-08 17:45:03.419][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393890390], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393890390], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.433][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [120]]
[2023-11-08 17:45:03.440][0x00001218][WARN ]- [CRTPDemux::ProcessVideoFrame] [3068] [Pre-conditions not met, I frame has not been obtained!
]
[2023-11-08 17:45:03.448][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393893900], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393893900], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.464][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [159]]
[2023-11-08 17:45:03.469][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393893900], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393893900], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.482][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [159]]
[2023-11-08 17:45:03.491][0x00001218][WARN ]- [CRTPDemux::ProcessVideoFrame] [3068] [Pre-conditions not met, I frame has not been obtained!
]
[2023-11-08 17:45:03.499][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393897500], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393897500], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.516][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [199]]
[2023-11-08 17:45:03.525][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393897500], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393897500], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.542][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [199]]
[2023-11-08 17:45:03.548][0x00001218][WARN ]- [CRTPDemux::ProcessVideoFrame] [3068] [Pre-conditions not met, I frame has not been obtained!
]
[2023-11-08 17:45:03.560][0x00001218][DEBUG]- [CRTPDemux::InputData] [808] [Private frame Timestamp is [254]]
[2023-11-08 17:45:03.569][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393901100], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393901100], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.581][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [239]]
[2023-11-08 17:45:03.586][0x00001218][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393901100], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393901100], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.601][0x00001218][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [239]]
[2023-11-08 17:45:03.610][0x00001218][WARN ]- [CRTPDemux::ProcessVideoFrame] [3068] [Pre-conditions not met, I frame has not been obtained!
]
[2023-11-08 17:45:03.617][0x000059a8][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393904790], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393904790], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.631][0x000059a8][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [280]]
[2023-11-08 17:45:03.637][0x000059a8][DEBUG]- [CRTPDemux::GetDeltaTimeStampMS] [982] [nTrack is [0], fUnit is [90.000000], nTimeStamp is [1393904790], m_dwFirstFrameTime is [15487551], m_dwLastRTPTime is [1393904790], m_dwRTPTimeDelta is [0]]
[2023-11-08 17:45:03.652][0x000059a8][DEBUG]- [CRTPDemux::InputData] [777] [Video frame Timestamp is [280]]
[2023-11-08 17:45:03.659][0x000059a8][WARN ]- [CRTPDemux::ProcessVideoFrame] [3068] [Pre-conditions not met, I frame has not been obtained!

您好,我在执行instant_preview2.py时,遇到问题,但是这个库文件是我从官网下载的,有什么办法解决吗?

Load libopenal.so.1 fail!
Load libAudioRender.so fail!
Load libopenal.so.1 fail!
Load libAudioRender.so fail!
loop[2] find 2 mac and 2 ip
Login successful,the userId is 0
start preview 成功 0
callback 1
ERROR:root:没有找到接口!
ERROR:root:PlayM4_SetStreamOpenMode 设置流播放模式失败: the error code is 0
ERROR:root:port 没准备好,不可执行该操作

祝早日康复

今日接到需求,找到你的code,刚star完就看见你更新病了的状态。代码蛮好用的,谢谢整理。
祝早日康复!

病毒?

为啥把文件锁定了,不能删除

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.