]> cat aescling's git repositories - mastodon.git/commitdiff
Detect videos with no sound, handle them like gifv
authorEugen Rochko <eugen@zeonfederated.com>
Sun, 5 Mar 2017 21:55:24 +0000 (22:55 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Sun, 5 Mar 2017 21:55:24 +0000 (22:55 +0100)
app/models/media_attachment.rb
config/application.rb
lib/paperclip/video_transcoder.rb [new file with mode: 0644]

index 620a92dbc382f89502fdbccd46e0a88614e3bef8..d560bd67354e709290302abf02dd4763af51d9df 100644 (file)
@@ -80,7 +80,7 @@ class MediaAttachment < ApplicationRecord
       if f.file_content_type == 'image/gif'
         [:gif_transcoder]
       elsif VIDEO_MIME_TYPES.include? f.file_content_type
-        [:transcoder]
+        [:video_transcoder]
       else
         [:thumbnail]
       end
index 30ed608c5e24880380bbcfcafa5bcdcdccb9c33d..cb009b24c1c265ebd56410517c04eac9f124a0ea 100644 (file)
@@ -8,6 +8,7 @@ Bundler.require(*Rails.groups)
 
 require_relative '../app/lib/exceptions'
 require_relative '../lib/paperclip/gif_transcoder'
+require_relative '../lib/paperclip/video_transcoder'
 
 Dotenv::Railtie.load
 
diff --git a/lib/paperclip/video_transcoder.rb b/lib/paperclip/video_transcoder.rb
new file mode 100644 (file)
index 0000000..c3504c1
--- /dev/null
@@ -0,0 +1,14 @@
+# 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
+      meta = ::Av.cli.identify(@file.path)
+      attachment.instance.type = MediaAttachment.types[:gifv] unless meta[:audio_encode]
+
+      Paperclip::Transcoder.make(file, options, attachment)
+    end
+  end
+end