From 577c47900ff4ef7628293b7429b89be6e36cff01 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Tue, 2 Jan 2024 13:02:40 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20video=20thumbnail=20genera?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In a previous commit we created the `Hyrax::FileSetDerivativesServiceDecorator` to override the default thumbnails that Hyrax uses but I forgot to add the video thumbnail, which is fixed here. Ref - https://github.com/scientist-softserv/hykuup_knapsack/issues/69 --- .../file_set_derivatives_service_decorator.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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