请求视频注释时,curl毫无回报



嗨,我正在遵循此处的说明,请求视频注释处理。

curl -s -H 'Content-Type: application/json' -H 'Authorization: Bearer ACCESS_TOKEN_PASTED_HERE' 'https://videointelligence.googleapis.com/v1/videos:annotate' -d @request.json

我的JSON文件包括指向项目存储在项目存储的视频文件的公共链接。

    {
   "inputUri":"https://storage.googleapis.com/PROJECT_URL_HERE/video.mp4",
   "features": [
       "LABEL_DETECTION"
    ]
    }

我应该以操作名称获得回复:

视频智能API创建了一个操作来处理您的 要求。响应包括操作名称:

{" name":" us-west1.18358601230245040268"}

我得到的实际结果一无所有,甚至不是错误。等待片刻,然后是空白命令行。

我的仪表板显示了我的凭据的成功创建,但在视频智能API上没有显示任何活动。

谢谢!

inputUri字段必须是格式gs://BUCKET_NAME/path/to/video中的有效GCS路径,如此处所述,而不是您正在使用的https://storage.googleapis.com链接。否则,它应该返回google.rpc.Code.INVALID_ARGUMENT。如果您没有获得任何输出,则可能是语法错误(请参见下面的步骤)。就我而言,它读取:

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT"
  }
}

如果您使用request.json中的gs://格式的公共示例之一:

{
   "inputUri":"gs://cloud-ml-sandbox/video/chicago.mp4",
   "features": [
       "LABEL_DETECTION"
   ]
}

然后通过运行以下内容来激活服务帐户,并请求视频注释:

gcloud auth activate-service-account --key-file=/path/to/credentials.json
curl -s -H "Content-Type: application/json" 
        -H "Authorization: Bearer $(gcloud auth print-access-token)" 
           "https://videointelligence.googleapis.com/v1/videos:annotate" 
        -d @request.json

您会得到一个回应:

{
  "name": "europe-west1.16***************80"
}

拥有操作名称后,您可以使用以下方式检查状态:

curl -s -H "Content-Type: application/json" 
    -H "Authorization: Bearer $(gcloud auth print-access-token)" 
    "https://videointelligence.googleapis.com/v1/operations/europe-west1.16***************80" > result.json

验证它是否完成:

cat result.json | grep done

如果完成,应该输出:

"done": true,

result.json将包含请求的注释:

"annotationResults": [
  {
    "inputUri": "/cloud-ml-sandbox/video/chicago.mp4",
    "segmentLabelAnnotations": [
      {
        "entity": {
          "entityId": "/m/0pg52",
          "description": "taxi",
          "languageCode": "en-US"
        },
        ...