【问题标题】:Rails preview for active storage videos not working活动存储视频的 Rails 预览不起作用
【发布时间】:2021-03-24 16:19:51
【问题描述】:

我有一个非常标准的模型,您可以在其中上传视频 - 到目前为止一切都很好。 视频被上传并显示在显示视图上。 Alle 似乎很好....但是:

我无法预览工作。

ActiveStorage::Blob.last.previewable?
--> false
ActiveStorage::Blob.video?
--> true

FFMPEG 安装在系统和 gem 文件中

which ffmpeg   
--> /usr/local/bin/ffmpeg

gem 'streamio-ffmpeg'

当然,如果我直接运行预览,我会得到一个错误

ActiveStorage::Blob.last.preview(resize: "200x200>").processed
--> ActiveStorage::UnpreviewableError (ActiveStorage::UnpreviewableError)

Previewers 包含视频

Rails.application.config.active_storage.previewers
--> [ActiveStorage::Previewer::PopplerPDFPreviewer, ActiveStorage::Previewer::MuPDFPreviewer, ActiveStorage::Previewer::VideoPreviewer]

我也尝试了不同的视频格式,但没有任何效果,而且我不知道该去哪里看。 有人遇到同样的问题吗?

【问题讨论】:

  • 我想调试一下,你能在 Rails 里面放一个断点吗?这是一个好的开始github.com/rails/rails/blob/…
  • 谢谢@Joel_Blum!我不能说为什么它现在起作用了,但它起作用了。
  • 对于以后发现这个的人,用这个来检查 ffmeg 是否安装正确:ActiveStorage::Previewer::VideoPreviewer.ffmpeg_exists?

标签: ruby-on-rails video ffmpeg ruby-on-rails-6 rails-activestorage


【解决方案1】:

我遇到了同样的问题,请按照以下步骤操作,这可能对您有所帮助,因为它对我有用。

  1. 安装ffmpeg

  2. 安装ImageMagick

    属性 :video_preview do |object| Rails.application.routes.url_helpers.rails_representation_url(object.video.preview(resize: "200x200").processed, only_path: true)

结束

使用此方法检查是否有效。

【讨论】:

    【解决方案2】:

    我有一个类似的问题,视频预览在本地可以正常工作,但在生产中无法播放。只是因为我的生产环境中没有installed ffmpeg

    我的生产环境是heroku,所以我简单的添加了ffmpeg buildpack like so:

    heroku buildpacks:add --index 1 https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
    
    

    然后一切都按预期进行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      • 2019-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多