about summary refs log tree commit diff
path: root/lib/paperclip/video_transcoder.rb
blob: 4d9544231e360ba0602a4c6817484d2c99253c43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module Paperclip
  # This transcoder is only to be used for the MediaAttachment model
  # to check when uploaded videos are actually gifv's
  class VideoTranscoder < Paperclip::Processor
    def make
      movie = FFMPEG::Movie.new(@file.path)

      attachment.instance.type = MediaAttachment.types[:gifv] unless movie.audio_codec

      Paperclip::Transcoder.make(file, actual_options(movie), attachment)
    end

    private

    def actual_options(movie)
      opts = options[:passthrough_options]
      if opts && opts[:video_codecs].include?(movie.video_codec) && opts[:audio_codecs].include?(movie.audio_codec) && opts[:colorspaces].include?(movie.colorspace)
        opts[:options]
      else
        options
      end
    end
  end
end