发送反馈
检测镜头变化
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
镜头变化分析 用于检测视频中的镜头变化。
本部分介绍分析视频以获取镜头变化的几种方法。
以下示例展示如何对 Cloud Storage 中的文件执行视频分析以获取镜头变化。
想要更深入了解其他内容?请查看我们的详细 Python 教程 。
REST
发送视频注解请求
下面演示了如何向 videos:annotate
方法发送 POST 请求。该示例使用 Google Cloud CLI 创建访问令牌。如需了解如何安装 gcloud CLI,请参阅 Video Intelligence API 快速入门 。
在使用任何请求数据之前,请先进行以下替换:
INPUT_URI :包含要添加注释的文件的 Cloud Storage 存储桶(包括文件名)。必须以 gs://
开头。
PROJECT_NUMBER :您的 Google Cloud 项目的数字标识符
HTTP 方法和网址:
POST https://videointelligence.googleapis.com/v1/videos:annotate
请求 JSON 正文:
{
"inputUri": "INPUT_URI ",
"features": ["SHOT_CHANGE_DETECTION"]
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-user-project: PROJECT_NUMBER " \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://videointelligence.googleapis.com/v1/videos:annotate"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER " } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://videointelligence.googleapis.com/v1/videos:annotate" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_NUMBER /locations/LOCATION_ID /operations/OPERATION_ID "
}
如果响应成功,Video Intelligence API 将返回您的操作的 name
。上面的示例展示了此类响应的示例,其中 project-name
是您的项目名称,operation-id
是为请求创建的长时间运行的操作的 ID。
PROJECT_NUMBER :您项目的编号
LOCATION_ID :在其中添加注解的 Cloud 区域。支持的云区域为:us-east1
、us-west1
、europe-west1
、asia-east1
。如果未指定区域,系统将根据视频文件位置确定区域。
OPERATION_ID :是为请求创建的长时间运行的操作的 ID,并在启动操作时在响应中提供,例如 12345....
获取注解结果
要检索操作的结果,请使用从 videos:annotate
调用返回的操作名称发出 GET 请求,如以下示例所示。
在使用任何请求数据之前,请先进行以下替换:
OPERATION_NAME :Video Intelligence API 返回的操作名称。操作名称采用 projects/PROJECT_NUMBER /locations/LOCATION_ID /operations/OPERATION_ID
格式
PROJECT_NUMBER :您的 Google Cloud 项目的数字标识符
HTTP 方法和网址:
GET https://videointelligence.googleapis.com/v1/OPERATION_NAME
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-user-project: PROJECT_NUMBER " \ "https://videointelligence.googleapis.com/v1/OPERATION_NAME "
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER " } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://videointelligence.googleapis.com/v1/OPERATION_NAME " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"inputUri": "/demomaker/gbikes_dinosaur.mp4",
"shotAnnotations": [
{
"startTimeOffset": "0s",
"endTimeOffset": "5.167104s"
},
{
"startTimeOffset": "5.236736s",
"endTimeOffset": "10.072064s"
},
{
"startTimeOffset": "10.106880s",
"endTimeOffset": "28.139520s"
},
{
"startTimeOffset": "28.174336s",
"endTimeOffset": "42.768384s"
}
]
}
镜头检测注释以 shotAnnotations
列表的形式返回。注意:仅当值为 True 时,才会返回 done 字段。操作未完成的响应中不包含该字段。
下载注解结果
将来源中的注解复制到目标存储桶(请参阅复制文件和对象 ):
gsutil cp gcs_uri gs://my-bucket
注意:如果输出 gcs uri 由用户提供,则注解存储在该 gcs uri 中。
Java
如需向 Video Intelligence 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证 。
Node.js
如需向 Video Intelligence 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证 。
发送反馈
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-03-29。
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]
需要向我们提供更多信息?