2017-03-05 22:55:24 +01:00
|
|
|
# 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
|
2020-03-09 23:15:59 +01:00
|
|
|
movie = FFMPEG::Movie.new(@file.path)
|
|
|
|
actual_options = options
|
|
|
|
passthrough_options = actual_options[:passthrough_options]
|
|
|
|
actual_options = passthrough_options[:options] if passthrough?(movie, passthrough_options)
|
2019-10-03 01:09:12 +02:00
|
|
|
|
2020-03-09 23:15:59 +01:00
|
|
|
attachment.instance.type = MediaAttachment.types[:gifv] unless movie.audio_codec
|
2017-03-05 22:55:24 +01:00
|
|
|
|
2020-03-09 23:15:59 +01:00
|
|
|
Paperclip::Transcoder.make(file, actual_options, attachment)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def passthrough?(movie, options)
|
|
|
|
options && options[:video_codec_whitelist].include?(movie.video_codec) && options[:audio_codec_whitelist].include?(movie.audio_codec)
|
2017-03-05 22:55:24 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|