name: storage-transcode-videos
version: 0.0.2
specVersion: v1beta

displayName: Transcode Videos on Google Cloud Storage
description:
  Transcode video files into formats suitable for consumer distribution.

license: Apache-2.0

author:
  authorName: Firebase
  url: https://firebase.google.com

sourceUrl: https://github.com/FirebaseExtended/experimental-extensions/tree/main/storage-transcode-videos

billingRequired: true

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

resources:
  - name: transcodevideo
    type: firebaseextensions.v1beta.function
    description:
      Listens to incoming Storage documents that are videos and executes a video
      transcoding job 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 transcoding should take place. For help selecting a
      location, refer to the [location selection
      guide](https://firebase.google.com/docs/functions/locations).
    type: select
    # Options limited to regions available in:
    # - https://cloud.google.com/transcoder/docs/concepts/regions#available_regions
    # - https://firebase.google.com/docs/functions/locations
    options:
      - label: Iowa (us-central1)
        value: us-central1
      - label: South Carolina (us-east1)
        value: us-east1
      - label: Belgium (europe-west1)
        value: europe-west1
      - label: Sao Paulo (southamerica-east1)
        value: southamerica-east1
    default: us-central1
    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_VIDEOS_BUCKET
    label: Cloud Storage bucket where processed videos should be output to.
    description: >
      A Storage bucket that the extension should process videos 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_transcoding_input/
    validationRegex: ^\/([0-9a-zA-Z_\/\-]*\/){0,1}$
    validationErrorMessage: Invalid storage folder name
    default: /video_transcoding_input/
    required: true

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

  - param: DEFAULT_TEMPLATE_ID
    label: The default transcoding template ID to use for transcoding jobs.
    description: >
      A template id for populating a job configuration.
    example: preset/web-hd
    validationRegex: ^[a-zA-Z0-9\/\-_]+$
    validationErrorMessage:
      Must be an alphanumeric string. Dashes, underscores and forward slashes
      are also allowed
    default: preset/web-hd
    required: true

roles:
  - role: transcoder.admin
    reason: Allows the extension to create video transcoding jobs.
  - role: storage.admin
    reason: Allows the extension to write to your Cloud Storage.
