Giter Club home page Giter Club logo

mediakit's Introduction

Mediakit

Circle CI Code Climate

mediakit is the libraries for ffmpeg and sox backed media manipulation something. I've design this library for following purpose.

  • have low and high level interfaces as you like use
  • easy testing design by separation of concern

Development Plan

Currently you can use low-level inteface of mediakit!

  • low-level interface
    • execute command for ffmpeg as a code
    • unit testing supports (fake driver)
    • nice command setting
    • read timeout setting
    • shell escape for security
    • ffmpeg instropection (retrive supported formats, codecs, encoders and decoders)
    • logger support
    • formats, codecs, encoders and decoders representation as a code
  • low-level ffprobe interface
  • high-level interface for ffmpeg
  • low-level interface for sox
  • high-level interface for sox

Installation

Add this line to your application's Gemfile:

gem 'mediakit'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mediakit

Requirements

This library behave command wrapper in your script. So it need each binary command file.

  • latest ffmpeg which have ffprobe command

Usage

Low Level Interface

The low level means it's near command line usage. This is a little bore interface for constructing options, but can pass certain it.

driver = Mediakit::Drivers::FFmpeg.new()
ffmpeg = Mediakit::FFmpeg.new(driver)

options = Mediakit::FFmpeg::Options.new
options.add_option(Mediakit::FFmpeg::Options::GlobalOption.new('t' => 100))
options.add_option(Mediakit::FFmpeg::Options::InputFileOption.new(options: nil, path: input))
options.add_option(
  Mediakit::FFmpeg::Options::OutputFileOption.new(
    options: {
      'vf' => 'crop=320:320:0:0',
      'ar' => '44100',
      'ab' => '128k',
    },
    path:    output,
  )
)
puts "$ #{ffmpeg.command(options)}"
puts ffmpeg.run(options, timeout: 30, nice: 0)

Drivers

mediakit has two drivers for execute command. First, Popen Driver is implemented by Open3#popen3 that is main driver. Second, FakeDriver is the fake object for unit-testing.

Driver Usage

instatiate

default_driver = Mediakit::Drivers::FFmpeg.new # default is popen driver
driver = Mediakit::Drivers::FFmpeg.new(:popen) # explicitly use popen driver
fake_driver = Mediakit::Drivers::FFmpeg.new(:fake) # fake driver

testing

# setup
fake_driver = Mediakit::Drivers::FFmpeg.new(:fake)
fake_driver.output = 'output'
fake_driver.error_output = 'error_output'
fake_driver.exit_status = true
ffmpeg = Mediakit::FFmpeg.new(fake_driver)

# excursie
options = Mediakit::FFmpeg::Options.new(
  Mediakit::FFmpeg::Options::GlobalOption.new(
    'version' => true,
  ),
}
out, err, exit_status = ffmpeg.run(options)

# verify
assert_equal(fake_driver.last_command, 'ffmpeg -version')
assert_equal(out, 'output')
assert_equal(err, 'error_output')
assert_equal(exit_status, true)

# teardown
fake_driver.reset

Formats/Codecs/Decoders/Encoders

FFmpeg has so many formats, codecs, decoders and encoders. So, mediakit provide constant values for presenting those resources as a code.

ffmpeg = Mediakit::FFmpeg.create
ffmpeg.init

# can use after call Mediakit::FFmpeg#init
Mediakit::FFmpeg::AudioCodec::CODEC_MP3 #=> #<Mediakit::FFmpeg::AudioCodec:0x007fb514040ad0>
Mediakit::FFmpeg::AudioCodec::CODEC_MP3.name #=> "mp3"
Mediakit::FFmpeg::AudioCodec::CODEC_MP3.desc #=> "MP3 (MPEG audio layer 3)"
...

These values reflect your ffmpeg binary build conditions by automate. Mediakit::FFmpeg::AudioCodec::CODEC_MP3 is just a instance of Mediakit::FFmpeg::AudioCodec class.

High Level Interface

TBD

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/mediakit/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

References

mediakit's People

Contributors

ainame avatar ypresto avatar

Watchers

James Cloos avatar  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.