Sha256: ddc52cb73429642ec2cf64b977ca2e23e688d6e2bfbd6f591f4ee51bce9fecfc

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

module Pageflow
  module Vr
    class ProjectionAutoDetection
      def call(options)
        file = options[:file]
        return unless file.is_a?(VideoFile)
        usage = file.usages.first

        if dimension_present?(file) && auto_detection_enabled?(usage)
          update(usage, file)
        end
      end

      private

      def dimension_present?(video_file)
        video_file.width.present? && video_file.height.present?
      end

      def auto_detection_enabled?(file_usage)
        file_usage.configuration['projection'] == 'auto_detect'
      end

      def update(usage, video_file)
        usage.configuration =
          usage.configuration.merge(projection: detect_projection(video_file))

        usage.save!
      end

      def detect_projection(video_file)
        if video_file.width == video_file.height
          'equirectangular_stereo'
        elsif video_file.width == video_file.height * 2
          'equirectangular_mono'
        else
          ''
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pageflow-vr-1.0.0 lib/pageflow/vr/projection_auto_detection.rb