diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-03-05 22:55:24 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-03-05 22:55:24 +0100 |
commit | 85fce04d1b4353c3645c15967d222cdcdb488dfd (patch) | |
tree | bfb83bd4ec8b545b21741b633d4fd39a90fd1701 | |
parent | 4fb95c91fbf808bafa581b8976d94ec36eee8619 (diff) |
Detect videos with no sound, handle them like gifv
-rw-r--r-- | app/models/media_attachment.rb | 2 | ||||
-rw-r--r-- | config/application.rb | 1 | ||||
-rw-r--r-- | lib/paperclip/video_transcoder.rb | 14 |
3 files changed, 16 insertions, 1 deletions
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 620a92dbc..d560bd673 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -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 diff --git a/config/application.rb b/config/application.rb index 30ed608c5..cb009b24c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 index 000000000..c3504c17c --- /dev/null +++ b/lib/paperclip/video_transcoder.rb @@ -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 |