diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index b567003fb9..c1bc7dac94 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -146,6 +146,20 @@ class MediaAttachment < ApplicationRecord original: VIDEO_FORMAT.merge(passthrough_options: VIDEO_PASSTHROUGH_OPTIONS).freeze, }.freeze + AUDIO_PASSTHROUGH_OPTIONS = { + audio_codecs: ['acc'].freeze, + options: { + format: 'mp3', + convert_options: { + output: { + 'loglevel' => 'fatal', + 'map_metadata' => '-1', + 'c:a' => 'copy', + }.freeze, + }.freeze, + }.freeze, + }.freeze + AUDIO_STYLES = { original: { format: 'mp3', @@ -156,6 +170,8 @@ class MediaAttachment < ApplicationRecord 'q:a' => 2, }.freeze, }.freeze, + + passthrough_options: AUDIO_PASSTHROUGH_OPTIONS, }.freeze, }.freeze diff --git a/lib/paperclip/transcoder.rb b/lib/paperclip/transcoder.rb index d2d946d3ad..00fb4767bb 100644 --- a/lib/paperclip/transcoder.rb +++ b/lib/paperclip/transcoder.rb @@ -115,7 +115,11 @@ module Paperclip end def eligible_to_passthrough?(metadata) - @passthrough_options && @passthrough_options[:video_codecs].include?(metadata.video_codec) && @passthrough_options[:audio_codecs].include?(metadata.audio_codec) && @passthrough_options[:colorspaces].include?(metadata.colorspace) + return false if @passthrough_options.blank? + + %i(video_codec audio_codec colorspace).all? do |attribute| + @passthrough_options["#{attribute}s".to_sym].nil? || @passthrough_options["#{attribute}s".to_sym].include?(metadata.public_send(attribute)) + end end def update_attachment_type(metadata)