name: storage-label-videos
version: 0.1.3
specVersion: v1beta

displayName: Label Videos with Cloud Video AI
description:
  Extracts labels from videos and saves to Cloud Storage using Cloud Video
  Intelligence API.

license: Apache-2.0

icon: icon.png

tags:
  [
    ai,
    cloud-video,
    video-recognition,
    video-classification,
    google-ai,
    video-intelligence-api,
  ]

author:
  authorName: Google Cloud
  url: https://cloud.google.com/

contributors:
  - authorName: Invertase
    email: oss@invertase.io
    url: https://github.com/invertase

sourceUrl: https://github.com/GoogleCloudPlatform/firebase-extensions/tree/main/storage-label-videos
releaseNotesUrl: https://github.com/GoogleCloudPlatform/firebase-extensions/tree/main/storage-label-videos/CHANGELOG.md

billingRequired: true

apis:
  - apiName: videointelligence.googleapis.com
    reason: Powers all Video Intelligence tasks performed by the extension.

resources:
  - name: labelVideo
    type: firebaseextensions.v1beta.function
    description:
      Listens to incoming Storage documents that are videos and executes video
      labelling detection on them.
    properties:
      location: ${param:LOCATION}
      availableMemoryMb: 128
      eventTrigger:
        eventType: google.storage.object.finalize
        resource: projects/_/buckets/${param:INPUT_VIDEOS_BUCKET}
      runtime: nodejs20

params:
  - param: LOCATION
    label: Cloud Functions location
    description: >-
      Cloud region where annotation should take place. For help selecting a
      location, refer to the [location selection
      guide](https://firebase.google.com/docs/functions/locations).
    type: select
    # Only these locations are available see:
    # https://cloud.google.com/video-intelligence/docs/reference/rpc/google.cloud.videointelligence.v1#annotatevideorequest
    options:
      - label: South Carolina (us-east1)
        value: us-east1
      - label: Oregon (us-west1)
        value: us-west1
      - label: Belgium (europe-west1)
        value: europe-west1
      - label: Taiwan (asia-east1)
        value: asia-east1

    default: us-east1
    required: true
    immutable: true

  - param: INPUT_VIDEOS_BUCKET
    label: Cloud Storage bucket where videos should be picked up and processed.
    description: >
      Cloud Storage bucket where videos should be picked up and processed.
    type: string
    example: my-project-12345.appspot.com
    validationRegex: ^([0-9a-z_.-]*)$
    validationErrorMessage: Invalid storage bucket
    default: ${STORAGE_BUCKET}
    required: true

  - param: OUTPUT_BUCKET
    label:
      Cloud Storage bucket where the ouput json from a processed videos should
      be stored.
    description: >
      Cloud Storage bucket where videos should be process to.
    type: string
    example: my-project-12345.appspot.com
    validationRegex: ^([0-9a-z_.-]*)$
    validationErrorMessage: Invalid storage bucket
    default: ${STORAGE_BUCKET}
    required: true

  - param: INPUT_VIDEOS_PATH
    label: Input videos path
    description: >
      A Storage path in the input video bucket that the extension should process
      videos from.
    type: string
    example: /video_annotation_input/
    validationRegex: ^\/([0-9a-zA-Z_\/\-]*\/){0,1}$
    validationErrorMessage: Invalid storage folder name
    default: /video_annotation_input/
    required: true

  - param: OUTPUT_PATH
    label: Output videos path
    description: >
      A Storage path in the output video bucket that the output json should be
      stored.
    type: string
    example: /video_annotation_output/
    validationRegex: ^\/([0-9a-zA-Z_\/\-]*\/){0,1}$
    validationErrorMessage: Invalid storage folder name
    default: /video_annotation_output/
    required: true

  - param: LABEL_DETECTION_MODE
    label: Label detection mode
    description: >
      What labels should be detected with LABEL_DETECTION, in addition to
      video-level labels or segment-level labels. If unspecified, defaults to
      SHOT_MODE.
    type: select
    options:
      - label: Detect shot-level labels
        value: SHOT_MODE
      - label: Detect frame-level labels
        value: FRAME_MODE
      - label: Detect both shot-level and frame-level labels
        value: SHOT_AND_FRAME_MODE
    default: SHOT_MODE
    required: true

  - param: VIDEO_CONFIDENCE_THRESHOLD
    label: Video confidence threshold
    description: >
      The confidence threshold we perform filtering on the labels from
      video-level and shot-level detections. If not set, it is set to 0.3 by
      default. The valid range for this threshold is [0.1, 0.9]. Any value set
      outside of this range will be clipped. Note: for best results please
      follow the default threshold. We will update the default threshold
      everytime when we release a new model.
    example: 0.3
    validationRegex: ^[01]\.[0-9]
    validationErrorMessage: Must be a value >= 0.0 and <= 1.0
    default: 0.3
    required: true

  - param: FRAME_CONFIDENCE_THRESHOLD
    label: Frame confidence threshold
    description: >
      The confidence threshold we perform filtering on the labels from
      frame-level detection. If not set, it is set to 0.4 by default. The valid
      range for this threshold is [0.1, 0.9]. Any value set outside of this
      range will be clipped. Note: for best results please follow the default
      threshold. We will update the default threshold everytime when we release
      a new model.
    example: 0.4
    validationRegex: ^[01]\.[0-9]
    validationErrorMessage: Must be a value >= 0.0 and <= 1.0
    default: 0.4
    required: true

  - param: MODEL
    label: Model
    description: >
      Model to use for label detection.
    type: select
    example: builtin/stable
    options:
      - label: Stable
        value: builtin/stable
      - label: Latest
        value: builtin/latest
    default: builtin/stable
    required: true

  - param: STATIONARY_CAMERA
    label: Stationary Camera
    description: >
      Whether the video has been shot from a stationary (i.e. non-moving)
      camera. When set to true this might improve detection accuracy for moving
      objects. Will default to false if LABEL_DETECTION_MODE has been set to
      SHOT_AND_FRAME_MODE.
    type: select
    options:
      - label: Yes
        value: true
      - label: No
        value: false
    default: true
    required: true

roles:
  - role: storage.objectAdmin
    reason: Allows the extension to write to your Cloud Storage.
