Because I want to use HTML5 video I need to convert videos uploaded by the user into multiple codecs. I am following this tutorial: http://jimneath.org/2008/06/03/converting-videos-with-rails-converting-the-video/ but it only outputs FLV, a format I don't even want at all.
I know I can add more FFmpeg commands and convert multiple times, but the problem lies in the database and the view. How can I define multiple source_file_name
s in the DB, and how can I specify in @video.source.url
which format I want? Should I subclass the Video
model, add more table columns for each type or something else?
Paperclip allows you to specify multiple styles. Generally, this is used to specify multiple sizes for uploaded images; Paperclip processes the image once for each style and places them in the filesystem accordingly. By specifying different video formats for your styles and subclassing
Paperclip::Processor
, you can create your own video formats. In your model, you'd do something like this:And then create a custom Processor that runs the correct FFmpeg command based on each style. See the documentation for more info, but here is a snippet:
When you create a link to a Paperclip attachment, you pass the style to determine which to link to: