Ruby on Rails Friday, October 1, 2010

I tried:

module Paperclip
class VideoThumbnail < Processor

attr_accessor :time_offset, :geometry, :whiny

def initialize(file, options = {}, attachment = nil)
super
@time_offset = options[:time_offset] || '-4'
unless options[:geometry].nil? || (@geometry =
Geometry.parse(options[:geometry])).nil?
@geometry.width = (@geometry.width / 2.0).floor * 2.0
@geometry.height = (@geometry.height / 2.0).floor * 2.0
@geometry.modifier = ''
end
@whiny = options[:whiny].nil? ? true : options[:whiny]
@basename = File.basename(file.path, File.extname(file.path))
end

def make
dst = Tempfile.new([ @basename, 'jpg' ].compact.join("."))
dst.binmode

puts 'wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww'
puts @file.path

cmd = <<-end_command
ffmpeg -i #{@file.path} -f flv -s 320x240 ~/Downloads/foobar/
q.flv
end_command
cmd.gsub!(/\s+/, " ")

begin
success = Paperclip.run('ffmpeg', cmd)
rescue PaperclipCommandLineError
raise PaperclipError, "There was an error processing the
thumbnail for #{@basename}" if whiny
end
dst
end
end
end

console reports:

[paperclip] ffmpeg ' ffmpeg -i /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE++
+TI/-Tmp-/stream,1547,1.mpeg -f flv -s 320x240 ~/Downloads/foobar/
q.flv ' 2>/dev/null


On Oct 1, 10:13 pm, radhames brito <rbri...@gmail.com> wrote:
> On Fri, Oct 1, 2010 at 9:38 AM, Christian Fazzini <
>
> christian.fazz...@gmail.com> wrote:
> > Im using a customs processor to run ffmpeg on a video to create a
> > thumbnail.
>
> this here is how i do it
>
> def create_thumbnail
>      jpg = File.join(File.dirname(vidfile.path), "#{id}.jpg")
>     File.open(jpg, 'w')
>      command = <<-end_command
>       ffmpeg -itsoffset -4 -i #{ vidfile.path } -y -vcodec mjpeg -vframes 1
> -an -f rawvideo -s 160x120  #{ jpg }
>     end_command
>     command.gsub!(/\s+/, " ")
>   end
>
> you have to manually delete the file on destroy since paperclip is only
> aware of the file i uploaded which it the video file and will not delete the
> jpg file.
>
> File.delete(@vidfile.path.gsub(/flv/,"jpg"))
>
> also you have to delete the original, and update the db entry
>
>  def set_new_filename
>     File.delete(vidfile.path)
>     update_attribute(:vidfile_file_name, "#{id}.flv")
>     update_attribute(:vidfile_thumb, "#{id}.jpg")
>   end
>
>  i also set everything in an starling worker
>
> ConvertWorker.async_convert_video(:file_path => vidfile.path)

--
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@googlegroups.com.
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.

No comments:

Post a Comment