Sha256: 1ad517046b57d255f5d4c088ec4c1ac76f4b7bc99d38e019ec48526c94957534

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

module Hydra::Derivatives
  module Video
    class Processor < Hydra::Derivatives::Processor
      include Ffmpeg

      class_attribute :config
      self.config = Config.new

      protected

      def options_for(format)
        input_options=""
        output_options = "-s #{config.size_attributes} #{codecs(format)}"

        if (format == "jpg")
          input_options +=" -itsoffset -2"
          output_options+= " -vframes 1 -an -f rawvideo"
        else
          output_options +=" #{config.video_attributes} #{config.audio_attributes}"
        end

        { Ffmpeg::OUTPUT_OPTIONS => output_options, Ffmpeg::INPUT_OPTIONS => input_options}
      end

      def codecs(format)
        case format
        when 'mp4'
          config.mpeg4.codec
        when 'webm'
          config.webm.codec
        when "mkv"
          config.mkv.codec
        when "jpg"
          config.jpeg.codec
        else
          raise ArgumentError, "Unknown format `#{format}'"
        end
      end

      def new_mime_type(format)
        format == "jpg" ? "image/jpeg" : "video/#{format}"
      end
    end
  end
end


Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hydra-derivatives-1.2.1 lib/hydra/derivatives/video/processor.rb
hydra-derivatives-1.2.0 lib/hydra/derivatives/video/processor.rb
hydra-derivatives-2.0.0 lib/hydra/derivatives/video/processor.rb
hydra-derivatives-1.1.0 lib/hydra/derivatives/video/processor.rb
hydra-derivatives-1.0.0 lib/hydra/derivatives/video/processor.rb