I used paperclip background process with delay jobs with ffmpeg.
In paperclip processors folder i have ffmpeg.rb file also.
my model
class product < ActiveRecord::Base
has_attached_file :video, :styles => {
:mp4video => { :geometry => "640x480", :format => 'mp4', :convert_options => {:output => {:ar => 44100}} },
:webmvideo =>{ :geometry => "1024x576", :format => 'webm', :convert_options => {:output => {:ar => 44100}} },
:oggvideo => { :geometry => "1024x576", :format => 'ogg', :convert_options => {:output => {:ar => 44100}} },
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 }
},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/aws.yml",
:processors => [:transcoder]
process_in_background :video
end
Related
I'm using gem 'paperclip-av-transcoder', "0.6.2" for my video processing.
I simply need to write this code to have my video converted into many formats:
has_attached_file :video, :styles => {
:mp4 => { :format => 'mp4', :convert_options => { :output => { :vcodec => 'libx264', :acodec => 'copy' } } },
:ogg => { :format => 'ogg', :auto_rotate => true },
:webm => { :format => 'webm', :auto_rotate => true },
:flv => { :format => 'flv', :convert_options => { :output => { :ar => 44100 } }, :auto_rotate => true },
:thumb => { :geometry => "300x300#", :format => 'jpg', :time => 1, :auto_rotate => true }
}, :processors => [:transcoder]
But this code is synchronous and the user that upload the video is stuck during the conversion.
I would like to add an async wrapper (worker) around :transcoder so I can call:
has_attached_file :video, :styles => {... }, :processors => [:wrapper_transcoder_worker]
I have installed resque and redis and everything work.
Do you have an idea on how can I write the asynch worker around transcoder?
Have you tried delayed_paperclip gem? It pushes all processing into background and supports resque (among others).
lock paperclip at version 4.2.0
I want to update my styles in paperclip, but when i run the command, a error is returned. Here is the code of my styles:
image.rb
class Image < ActiveRecord::Base
belongs_to :imageable, :polymorphic => true
validates_presence_of :image
has_attached_file :image, :processors => [:ffmpeg],
:styles => { :video => { :geometry => "640x480", :format => 'mp4' },
:thumb => { :geometry => "100x100>", :format => 'jpg' },
:large => { :geometry => "400x300>", :format => 'jpg' },
:medium => { :geometry => "400x200>", :format => 'png' },
:icon => { :geometry => "36x36>", :format => 'jpg' },
:profile => { :geometry => "28x28>", :format => 'jpg' } },
:default_url => "/images/:style/missing.png"
end
Returned Error:
Regenerating Image -> image -> [:icon, :large, :medium, :profile, :thumb, :video]
rake aborted!
Cocaine::CommandNotFoundError
How i solve this error?
It seems to be that you have not installed the "paperclip-ffmpeg" gem.
See this link: https://github.com/owahab/paperclip-ffmpeg#requirements
When I try to upload a video using Paperclip, I get an error message can't dump File.
Model Video :
class Video < ActiveRecord::Base
has_attached_file :avatar,
:storage => :s3,
:styles => {
:mp4 => { :geometry => "640x480", :format => 'mp4' },
:thumb => { :geometry => "300x300>", :format => 'jpg', :time => 5 }
}, :processors => [:ffmpeg]
validates_attachment_presence :avatar
validates_attachment_content_type :avatar,
:content_type => /video/,
:message => "Video not supported"
end
I was doing some image optimization on my site. Things are working awesome on development machine but in production mode I am getting an error ie:
ActionView::Template::Error (can't dup Symbol):
This is happening only in case of aws, If I remove this then things working perfectly fine:
A code I was using and was working perfectly:
has_attached_file :attachment, {
:styles => {
:medium=>"654x346>",
:small => "260x400>",
:thumb => "75x75#",
:facebook_meta_tag => "200x200#"
}, :include_updated_timestamp => false
}.merge(PAPERCLIP_STORAGE_OPTIONS)
But now I modified this and Its working perfectly fine in development environment but not working on production environment.
has_attached_file :attachment,
:styles => {
:medium => {
:geometry => "654x346>",
:quality => 60,
:format => 'JPG'
},
:small => {
:geometry => "260x400>",
:quality => 60,
:format => 'JPG'
},
:thumb => {
:geometry =>"75x75#",
:quality => 60,
:format => 'JPG'
},
:facebook_meta_tag => {
:geometry =>"200x200#",
:quality => 50,
:format => 'JPG'
}
}.merge(PAPERCLIP_STORAGE_OPTIONS)
Other relevant settings:
PAPERCLIP_STORAGE_OPTIONS = {
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/amazons3.yml",
}
amazons3.yml
production:
access_key_id: XXXXxxxXXXXxxx
secret_access_key: XXXXxxxXXXXxxxXXXXxxxXXXXxxxXXXXxxxXXXXxxx
bucket: images.XXXXxxx.com
Here is the working code:
has_attached_file :attachment, {
:styles => {
:medium => ["654x346>", :jpg],
:small => ["260x400>", :jpg],
:thumb => ["75x75#", :jpg],
:facebook_meta_tag =>["200x200#", :jpg]
},
:convert_options => {
:medium => "-quality 60",
:small => "-quality 60",
:thumb => "-quality 60",
:facebook_meta_tag => "-quality 60"
}
}.merge(PAPERCLIP_STORAGE_OPTIONS)
ActionView::Template::Error tends to be an error raised inside of a view (Rails re-wraps errors inside views inside ActionView::Template::Error exceptions).
To help you more I'd need to see the backtrace and the view involved.
This is not really an answer, but if this helps you find the cause you may as well accept it.
How can I do something inside the model depending on the whether it's creating or updating a record? I'm sure it's really simple, but I can't seem to figure it out.
These are different styles for updating or creating attachments with paperclip.
class Photo < ActiveRecord::Base
belongs_to :product
#after_upate :flag_somthin
Paperclip.interpolates :product_id do |attachment, style|
attachment.instance.product_id
end
has_attached_file :data,
:storage => 's3',
:s3_credentials => "#{RAILS_ROOT}/config/s3_credentials.yml",
:bucket => 'leatherarts.com',
:s3_host_alias => 'leatherarts.com.s3.amazonaws.com',
:url => ':s3_alias_url',
:path => "images/products/:product_id/:style/:basename.:extension",
:styles => lambda { |style| style.instance.choose_styles },
:default_style => :medium,
:default_url => 'http://leatherarts.com.s3.amazonaws.com/images/records/m1.png',
:s3_headers => { 'Expires' => 2.months.from_now.httpdate }
validates_attachment_presence :data
validates_attachment_size :data, :less_than => 10.megabytes
validates_attachment_content_type :data, :content_type => ['image/jpeg','image/gif','image/png']
def choose_styles
{ :thumb => "60x60#", :small => "200x200>", :medium => "400x400>", :large => "1000x1000>", :backup => "2000x2000>" }, :on => :create
{ :thumb => "60x60#", :small => "200x200>", :medium => "400x400>", :large => "1000x1000>" }, :on => :update
end
end
Use the new_record? method to return different hashes:
def choose_styles
defaults = { :thumb => "60x60#", :small => "200x200>", :medium => "400x400>", :large => "1000x1000>" }
defaults.merge! :backup => "2000x2000>" if new_record?
defaults
end