streaming.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from onvif import ONVIFCamera
  2. def media_profile_configuration():
  3. '''
  4. A media profile consists of configuration entities such as video/audio
  5. source configuration, video/audio encoder configuration,
  6. or PTZ configuration. This use case describes how to change one
  7. configuration entity which has been already added to the media profile.
  8. '''
  9. # Create the media service
  10. mycam = ONVIFCamera('192.168.1.64', 80, 'admin', 'intflow3121')
  11. media_service = mycam.create_media_service()
  12. profiles = media_service.GetProfiles()
  13. # Use the first profile and Profiles have at least one
  14. token = profiles[0]._token
  15. # Get all video encoder configurations
  16. configurations_list = media_service.GetVideoEncoderConfigurations()
  17. # Use the first profile and Profiles have at least one
  18. video_encoder_configuration = configurations_list[0]
  19. # Get video encoder configuration options
  20. options = media_service.GetVideoEncoderConfigurationOptions({'ProfileToken':token})
  21. # Setup stream configuration
  22. video_encoder_configuration.Encoding = 'H264'
  23. # Setup Resolution
  24. video_encoder_configuration.Resolution.Width = \
  25. options.H264.ResolutionsAvailable[0].Width
  26. video_encoder_configuration.Resolution.Height = \
  27. options.H264.ResolutionsAvailable[0].Height
  28. # Setup Quality
  29. video_encoder_configuration.Quality = options.QualityRange.Min
  30. # Setup FramRate
  31. video_encoder_configuration.RateControl.FrameRateLimit = \
  32. options.H264.FrameRateRange.Min
  33. # Setup EncodingInterval
  34. video_encoder_configuration.RateControl.EncodingInterval = \
  35. options.H264.EncodingIntervalRange.Min
  36. # Setup Bitrate
  37. video_encoder_configuration.RateControl.BitrateLimit = \
  38. options.Extension.H264[0].BitrateRange[0].Min[0]
  39. # Create request type instance
  40. request = media_service.create_type('SetVideoEncoderConfiguration')
  41. request.Configuration = video_encoder_configuration
  42. # ForcePersistence is obsolete and should always be assumed to be True
  43. request.ForcePersistence = True
  44. # Set the video encoder configuration
  45. media_service.SetVideoEncoderConfiguration(request)
  46. if __name__ == '__main__':
  47. media_profile_configuration()