deuxhuithuit / craft-cloudflare-stream

将您的视频资源从Craft CMS资源界面上传到Cloudflare Stream

2.0.0 2024-08-13 17:56 UTC

README

此插件提供了一个简单的方法,将您的视频资源从Craft CMS上传到Cloudflare Stream。

安装

  1. 使用composer安装
composer require deuxhuithuit/craft-cloudflare-stream
  1. 在craft中安装
craft plugin/install cloudflare-stream
  1. 在设置中添加您的账户id和api token。

  2. 创建一个视频流字段并将其添加到您的资产数据模型中。

  3. 在编辑资产时,现在可以选择将视频发送到Cloudflare Stream

  4. 如果您使用twig,可以通过名为stream的字段这样访问流数据

{% 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. 如果您使用graphql,已注册一个类型以简化正确数据的请求。
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. 您还可以通过Craft的cli批量重新上传所有内容
./craft cloudflare-stream/reupload

此扩展使用Craft的队列系统,因此请确保其正常运行。请确保Craft的最大上传限制也正确设置。

在蒙特利尔用❤️制作。

(c) Deux Huit Huit