이 페이지에서는 curl
을 사용해서 Video Intelligence API 요청을 수행하는 방법을 보여줍니다.
이 페이지의 단계를 따르거나 Google Cloud 교육 실습으로 빠른 시작을 사용할 수 있습니다.
시작하기 전에
-
Google 계정으로
로그인합니다.
아직 계정이 없으면 새 계정을 등록하세요.
-
Google Cloud Console의 프로젝트 선택기 페이지에서 Google Cloud 프로젝트를 선택하거나 만듭니다.
-
Cloud 프로젝트에 결제가 사용 설정되어 있는지 확인합니다. 프로젝트에 결제가 사용 설정되어 있는지 확인하는 방법을 알아보세요.
- 필요한 API를 사용 설정합니다.
-
인증 설정:
-
Cloud Console에서 서비스 계정 키 만들기 페이지로 이동합니다.
서비스 계정 키 만들기 페이지로 이동 - 서비스 계정 목록에서 새 서비스 계정을 선택합니다.
- 서비스 계정 이름 필드에 이름을 입력합니다.
- 역할 목록에서 값을 선택하지 않습니다. 이 서비스에 액세스해야 할 역할이 없습니다.
- 만들기를 클릭합니다. 이 서비스 계정에 역할 없다는 경고가 표시됩니다.
- 역할 없이 만들기를 클릭합니다. 키가 포함된 JSON 파일이 컴퓨터에 다운로드됩니다.
-
-
GOOGLE_APPLICATION_CREDENTIALS
환경 변수를 서비스 계정 키가 포함된 JSON 파일의 경로로 설정합니다. 이 변수는 현재 셸 세션에만 적용되므로, 새 세션을 열 경우, 변수를 다시 설정합니다. - Cloud SDK 설치 및 초기화
동영상에 주석 추가 요청 만들기
gcloud
gcloud
명령줄 도구를 사용하여 분석할 동영상 경로에서 detect-labels
명령어를 호출합니다.
gcloud ml video detect-labels gs://your_bucket/your_object
명령줄
curl
을 사용하여videos:annotate
메서드에 대해 POST 요청을 수행합니다.gcloud auth application-default print-access-token
명령어를 사용하여 서비스 계정에 액세스 토큰을 붙여넣습니다.curl -X POST \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ -H "Content-Type: application/json; charset=utf-8" \ --data "{ "inputUri":"gs://your_bucket/your_object", "features": [ "LABEL_DETECTION" ] }" "https://videointelligence.googleapis.com/v1/videos:annotate"
Video Intelligence API가 요청을 처리하는 작업을 만듭니다. 응답에는 작업 이름이 포함됩니다.
{ "name": "projects/project-number/locations/location-id/operations/operation-id" }
v1.operations
엔드포인트를 호출하고, 아래 예시의 operation-name을 이전 단계에서 반환된 이름으로 바꿔서 작업에 대한 정보를 요청할 수 있습니다.curl -X GET \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ https://videointelligence.googleapis.com/v1/operation-name
작업과 관련된 정보가 표시됩니다. 작업이 완료되면
done
필드가 포함되고true
로 설정됩니다.{ "name": "projects/project-number/locations/location-id/operations/operation-id", "metadata": { "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress", "annotationProgress": [ { "inputUri": "/your_bucket/your_object", "progressPercent": 100, "startTime": "2020-04-01T22:13:17.978847Z", "updateTime": "2020-04-01T22:13:29.576004Z" } ] }, "done": true, ... }
요청을 잠시(보통 1분 정도) 기다리면 동일한 요청이 주석 결과를 반환합니다.
{ "name": "projects/project-number/locations/location-id/operations/operation-id", "metadata": { "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress", "annotationProgress": [ { "inputUri": "your_bucket/your_object", "progressPercent": 100, "startTime": "2020-04-01T22:13:17.978847Z", "updateTime": "2020-04-01T22:13:29.576004Z" } ] }, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoResponse", "annotationResults": [ { "inputUri": "/your_bucket/your_object", "segmentLabelAnnotations": [ { "entity": { "entityId": "/m/07bsy", "description": "transport", "languageCode": "en-US" }, "segments": [ { "segment": { "startTimeOffset": "0s", "endTimeOffset": "38.757872s" }, "confidence": 0.81231534 } ] }, { "entity": { "entityId": "/m/01n32", "description": "city", "languageCode": "en-US" }, "categoryEntities": [ { "entityId": "/m/043rvww", "description": "geographical feature", "languageCode": "en-US" } ], "segments": [ { "segment": { "startTimeOffset": "0s", "endTimeOffset": "38.757872s" }, "confidence": 0.3942462 } ] }, ... { "entity": { "entityId": "/m/06gfj", "description": "road", "languageCode": "en-US" }, "segments": [ { "segment": { "startTimeOffset": "0s", "endTimeOffset": "38.757872s" }, "confidence": 0.86698604 } ] } ] } ] } }
수고하셨습니다. 첫 번째 요청을 Video Intelligence API에 보냈습니다.
정리
불필요한 Google Cloud Platform 요금을 지출하지 않으려면 Cloud Console을 사용하여 필요하지 않은 프로젝트를 삭제해야 합니다.