summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-10-05 14:58:46 +0200
committerClaire <claire.github-309c@sitedethib.com>2023-10-05 14:59:08 +0200
commit0bc7bd75cbabb31224d5214a4897d7bf50d981a0 (patch)
tree203de6d4b3d9f2c5486239a58450c761f33d1af1
parent40ba6e119b7457161fd43b449875d0fb9d473c1a (diff)
Add passthrough options for audio attachmentsfixes/audio-passthrough
-rw-r--r--app/models/media_attachment.rb16
-rw-r--r--lib/paperclip/transcoder.rb6
2 files changed, 21 insertions, 1 deletions
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index b567003fb95..c1bc7dac946 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 d2d946d3ade..00fb4767bbd 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)