about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-03-09 23:15:59 +0100
committerGitHub <noreply@github.com>2020-03-09 23:15:59 +0100
commitabd839488054b6de2dec9e7ec095d79e4a106573 (patch)
tree5fb6e304461827fa3fe684a0cd5639b317f81394 /lib
parent57d98b20f29650d7e8bcaa42b824ce4d794cbcbb (diff)
Fix MP4 (H264 + AAC) video files being needlessly re-encoded (#13239)
Diffstat (limited to 'lib')
-rw-r--r--lib/paperclip/video_transcoder.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/paperclip/video_transcoder.rb b/lib/paperclip/video_transcoder.rb
index 66f7feda5..0de548964 100644
--- a/lib/paperclip/video_transcoder.rb
+++ b/lib/paperclip/video_transcoder.rb
@@ -5,12 +5,20 @@ module Paperclip
   # to check when uploaded videos are actually gifv's
   class VideoTranscoder < Paperclip::Processor
     def make
-      meta = ::Av.cli.identify(@file.path)
+      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)
 
-      attachment.instance.type = MediaAttachment.types[:gifv] unless meta[:audio_encode]
-      options[:format] = File.extname(attachment.instance.file_file_name)[1..-1] if options[:keep_same_format]
+      attachment.instance.type = MediaAttachment.types[:gifv] unless movie.audio_codec
 
-      Paperclip::Transcoder.make(file, options, attachment)
+      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)
     end
   end
 end