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
INPUT_URI = f"gs://{BUCKET_NAME_DST}/{FILE_NAME}"
detect_video_label = CloudVideoIntelligenceDetectVideoLabelsOperator(
input_uri=INPUT_URI,
output_uri=None,
video_context=None,
timeout=5,
task_id="detect_video_label",
)
您可以透過 Xcom 使用註解輸出
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
使用運算子¶
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 使用註解輸出
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
使用運算子¶
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 使用註解輸出
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",
)
更多資訊¶
注意:影片註解操作的持續時間等於或長於註解影片本身。