async def setup_move(): mycam = ONVIFCamera(IP, PORT, USER, PASS) await mycam.update_xaddrs() # Create media service object media = mycam.createService('media') # Create ptz service object global ptz ptz = mycam.createService('ptz') # Get target profile media_profile = await media.GetProfiles()[0] # Get PTZ configuration options for getting continuous move range request = ptz.create_type('GetConfigurationOptions') request.ConfigurationToken = media_profile.PTZConfiguration.token ptz_configuration_options = await ptz.GetConfigurationOptions(request) global moverequest moverequest = ptz.create_type('ContinuousMove') moverequest.ProfileToken = media_profile.token if moverequest.Velocity is None: moverequest.Velocity = await ptz.GetStatus({'ProfileToken': media_profile.token}).Position # Get range of pan and tilt # NOTE: X and Y are velocity vector global XMAX, XMIN, YMAX, YMIN XMAX = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].XRange.Max XMIN = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].XRange.Min YMAX = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].YRange.Max YMIN = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].YRange.Min
async def run(): mycam = ONVIFCamera('192.168.3.7', 80, 'hass', 'peek4boo') #, no_cache=True) await mycam.update_xaddrs() event_service = mycam.createService('events') properties = await event_service.GetEventProperties() print(properties) pullpoint = mycam.createService('pullpoint') req = pullpoint.create_type('PullMessages') req.MessageLimit = 100 req.Timeout = 30 messages = await pullpoint.PullMessages(req) print(messages)
async def rotate_image_180(): ''' Rotate the image ''' # Create the media service mycam = ONVIFCamera('192.168.0.112', 80, 'admin', '12345') await mycam.update_xaddrs() media_service = mycam.createService('media') profiles = await media_service.GetProfiles() # Use the first profile and Profiles have at least one token = profiles[0].token # Get all video source configurations configurations_list = await media_service.GetVideoSourceConfigurations() # Use the first profile and Profiles have at least one video_source_configuration = configurations_list[0] # Enable rotate video_source_configuration.Extension[0].Rotate[0].Mode[0] = 'OFF' # Create request type instance request = media_service.create_type('SetVideoSourceConfiguration') request.Configuration = video_source_configuration # ForcePersistence is obsolete and should always be assumed to be True request.ForcePersistence = True # Set the video source configuration await media_service.SetVideoSourceConfiguration(request)
async def media_profile_configuration(): ''' A media profile consists of configuration entities such as video/audio source configuration, video/audio encoder configuration, or PTZ configuration. This use case describes how to change one configuration entity which has been already added to the media profile. ''' # Create the media service mycam = ONVIFCamera('192.168.0.112', 80, 'admin', '12345') await mycam.update_xaddrs() media_service = mycam.createService('media') profiles = await media_service.GetProfiles() # Use the first profile and Profiles have at least one token = profiles[0].token # Get all video encoder configurations configurations_list = await media_service.GetVideoEncoderConfigurations() # Use the first profile and Profiles have at least one video_encoder_configuration = configurations_list[0] # Get video encoder configuration options options = await media_service.GetVideoEncoderConfigurationOptions({'ProfileToken':token}) # Setup stream configuration video_encoder_configuration.Encoding = 'H264' # Setup Resolution video_encoder_configuration.Resolution.Width = \ options.H264.ResolutionsAvailable[0].Width video_encoder_configuration.Resolution.Height = \ options.H264.ResolutionsAvailable[0].Height # Setup Quality video_encoder_configuration.Quality = options.QualityRange.Min # Setup FramRate video_encoder_configuration.RateControl.FrameRateLimit = \ options.H264.FrameRateRange.Min # Setup EncodingInterval video_encoder_configuration.RateControl.EncodingInterval = \ options.H264.EncodingIntervalRange.Min # Setup Bitrate video_encoder_configuration.RateControl.BitrateLimit = \ options.Extension.H264[0].BitrateRange[0].Min[0] # Create request type instance request = media_service.create_type('SetVideoEncoderConfiguration') request.Configuration = video_encoder_configuration # ForcePersistence is obsolete and should always be assumed to be True request.ForcePersistence = True