deuxhuithuit/craft-cloudflare-stream

Upload your videos assets to Cloudflare Stream from Craft CMS assets interface

1.4.8 2024-03-28 23:10 UTC

This package is auto-updated.

Last update: 2024-04-28 23:16:20 UTC


README

This plugin offers a easy way to upload your videos assets from Craft CMS to Cloudflare stream.

Installation:

  1. Install with composer
composer require deuxhuithuit/craft-cloudflare-stream
  1. Install in craft
craft plugin/install cloudflare-stream
  1. Add your account id and api token in the settings.

  2. Create a video stream Field and add it to your Asset data model.

  3. When editing an asset, you can now opt-in into sending videos in Cloudflare Stream.

  4. If your are using twig, with a field named stream you can access the stream data like so:

{% set value = asset.stream %}
<video controls style="width: 100%" poster="{{ value.thumbnail }}">
    {% if value.mp4Url and value.completed %}
        <source src="{{ value.mp4Url }}" type="video/mp4">
    {% endif %}
    {% if value.playback.hls %}
        <source src="{{ value.playback.hls }}" type="application/x-mpegURL">
    {% endif %}
    {% if value.playback.dash %}
        <source src="{{ value.playback.dash }}" type="application/dash+xml">
    {% endif %}
</video>
  1. If you are using graphql, there is a type registered to make it easy to request the proper data.
query MyQuery {
  asset(site: ["en"], volume: "stream") {
    url
    kind
    extension
    filename
    ... on stream_Asset {
      videoStream {
        uid
        name
        size
        thumbnailTimestampPct
        thumbnail
        preview
        hls
        dash
        mp4
        ready
        completed
        watermark {
          uid
          created
          downloadedFrom
          height
          name
          opacity
          padding
          position
          scale
          size
          width
        }
        input {
          width
          height
        }
      }
    }
  }
}
  1. You can also mass re-upload everything via Craft's cli
./craft cloudflare-stream/reupload

This extension uses Craft's Queue system, so make sure it works properly. Please make sure that Craft's max upload limit is also properly set.

Made with ❤️ in Montréal.

(c) Deux Huit Huit