Google Cloud Video Intelligence Operators¶
Prerequisite Tasks¶
To use these operators, you must do a few things:
Select or create a Cloud Platform project using the Cloud Console.
Enable billing for your project, as described in the Google Cloud documentation.
Enable the API, as described in the Cloud Console documentation.
Install API libraries via pip.
pip install 'apache-airflow[google]'Detailed information is available for Installation.
CloudVideoIntelligenceDetectVideoLabelsOperator¶
Performs video annotation, annotating video labels.
For parameter definition, take a look at
CloudVideoIntelligenceDetectVideoLabelsOperator
Using the operator¶
Input uri is an uri to a file in Google Cloud Storage
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",
)
You can use the annotation output via 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",
)
Templating¶
template_fields: Sequence[str] = (
"input_uri",
"output_uri",
"gcp_conn_id",
"impersonation_chain",
)
More information¶
Note: The duration of video annotation operation is equal or longer than the annotation video itself.
CloudVideoIntelligenceDetectVideoExplicitContentOperator¶
Performs video annotation, annotating explicit content.
For parameter definition, take a look at
CloudVideoIntelligenceDetectVideoExplicitContentOperator
Arguments¶
Input uri is an uri to a file in Google Cloud Storage
INPUT_URI = f"gs://{BUCKET_NAME_DST}/{FILE_NAME}"
Using the operator¶
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",
)
You can use the annotation output via 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",
)
Templating¶
template_fields: Sequence[str] = (
"input_uri",
"output_uri",
"gcp_conn_id",
"impersonation_chain",
)
More information¶
Note: The duration of video annotation operation is equal or longer than the annotation video itself.
CloudVideoIntelligenceDetectVideoShotsOperator¶
Performs video annotation, annotating explicit content.
For parameter definition, take a look at
CloudVideoIntelligenceDetectVideoShotsOperator
Arguments¶
Input uri is an uri to a file in Google Cloud Storage
INPUT_URI = f"gs://{BUCKET_NAME_DST}/{FILE_NAME}"
Using the operator¶
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",
)
You can use the annotation output via 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",
)
Templating¶
template_fields: Sequence[str] = (
"input_uri",
"output_uri",
"gcp_conn_id",
"impersonation_chain",
)
More information¶
Note: The duration of video annotation operation is equal or longer than the annotation video itself.