Does anyone know the right approach to change the duration/length of an uploaded mp3 file? User has the option to upload mp3 file as full, 30 secs or 90 secs. So far, I have gotten it to work for full. Do I have to use a processor (with ffmpeg) for this? Or is there a built-in option in paperclip for this to happen? Tried googling around to no avail.... By the way, if user selects 90 secs (for example), then I need Paperclip not to upload the original. The same goes for 30 secs. In theory, its one file or the other. Your suggestions / feedback are welcome -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Note that I am using Paperclip for all my uploads ... On Oct 2, 9:07 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Does anyone know the right approach to change the duration/length of > an uploaded mp3 file? User has the option to upload mp3 file as full, > 30 secs or 90 secs. So far, I have gotten it to work for full. > > Do I have to use a processor (with ffmpeg) for this? Or is there a > built-in option in paperclip for this to happen? > > Tried googling around to no avail.... > > By the way, if user selects 90 secs (for example), then I need > Paperclip not to upload the original. The same goes for 30 secs. In > theory, its one file or the other. > > Your suggestions / feedback are welcome-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
This is what I have. When i submit the form, the page just hangs. No errors, no nothing. model: has_attached_file :media, :styles => { :short => ''k128'' }, :url => ''/assets/:id/:style.:extension'', :path => '':rails_root/public/ assets/:id/:style.:extension'', :processors => [:process_audio] ------------------ module Paperclip class ProcessAudio < Processor attr_accessor :resolution, :whiny def initialize(file, options = {}, attachment = nil) super @file = file @whiny = options[:whiny].nil? ? true : options[:whiny] @basename = File.basename(@file.path, File.extname(@file.path)) end def make dst = Tempfile.new([ @basename, ''mp3'' ].compact.join(".")) dst.binmode cmd = "ffmpeg -i #{@file.path} -t 30 -acodec copy #{File.expand_path(dst.path)}" begin success = Paperclip.run(cmd, [ 0, 1 ]) rescue PaperclipCommandLineError raise PaperclipError, "There was an error processing the preview for #{@basename}" if whiny end dst end end end On Oct 2, 9:08 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Note that I am using Paperclip for all my uploads ... > > On Oct 2, 9:07 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > Does anyone know the right approach to change the duration/length of > > an uploaded mp3 file? User has the option to upload mp3 file as full, > > 30 secs or 90 secs. So far, I have gotten it to work for full. > > > Do I have to use a processor (with ffmpeg) for this? Or is there a > > built-in option in paperclip for this to happen? > > > Tried googling around to no avail.... > > > By the way, if user selects 90 secs (for example), then I need > > Paperclip not to upload the original. The same goes for 30 secs. In > > theory, its one file or the other. > > > Your suggestions / feedback are welcome > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Checkout http://blog.ncodedevlabs.com/2010/01/14/extracting-audio-length-using-rails/ On Oct 2, 1:39 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This is what I have. When i submit the form, the page just hangs. No > errors, no nothing. > > model: > has_attached_file :media, > :styles => { :short => ''k128'' }, > :url => ''/assets/:id/:style.:extension'', > :path => '':rails_root/public/ > assets/:id/:style.:extension'', > :processors => [:process_audio] > > ------------------ > > module Paperclip > class ProcessAudio < Processor > > attr_accessor :resolution, :whiny > > def initialize(file, options = {}, attachment = nil) > super > @file = file > @whiny = options[:whiny].nil? ? true : options[:whiny] > @basename = File.basename(@file.path, File.extname(@file.path)) > end > > def make > dst = Tempfile.new([ @basename, ''mp3'' ].compact.join(".")) > dst.binmode > > cmd = "ffmpeg -i #...@file.path} -t 30 -acodec copy > #{File.expand_path(dst.path)}" > > begin > success = Paperclip.run(cmd, [ 0, 1 ]) > rescue PaperclipCommandLineError > raise PaperclipError, "There was an error processing the > preview for #{@basename}" if whiny > end > dst > end > end > end > > On Oct 2, 9:08 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > Note that I am using Paperclip for all my uploads ... > > > On Oct 2, 9:07 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > Does anyone know the right approach to change the duration/length of > > > an uploaded mp3 file? User has the option to upload mp3 file as full, > > > 30 secs or 90 secs. So far, I have gotten it to work for full. > > > > Do I have to use a processor (with ffmpeg) for this? Or is there a > > > built-in option in paperclip for this to happen? > > > > Tried googling around to no avail.... > > > > By the way, if user selects 90 secs (for example), then I need > > > Paperclip not to upload the original. The same goes for 30 secs. In > > > theory, its one file or the other. > > > > Your suggestions / feedback are welcome-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I got mine to work with the following code, incase future devs stumble across a similar situation: module Paperclip class ProcessAudio < Processor attr_accessor :geometry, :whiny def initialize(file, options = {}, attachment = nil) super @file = file unless options[:geometry].nil? if options[:geometry] == ''full'' @geometry = '''' elsif options[:geometry] == ''30'' @geometry = ''-t 30'' elsif options[:geometry] == ''90'' @geometry = ''-t 90'' end end @whiny = options[:whiny].nil? ? true : options[:whiny] @basename = File.basename(@file.path, File.extname(@file.path)) end def make dst = Tempfile.new([ @basename, ''mp3'' ].compact.join(".")) dst.binmode cmd = "ffmpeg -i #{@file.path} #{@geometry} -acodec copy -y #{File.expand_path(dst.path)}" begin success = Paperclip.run(cmd) rescue PaperclipCommandLineError raise PaperclipError, "There was an error processing the preview for #{@basename}" if whiny end dst end end end On Oct 2, 11:37 pm, nukturnal <luvlyr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Checkouthttp://blog.ncodedevlabs.com/2010/01/14/extracting-audio-length-using... > > On Oct 2, 1:39 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > This is what I have. When i submit the form, the page just hangs. No > > errors, no nothing. > > > model: > > has_attached_file :media, > > :styles => { :short => ''k128'' }, > > :url => ''/assets/:id/:style.:extension'', > > :path => '':rails_root/public/ > > assets/:id/:style.:extension'', > > :processors => [:process_audio] > > > ------------------ > > > module Paperclip > > class ProcessAudio < Processor > > > attr_accessor :resolution, :whiny > > > def initialize(file, options = {}, attachment = nil) > > super > > @file = file > > @whiny = options[:whiny].nil? ? true : options[:whiny] > > @basename = File.basename(@file.path, File.extname(@file.path)) > > end > > > def make > > dst = Tempfile.new([ @basename, ''mp3'' ].compact.join(".")) > > dst.binmode > > > cmd = "ffmpeg -i #...@file.path} -t 30 -acodec copy > > #{File.expand_path(dst.path)}" > > > begin > > success = Paperclip.run(cmd, [ 0, 1 ]) > > rescue PaperclipCommandLineError > > raise PaperclipError, "There was an error processing the > > preview for #{@basename}" if whiny > > end > > dst > > end > > end > > end > > > On Oct 2, 9:08 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > Note that I am using Paperclip for all my uploads ... > > > > On Oct 2, 9:07 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > Does anyone know the right approach to change the duration/length of > > > > an uploaded mp3 file? User has the option to upload mp3 file as full, > > > > 30 secs or 90 secs. So far, I have gotten it to work for full. > > > > > Do I have to use a processor (with ffmpeg) for this? Or is there a > > > > built-in option in paperclip for this to happen? > > > > > Tried googling around to no avail.... > > > > > By the way, if user selects 90 secs (for example), then I need > > > > Paperclip not to upload the original. The same goes for 30 secs. In > > > > theory, its one file or the other. > > > > > Your suggestions / feedback are welcome > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.