Sha256: f2d6ad818678171fbeec8c58d783487a6ae9be13b7dd3b74de485603635260e7

Contents?: true

Size: 1.15 KB

Versions: 11

Compression:

Stored size: 1.15 KB

Contents

require 'parsers/iso_base_media_file_format/utils'

class FormatParser::MOVParser
  include FormatParser::IOUtils
  include FormatParser::ISOBaseMediaFileFormat::Utils
  require_relative 'mov_parser/decoder'

  MAGIC_BYTES = 'ftypqt  '
  MOV_MIME_TYPE = 'video/quicktime'

  def likely_match?(filename)
    /\.(mov|moov|qt)$/i.match?(filename)
  end

  def call(io)
    @buf = FormatParser::IOConstraint.new(io)

    return unless matches_mov_definition?

    box_tree = Measurometer.instrument('format_parser.mov_parser.decoder.build_box_tree') do
      Decoder.new.build_box_tree(0xffffffff, @buf)
    end

    width, height = dimensions(box_tree)

    FormatParser::Video.new(
      format: :mov,
      width_px: width,
      height_px: height,
      frame_rate: frame_rate(box_tree),
      media_duration_seconds: duration(box_tree),
      content_type: MOV_MIME_TYPE,
      codecs: video_codecs(box_tree),
      intrinsics: box_tree
    )
  end

  private

  def matches_mov_definition?
    skip_bytes(4)
    matches = read_string(8) == MAGIC_BYTES
    @buf.seek(0)
    matches
  end

  FormatParser.register_parser new, natures: [:video], formats: [:mov], priority: 3
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
format_parser-2.10.0 lib/parsers/mov_parser.rb
format_parser-2.9.0 lib/parsers/mov_parser.rb
format_parser-2.8.0 lib/parsers/mov_parser.rb
format_parser-2.7.2 lib/parsers/mov_parser.rb
format_parser-2.7.1 lib/parsers/mov_parser.rb
format_parser-2.7.0 lib/parsers/mov_parser.rb
format_parser-2.6.0 lib/parsers/mov_parser.rb
format_parser-2.5.0 lib/parsers/mov_parser.rb
format_parser-2.4.5 lib/parsers/mov_parser.rb
format_parser-2.4.4 lib/parsers/mov_parser.rb
format_parser-2.4.3 lib/parsers/mov_parser.rb