首页 > 解决方案 > how to use pssh python script using Python ProtoBuf library?

问题描述

I am not able to figure out how Python ProtoBuf library is related to use pssh python script in this documentation https://github.com/google/shaka-packager/tree/master/packager/tools/pssh

How can I build the pssh.py script without the proto file?

标签: protocol-buffersdrmwidevineshakaeme

解决方案


您可以将构建脚本与 shaka-packager 一起使用,也可以直接从widevine 头 proto 文件生成 python protobuf 文件。

Python的 Protocol Buffers教程很好地描述了如何使用 protoc 编译必要的 Python 代码。

如果您不想要或不需要任何其他 shaka-packager 的东西,而只想使用 pssh.py,那么您可以修改这部分:

# Append the local protobuf location.  Use a path relative to the tools/pssh
# folder where this file should be found.  This allows the file to be executed
# from any directory.
_pssh_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(_pssh_dir, '../../third_party/protobuf/python'))
# Import the widevine protobuf.  Use either Release or Debug.
_proto_path_format = os.path.join(
    _pssh_dir, '../../../out/%s/pyproto/packager/media/base')
if os.path.isdir(_proto_path_format % 'Release'):
  sys.path.insert(0, _proto_path_format % 'Release')
else:
  sys.path.insert(0, _proto_path_format % 'Debug')
try:
  import widevine_pssh_data_pb2  # pylint: disable=g-import-not-at-top
except ImportError:
  print >> sys.stderr, 'Cannot find proto file, make sure to build first'
  raise

只需保留import widevine_pssh_data_pb2并确保您使用 protoc 生成的代码位于 pssh.py 文件的路径中。然后它应该工作得很好。

你打算用 pssh.py 做什么?


推荐阅读