diff --git a/app/services/hyrax/file_set_derivatives_service_decorator.rb b/app/services/hyrax/file_set_derivatives_service_decorator.rb index 5040f24e8..b46929d0e 100644 --- a/app/services/hyrax/file_set_derivatives_service_decorator.rb +++ b/app/services/hyrax/file_set_derivatives_service_decorator.rb @@ -4,6 +4,9 @@ module Hyrax module FileSetDerivativesServiceDecorator + # @see https://github.com/samvera/hydra-derivatives/blob/main/lib/hydra/derivatives/processors/video/config.rb#L59 + DEFAULT_VIDEO_SIZE = '320x240' + def create_pdf_derivatives(filename) Hydra::Derivatives::PdfDerivatives.create(filename, outputs: [{ label: :thumbnail, format: 'jpg', @@ -30,6 +33,23 @@ def create_image_derivatives(filename) url: derivative_url('thumbnail'), layer: 0 }]) end + + # Ensures the video dimensions do not get altered when it is ingested + def create_video_derivatives(filename) + width = Array(file_set.width).first + height = Array(file_set.height).first + original_size = "#{width}x#{height}" + size = width.nil? || height.nil? ? DEFAULT_VIDEO_SIZE : original_size + + Hydra::Derivatives::Processors::Video::Processor.config.size_attributes = size + Hydra::Derivatives::VideoDerivatives.create(filename, + outputs: [{ label: :thumbnail, format: 'jpg', + url: derivative_url('thumbnail') }, + { label: 'webm', format: 'webm', + url: derivative_url('webm') }, + { label: 'mp4', format: 'mp4', + url: derivative_url('mp4') }]) + end end end