Rails video uploading

paperclip, ruby-on-rails

Solution

We got Paperclip working with video a while back

Systems

You'll have the same ambiguity whether you use CarrierWave or Paperclip (Rails' two main "attachment" handlers)

Any upload system only handles the transfer of file data between your PC, your Rails app & your db. Each of them (from my understanding). E.G Paperclip only creates an `ActiveRecord` object from your file, saves the data to your server's `public` dir & creates a record in your db

Code

The question of video is one of using the right processor, rather than the right uploader:

#app/models/attachment.rb
has_attached_file :attachment,
    styles: lambda { |a| a.instance.is_image? ? {:small => "x200>", :medium => "x300>", :large => "x400>"}  : {:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10}, :medium => { :geometry => "300x300#", :format => 'jpg', :time => 10}}},
    processors: lambda { |a| a.is_video? ? [ :ffmpeg ] : [ :thumbnail ] }

Extra

You'll need to use a video processor such as ffmpeg for Paperclip:

#GemFile
gem "paperclip-ffmpeg", "~> 1.0.1"

You may have to install ffmpeg on your system to get the processor to work locally (Heroku has ffmpeg). This will allow you to use the `video_tag` helper:

<%= video_tag(@model.attachment.url) %>

There's a good tutorial about using ffmpeg with Paperclip here And another tutorial here

Problem

I've searched around for different uploading options for rails and video and Paperclip seems to be pretty good, but are there any others people would recommend, it should have good tutorials and docs because i can't really find any great paperclip docs involving uploading video content.

Original source