The code powering m.abunchtell.com https://m.abunchtell.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 lines
792 B

  1. # frozen_string_literal: true
  2. module Paperclip
  3. # This transcoder is only to be used for the MediaAttachment model
  4. # to convert animated gifs to webm
  5. class GifTranscoder < Paperclip::Processor
  6. def make
  7. return File.open(@file.path) unless needs_convert?
  8. final_file = Paperclip::Transcoder.make(file, options, attachment)
  9. attachment.instance.file_file_name = File.basename(attachment.instance.file_file_name, '.*') + '.mp4'
  10. attachment.instance.file_content_type = 'video/mp4'
  11. attachment.instance.type = MediaAttachment.types[:gifv]
  12. final_file
  13. end
  14. private
  15. def needs_convert?
  16. num_frames = identify('-format %n :file', file: file.path).to_i
  17. options[:style] == :original && num_frames > 1
  18. end
  19. end
  20. end