Browse Source

Detect videos with no sound, handle them like gifv

closed-social-glitch-2
Eugen Rochko 7 years ago
parent
commit
85fce04d1b
3 changed files with 16 additions and 1 deletions
  1. +1
    -1
      app/models/media_attachment.rb
  2. +1
    -0
      config/application.rb
  3. +14
    -0
      lib/paperclip/video_transcoder.rb

+ 1
- 1
app/models/media_attachment.rb View 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

+ 1
- 0
config/application.rb View 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

+ 14
- 0
lib/paperclip/video_transcoder.rb View File

@ -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

Loading…
Cancel
Save