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!

  • [x] low-level interface
    • [x] execute command for ffmpeg as a code
    • [x] unit testing supports (fake driver)
    • [x] nice command setting
    • [x] read timeout setting
    • [x] shell escape for security
    • [x] ffmpeg instropection (retrive supported formats, codecs, encoders and decoders)
    • [x] logger support
    • [x] 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


Add this line to your application's Gemfile:

gem 'mediakit'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mediakit


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

  • latest ffmpeg which have ffprobe command


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 =
ffmpeg =

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


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


default_driver = # default is popen driver
driver = # explicitly use popen driver
fake_driver = # fake driver


# setup
fake_driver =
fake_driver.output = 'output'
fake_driver.error_output = 'error_output'
fake_driver.exit_status = true
ffmpeg =

# excursie
options =
    'version' => true,
out, err, exit_status =

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

# teardown


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

# can use after call Mediakit::FFmpeg#init
Mediakit::FFmpeg::AudioCodec::CODEC_MP3 #=> #<Mediakit::FFmpeg::AudioCodec:0x007fb514040ad0> #=> "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



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


  1. Fork it ([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