Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

showbox-public / mediainfo   ruby

Repository URL to install this package:

  lib
  test
9y   CHANGELOG
9y   Gemfile
9y   LICENSE
9y   Manifest
9y   README.markdown
9y   Rakefile
9y   index.html.template
9y   mediainfo.gemspec
  README.markdown

Mediainfo

Mediainfo is a class wrapping the mediainfo CLI.

Installation

$ gem install mediainfo

Usage

info = Mediainfo.new "/path/to/file"

That will issue the system call to mediainfo and parse the output. You can specify an alternate path if necessary:

Mediainfo.path = "/opt/local/bin/mediainfo"

Once you have an info object, you can start inspecting streams and general metadata.

info.streams.count # 2
info.audio?        # true
info.video?        # true
info.image?        # false

When inspecting specific types of streams, you have a couple general API options. The first approach assumes one stream of a given type, a common scenario in many video files, for example.

info.video.count    # 1
info.audio.count    # 1
info.video.duration # 120 (seconds)

Sometimes you'll have more than one stream of a given type. Quicktime files can often contain artifacts like this from somebody editing a more 'normal' file.

info = Mediainfo.new "funky.mov"

info.video?            # true
info.video.count       # 2
info.video.duration    # raises SingleStreamAPIError !
info.video[0].duration # 120
info.video[1].duration # 10

For some more usage examples, please see the very reasonable test suite accompanying the source code for this library. It contains a bunch of relevant usage examples. More docs in the future.. contributions very welcome!

Moving on, REXML is used as the XML parser by default. If you'd like, you can configure Mediainfo to use Hpricot or Nokogiri instead using one of the following approaches:

  • define the MEDIAINFO_XML_PARSER environment variable to be the name of the parser as you'd pass to a :gem or :require call.

    e.g. export MEDIAINFO_XML_PARSER=nokogiri

  • assign to Mediainfo.xml_parser after you've loaded the gem, following the same naming conventions mentioned previously.

    e.g. Mediainfo.xml_parser = "hpricot"

Once you've got an instance setup, you can call numerous methods to get a variety of information about a file. Some attributes may be present for some files where others are not, but any supported attribute should at least return nil.

Requirements

This requires at least the following version of the Mediainfo CLI:

MediaInfo Command line,
MediaInfoLib - v0.7.58

Previous versions of this gem(<= 0.5.1) worked against v0.7.11, which did not generate XML output, and is no longer supported.

Contributors

This is a fork of https://github.com/greatseth/mediainfo and because it seems that greatseth is now longer maintainig the project, I will continue development.