Heroku ffmpeg buildpacks for video uploads

人盡茶涼 提交于 2019-12-03 21:00:49

users can upload videos

We've had it working on Heroku before; we used paperclip-ffmpeg (which is now paperclip-av-transcoder) with the actual Paperclip gem.

Whilst I can't provide any information about the buildpacks, I can share how we were able to get video uploading working on Heroku...

#app/models/attachment.rb
class Attachment < ActiveRecord::Base
    has_attached_file :attachment,
    styles:     { thumb: { geometry: "100x100#", format: 'jpg', time: 10}, medium: { geometry: "300x300#", format: 'jpg', time: 10} },
    processors: [ :transcoder ]
end

As long as the paperclip-av-transcoder gem installs (ensure you've got it in your Gemfile), this should allow you to store the videos - and images - you need.

Got heroku Video uploads to work!

Video model:
    has_attached_file :video, styles: {
        :medium => {
          :geometry => "640x480",
          :format => 'mp4'
        },
        :thumb => { :geometry => "160x120", :format => 'jpeg', :time => 10}
    }, :processors => [:transcoder]
    validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/

Make sure you already bundled:

gem 'paperclip', '~> 4.3.1'
gem 'aws-sdk', '< 2.0'
gem 'paperclip-av-transcoder'

Run the paperclip migration:

rails g paperclip model video

Be sure to add in post_controller.rb:

private

    def bscenes_params
        params.require(:post).permit(:video)
    end

Upload form:

<%= f.file_field :video %>

Show page:

<%= video_tag bscene.video.url(:medium), controls: true, style: "max-width: 100%;" %>

At this point you should get this error:

Av::UnableToDetect (Unable to detect any supported library):

Go to your terminal and type in:

brew options ffmpeg

Then run the following to install ffmpeg:

brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libas

At this point video uploads will work locally

Now for remote uploads you will need to setup https://devcenter.heroku.com/articles/buildpacks

After setting up Heroku buildpacks you may get an error:

Av::UnableToDetect (Unable to detect any supported library)

You will need to create a Procfile in the root of your app directory more information about Procfile here: https://devcenter.heroku.com/articles/procfile

touch Procfile

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!