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",
)
更多信息¶
注意:视频标注操作的持续时间等于或长于要标注的视频本身。
参考¶
更多信息请参阅