'Rails preview for active storage videos not working

I have a pretty standard model where you can upload videos - so far so good. The video gets uploaded and is also displayed on the show view. Alle seems to be fine....but:

I cannot get a preview fo to work.

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

FFMPEG is installed on the system and in the gem file

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

gem 'streamio-ffmpeg'

And of course if I run preview directly, I get an error

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

Previewers is having video included

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

I also tried different video formats, but nothing works and I am out of ideas where to look. Anybody had the same issue?



Solution 1:[1]

I had face the same issue, please follow the below step which might help you because it work for me.

  1. install the ffmpeg

  2. install the ImageMagick

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

end

use this method to check whether is working or not.

Solution 2:[2]

I had a similar problem of video previews working fine locally but not playing in production. It was simply because I hadn't installed ffmpeg in my production environment.

My production environment was heroku, so I simply added the ffmpeg buildpack like so:

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

And then everything worked as expected.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2