]> cat aescling's git repositories - mastodon.git/commitdiff
Fix videos with unsupported colorspace not being transcoded (#13242)
authorThibG <thib@sitedethib.com>
Tue, 10 Mar 2020 10:58:40 +0000 (11:58 +0100)
committerGitHub <noreply@github.com>
Tue, 10 Mar 2020 10:58:40 +0000 (11:58 +0100)
app/models/media_attachment.rb
lib/paperclip/video_transcoder.rb

index 9ca0a6cda8fba5b4263521728c2356efbe81639d..31aa918b73c7182bca4d37a1ba937e429b95dc41 100644 (file)
@@ -78,8 +78,9 @@ class MediaAttachment < ApplicationRecord
   }.freeze
 
   VIDEO_PASSTHROUGH_OPTIONS = {
-    video_codec_whitelist: ['h264'],
-    audio_codec_whitelist: ['aac', nil],
+    video_codecs: ['h264'],
+    audio_codecs: ['aac', nil],
+    colorspaces: ['yuv420p'],
     options: {
       format: 'mp4',
       convert_options: {
index 0de5489646ba01505105540f9fdb9fd54fdf4846..4d9544231e360ba0602a4c6817484d2c99253c43 100644 (file)
@@ -6,19 +6,21 @@ module Paperclip
   class VideoTranscoder < Paperclip::Processor
     def make
       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 movie.audio_codec
 
-      Paperclip::Transcoder.make(file, actual_options, attachment)
+      Paperclip::Transcoder.make(file, actual_options(movie), attachment)
     end
 
     private
 
-    def passthrough?(movie, options)
-      options && options[:video_codec_whitelist].include?(movie.video_codec) && options[:audio_codec_whitelist].include?(movie.audio_codec)
+    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