Sha256: f94ea076727f4226e503788b1316dc58c429c1c6005467c62eb4dcdded36b65d
Contents?: true
Size: 1.26 KB
Versions: 40
Compression:
Stored size: 1.26 KB
Contents
module Sufia module GenericFile module Thumbnail extend ActiveSupport::Concern # Create thumbnail requires that the characterization has already been run (so mime_type, width and height is available) # and that the object is already has a pid set def create_thumbnail return unless self.content.has_content? if video? create_video_thumbnail else create_derivatives end self.save end protected def create_video_thumbnail return unless Sufia.config.enable_ffmpeg output_file = Dir::Tmpname.create(['sufia', ".png"], Sufia.config.temp_file_base){} content.to_tempfile do |f| # we could use something like this in order to find a frame in the middle. #ffprobe -show_files video.avi 2> /dev/null | grep duration | cut -d= -f2 53.399999 command = "#{Sufia.config.ffmpeg_path} -i \"#{f.path}\" -loglevel quiet -vf \"scale=338:-1\" -r 1 -t 1 #{output_file}" system(command) raise "Unable to execute command \"#{command}\"" unless $?.success? end self.thumbnail.content = File.open(output_file, 'rb').read self.thumbnail.mimeType = 'image/png' end end end end
Version data entries
40 entries across 40 versions & 2 rubygems