Skip to content

Instantly share code, notes, and snippets.

@audiodude
Created March 29, 2011 23:52
Show Gist options
  • Save audiodude/893593 to your computer and use it in GitHub Desktop.
Save audiodude/893593 to your computer and use it in GitHub Desktop.
module Paperclip
# Handles thumbnailing videos that are uploaded.
class FlvConvert < Processor
def initialize file, options = {}, attachment = nil
super
@file = file
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
@make_flv = options[:make_flv]
end
def make
return @file unless @make_flv
src = @file
dst = Tempfile.new([@basename, '.flv'])
dst.binmode
begin
src = File.expand_path(src.path)
dest = File.expand_path(dst.path)
cmd = "ffmpeg -y -i #{src} -vcodec flv #{dest}"
Paperclip.log(cmd)
`#{cmd}`
rescue PaperclipCommandLineError => e
raise PaperclipError, "There was an error converting to flv: #{@basename}" if @whiny
end
dst
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment