问题描述
from onvif import ONVIFCamera
camera = ONVIFCamera(<host>,<port>,<user>,<passwd>,adjust_time=True)
camera.create_media_service()
osd = camera.media.create_type('CreateOSD')
osd.OSD = {
'token': 'token0','Position': {
'Type': 'UpperLeft',},'TextString': {
'PlainText': 'TEST','Type': 'Plain','Type': 'Text','VideoSourceConfigurationToken': 'token1',}
response = camera.media.CreateOSD(osd)
print(response)
这是我的全部代码。
当我调用 GetServiceCapabilities() 时,OSD 返回 True,所以我认为我的相机确实支持 OSD。
解决方法
通过添加 VideoSourceConfigurationToken
解决了这个问题。
最终代码:
from onvif import ONVIFCamera
camera = ONVIFCamera(<host>,<port>,<user>,<passwd>,adjust_time=True)
camera.create_media_service()
profiles = camera.media.GetProfiles()
osd = camera.media.create_type('CreateOSD')
osd.OSD = {
'token': 'token0','Position': {
'Type': 'UpperLeft',},'TextString': {
'PlainText': 'TEST','Type': 'Plain','Type': 'Text','VideoSourceConfigurationToken': profiles[0].VideoSourceConfiguration.token,}
response = camera.media.CreateOSD(osd)
print(response)