Coder Social home page Coder Social logo

mediainfo's Introduction

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.

For a list of all possible attributes supported:

Mediainfo.supported_attributes

Requirements

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

MediaInfo Command line,
MediaInfoLib - v0.7.25

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

mediainfo's People

Contributors

greatseth avatar d--j avatar derobo avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.