Audio/Video Transcoder for Paperclip using FFMPEG/Avconv
Audio/Video Transcoder for Paperclip using FFMPEG/Avconv.
This is a replacement for ( https://github.com/owahab/paperclip-ffmpeg ).
Add this line to your application's Gemfile:
gem 'paperclip-av-transcoder'
And then execute:
$ bundle
Or install it yourself as:
$ gem install paperclip-av-transcoder
In your model:
# app/models/user.rb class User < ActiveRecord::Base has_attached_file :avatar, :styles => { :medium => { :geometry => "640x480", :format => 'flv' }, :thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 } }, :processors => [:transcoder] end
This will produce:
:mediumFLV file with the requested dimensions if they will match the aspect ratio of the original file, otherwise, width will be maintained and height will be recalculated to keep the original aspect ration.
:thumbwith the requested dimensions regardless of the aspect ratio.
Then paperclip-av-transcoder can optionally add uploaded file meta data to a database column for
_meta.
Example: Given a model called
Userwith an attachment field named
:avatar, create a new migration to add an
avatar_metacolumn to the
userstable.
def change add_column :users, :avatar_meta, :data_type endYou can use a data type of
:json,
:jsonb,
:hstoreor even just
:string. Check what data types your database supports.
geometry
The
geometryoption has the following available modifiers:
convert_options
The
convert_optionsoption lets you specify custom command line options to be sent to the
ffmpegcommand. The options are split into
outputand
input, which define where in the pipeline they will be applied. Read more about which flags go where on the official documentation.
For example, sending in the
-anflag would look like this:
has_attached_file :video, styles: { mobile: { format: "mp4", convert_options: { output: { an: nil # Remove audio track resulting in a silent movie, passing in nil results in `-an`, name: "value" # Results in `-name value` in the command line } } }, }
git checkout -b my-new-feature)
git commit -am 'Add some feature')
git push origin my-new-feature)