1
0

video_transcoder.rb 776 B

1234567891011121314151617181920212223242526
  1. # frozen_string_literal: true
  2. module Paperclip
  3. # This transcoder is only to be used for the MediaAttachment model
  4. # to check when uploaded videos are actually gifv's
  5. class VideoTranscoder < Paperclip::Processor
  6. def make
  7. movie = FFMPEG::Movie.new(@file.path)
  8. attachment.instance.type = MediaAttachment.types[:gifv] unless movie.audio_codec
  9. Paperclip::Transcoder.make(file, actual_options(movie), attachment)
  10. end
  11. private
  12. def actual_options(movie)
  13. opts = options[:passthrough_options]
  14. if opts && opts[:video_codecs].include?(movie.video_codec) && opts[:audio_codecs].include?(movie.audio_codec) && opts[:colorspaces].include?(movie.colorspace)
  15. opts[:options]
  16. else
  17. options
  18. end
  19. end
  20. end
  21. end