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 Cloud Console.
Enable billing for your project, as described in Google Cloud documentation.
Enable API, as described in Cloud Console documentation.
Install API libraries via pip.
pip install 'apache-airflow[gcp]'
Detailed information is available Installation
CloudVideoIntelligenceDetectVideoLabelsOperator¶
Performs video annotation, annotating video labels.
For parameter definition, take a look at
airflow.contrib.operators.gcp_video_intelligence_operator.CloudVideoIntelligenceDetectVideoLabelsOperator
Arguments¶
Some arguments in the example DAG are taken from the OS environment variables:
GCP_BUCKET_NAME = os.environ.get(
"GCP_VIDEO_INTELLIGENCE_BUCKET_NAME", "test-bucket-name"
)
Input uri is an uri to a file in Google Cloud Storage
INPUT_URI = "gs://{}/video.mp4".format(GCP_BUCKET_NAME)
Using the operator¶
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 = ("input_uri", "output_uri", "gcp_conn_id")
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
airflow.contrib.operators.gcp_video_intelligence_operator.CloudVideoIntelligenceDetectVideoExplicitContentOperator
Arguments¶
Some arguments in the example DAG are taken from the OS environment variables:
GCP_BUCKET_NAME = os.environ.get(
"GCP_VIDEO_INTELLIGENCE_BUCKET_NAME", "test-bucket-name"
)
Input uri is an uri to a file in Google Cloud Storage
INPUT_URI = "gs://{}/video.mp4".format(GCP_BUCKET_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 = ("input_uri", "output_uri", "gcp_conn_id")
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
airflow.contrib.operators.gcp_video_intelligence_operator.CloudVideoIntelligenceDetectVideoShotsOperator
Arguments¶
Some arguments in the example DAG are taken from the OS environment variables:
GCP_BUCKET_NAME = os.environ.get(
"GCP_VIDEO_INTELLIGENCE_BUCKET_NAME", "test-bucket-name"
)
Input uri is an uri to a file in Google Cloud Storage
INPUT_URI = "gs://{}/video.mp4".format(GCP_BUCKET_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 = ("input_uri", "output_uri", "gcp_conn_id")
More information¶
Note: The duration of video annotation operation is equal or longer than the annotation video itself.