Google Cloud Video Intelligence 運算子¶
先決條件任務¶
要使用這些運算子,您必須執行以下幾項操作:
使用 Cloud Console 選擇或建立一個 Cloud Platform 專案。
為您的專案啟用結算功能,如 Google Cloud 文件中所述。
啟用 API,如 Cloud Console 文件中所述。
透過 pip 安裝 API 庫。
pip install 'apache-airflow[google]'有關詳細資訊可參閱 安裝。
CloudVideoIntelligenceDetectVideoLabelsOperator¶
執行影片標註,標註影片標籤。
有關引數定義,請參閱 CloudVideoIntelligenceDetectVideoLabelsOperator
使用運算子¶
輸入 uri 是 Google Cloud Storage 中檔案的 uri
tests/system/google/cloud/video_intelligence/example_video_intelligence.py
INPUT_URI = f"gs://{BUCKET_NAME_DST}/{FILE_NAME}"
tests/system/google/cloud/video_intelligence/example_video_intelligence.py
detect_video_label = CloudVideoIntelligenceDetectVideoLabelsOperator(
input_uri=INPUT_URI,
output_uri=None,
video_context=None,
timeout=5,
task_id="detect_video_label",
)
您可以透過 Xcom 使用標註輸出
tests/system/google/cloud/video_intelligence/example_video_intelligence.py
detect_video_label_result = BashOperator(
bash_command="echo {{ task_instance.xcom_pull('detect_video_label')"
"['annotationResults'][0]['shotLabelAnnotations'][0]['entity']}}",
task_id="detect_video_label_result",
)
模板¶
template_fields: Sequence[str] = (
"input_uri",
"output_uri",
"gcp_conn_id",
"impersonation_chain",
)
更多資訊¶
注意:影片標註操作的持續時間等於或長於要標註的影片本身。
CloudVideoIntelligenceDetectVideoExplicitContentOperator¶
執行影片標註,標註明確內容。
有關引數定義,請參閱 CloudVideoIntelligenceDetectVideoExplicitContentOperator
引數¶
輸入 uri 是 Google Cloud Storage 中檔案的 uri
tests/system/google/cloud/video_intelligence/example_video_intelligence.py
INPUT_URI = f"gs://{BUCKET_NAME_DST}/{FILE_NAME}"
使用運算子¶
tests/system/google/cloud/video_intelligence/example_video_intelligence.py
detect_video_explicit_content = CloudVideoIntelligenceDetectVideoExplicitContentOperator(
input_uri=INPUT_URI,
output_uri=None,
video_context=None,
retry=Retry(maximum=10.0),
timeout=5,
task_id="detect_video_explicit_content",
)
您可以透過 Xcom 使用標註輸出
tests/system/google/cloud/video_intelligence/example_video_intelligence.py
detect_video_explicit_content_result = BashOperator(
bash_command="echo {{ task_instance.xcom_pull('detect_video_explicit_content')"
"['annotationResults'][0]['explicitAnnotation']['frames'][0]}}",
task_id="detect_video_explicit_content_result",
)
模板¶
template_fields: Sequence[str] = (
"input_uri",
"output_uri",
"gcp_conn_id",
"impersonation_chain",
)
更多資訊¶
注意:影片標註操作的持續時間等於或長於要標註的影片本身。
CloudVideoIntelligenceDetectVideoShotsOperator¶
執行影片標註,標註明確內容。
有關引數定義,請參閱 CloudVideoIntelligenceDetectVideoShotsOperator
引數¶
輸入 uri 是 Google Cloud Storage 中檔案的 uri
tests/system/google/cloud/video_intelligence/example_video_intelligence.py
INPUT_URI = f"gs://{BUCKET_NAME_DST}/{FILE_NAME}"
使用運算子¶
tests/system/google/cloud/video_intelligence/example_video_intelligence.py
detect_video_shots = CloudVideoIntelligenceDetectVideoShotsOperator(
input_uri=INPUT_URI,
output_uri=None,
video_context=None,
retry=Retry(maximum=10.0),
timeout=5,
task_id="detect_video_shots",
)
您可以透過 Xcom 使用標註輸出
tests/system/google/cloud/video_intelligence/example_video_intelligence.py
detect_video_shots_result = BashOperator(
bash_command="echo {{ task_instance.xcom_pull('detect_video_shots')"
"['annotationResults'][0]['shotAnnotations'][0]}}",
task_id="detect_video_shots_result",
)
模板¶
template_fields: Sequence[str] = (
"input_uri",
"output_uri",
"gcp_conn_id",
"impersonation_chain",
)
更多資訊¶
注意:影片標註操作的持續時間等於或長於要標註的影片本身。
參考¶
更多資訊請參閱