1

来自这个 github: https ://github.com/GoogleCloudPlatform/python-docs-samples

我正在尝试测试视频智能 API 并进行标签分析。

import argparse
import sys
import time
import io
import base64

from google.cloud.gapic.videointelligence.v1beta1 import enums
from google.cloud.gapic.videointelligence.v1beta1 import (
    video_intelligence_service_client)
# [END imports]


#python labels.py /Users/rockbaek/tildawatch-contents/EpicSkillShot/M7-_VukSueY/SKT\ vs\ KT\ Game\ 3\ _\ Grand\ Finals\ S7\ LCK\ Spring\ 2017\ _\ KT\ Rolster\ vs\ SK\ Telecom\ T1\ G3\ 1080p-M7-_VukSueY.mp4

def analyze_labels_file(path):
    """ Detects labels given a file path. """
    video_client = (video_intelligence_service_client.
                    VideoIntelligenceServiceClient())
    features = [enums.Feature.LABEL_DETECTION]

    with io.open(path, "rb") as movie:
        content_base64 = base64.b64encode(movie.read())

    operation = video_client.annotate_video(
        '', features, input_content=content_base64)
    print('\nProcessing video for label annotations:')

    while not operation.done():
        sys.stdout.write('.')
        sys.stdout.flush()
        time.sleep(15)

    print('\nFinished processing.')

    # first result is retrieved because a single video was processed
    results = operation.result().annotation_results[0]

    for i, label in enumerate(results.label_annotations):
        print('Label description: {}'.format(label.description))
        print('Locations:')

        for l, location in enumerate(label.locations):
            positions = 'Entire video'
            if (location.segment.start_time_offset != -1 or
                    location.segment.end_time_offset != -1):
                positions = '{} to {}'.format(
                    location.segment.start_time_offset / 1000000.0,
                    location.segment.end_time_offset / 1000000.0)
            print('\t{}: {}'.format(l, positions))

        print('\n')

if __name__ == '__main__':
    # [START running_app]
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('path', help='GCS file path for label detection.')
    args = parser.parse_args()

    analyze_labels_file(args.path)
# [END running_app]
# [END full_tutorial]

然后我从终端 python labels.py MP4_FILE_PATH 运行它

过了一会儿,它失败了这个错误代码:

Traceback (most recent call last):
  File "labels.py", line 123, in <module>
    analyze_labels_file(args.path)
  File "labels.py", line 52, in analyze_labels_file
    '', features, input_content=content_base64)
  File "/Library/Python/2.7/site-packages/google/cloud/gapic/videointelligence/v1beta1/video_intelligence_service_client.py", line 237, in annotate_video
    self._annotate_video(request, options), self.operations_client,
  File "/Library/Python/2.7/site-packages/google/gax/api_callable.py", line 428, in inner
    return api_caller(api_call, this_settings, request)
  File "/Library/Python/2.7/site-packages/google/gax/api_callable.py", line 416, in base_caller
    return api_call(*args)
  File "/Library/Python/2.7/site-packages/google/gax/api_callable.py", line 376, in inner
    return a_func(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/google/gax/retry.py", line 144, in inner
    raise exc
google.gax.errors.RetryError: GaxError(Retry total timeout exceeded with exception, caused by <_Rendezvous of RPC that terminated with (StatusCode.DEADLINE_EXCEEDED, Deadline Exceeded)>)

请帮助为什么它不起作用!:(

4

2 回答 2

1

对于未来的访问者,我在使用 Cloud Speech API 时遇到了同样的错误。

我只是timeout在调用时增加了值operation.result。那解决了它。虽然这个片段不在 OP 的代码中,但它应该在 Google 的示例代码 OP 中提到。

operation.result(timeout=90)   # increase this numeric value
于 2018-08-11T18:19:28.960 回答
0

我用一个小视频尝试了你的代码,它对我来说似乎工作得很好。也许您正在达到某种形式的配额或限制(请参阅:https ://cloud-dot-devsite.googleplex.com/video-intelligence/limits )?我还运行了在 Google Storage 中加载并使用 Python 客户端库没有问题的大型视频。

其他尝试步骤:通过 curl 命令将请求发送到服务。

于 2017-07-05T21:07:57.183 回答