Skip to content

Commit

Permalink
Merge pull request #2120 from samvera/hyrax-5-fix-video-thumbnail
Browse files Browse the repository at this point in the history
🐛 Fix video thumbnail generation
  • Loading branch information
kirkkwang authored Jan 2, 2024
2 parents 84fbabf + 577c479 commit a8d190b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/services/hyrax/file_set_derivatives_service_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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

Expand Down

0 comments on commit a8d190b

Please sign in to comment.