logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

gif_transcoder.rb (880B)


  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. num_frames = identify('-format %n :file', file: file.path).to_i
  8. unless options[:style] == :original && num_frames > 1
  9. tmp_file = Paperclip::TempfileFactory.new.generate(attachment.instance.file_file_name)
  10. tmp_file << file.read
  11. tmp_file.flush
  12. return tmp_file
  13. end
  14. final_file = Paperclip::Transcoder.make(file, options, attachment)
  15. attachment.instance.file_file_name = File.basename(attachment.instance.file_file_name, '.*') + '.mp4'
  16. attachment.instance.file_content_type = 'video/mp4'
  17. attachment.instance.type = MediaAttachment.types[:gifv]
  18. final_file
  19. end
  20. end
  21. end