该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"
}
}
相反,如果您使用以下gs://
格式的公共示例之一request.json
:
{
"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"
},
...