github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

gwik / ffmpeg-ruby

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 54
    • 4
  • Source
  • Commits
  • Network (4)
  • Issues (0)
  • Downloads (2)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (2)
    • v0.1.1
    • v0.1.0
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Ruby interface to the ffmpeg C library — Read more

  cancel

http://blog.gwikzone.org/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

fix memory allocation in to_ppm 
Antonin Amand (author)
Thu Sep 24 15:01:22 -0700 2009
commit  30d42e832abbbadd744abca3fa22d5fdc5fcb6b7
tree    cfe8142182156649ae91bb19f3ce01e69a3222a8
parent  4263ae9f2dd262cc234e908fd21cc26eb2da77e4
ffmpeg-ruby /
name age
history
message
file .gitignore Thu Sep 24 01:37:21 -0700 2009 gitignore [Antonin Amand]
file LICENSE Sun Oct 12 09:48:13 -0700 2008 initial commit [gwik]
file README.mdown Mon Jun 01 01:21:27 -0700 2009 fix README [gwik]
file Rakefile Mon Dec 01 12:40:58 -0800 2008 * adding compile tasks with dependencies * chec... [Todd A. Fisher]
file animated_gif_example.rb Mon Dec 01 13:29:38 -0800 2008 include ruby in the headers fix a few warnings ... [Todd A. Fisher]
directory ext/ Thu Sep 24 15:01:22 -0700 2009 fix memory allocation in to_ppm [Antonin Amand]
file ffmpeg-ruby.gemspec Sun Oct 12 09:48:13 -0700 2008 initial commit [gwik]
directory spec/ Mon Dec 01 13:29:38 -0800 2008 include ruby in the headers fix a few warnings ... [Todd A. Fisher]
README.mdown

ffmpeg-ruby

project home on github

Summary

ffmpeg-ruby is a ruby C extension binding to ffmpeg/libav* library.

It's main purpose is to extract frame in order to make video thumbnails. It also give access to main video attributes (frame rate, bit rate, duration, codecs, ...)

So, it doesn't support encoding (at least for now).

Installation

Download latest sources of ffmpeg :

wget http://ffmpeg.mplayerhq.hu/ffmpeg-export-snapshot.tar.bz2
tar xjvf ffmpeg-export-snapshot.tar.bz2
cd ffmpeg-export-20*

Configure, optionally with some prefix :

./configure --prefix=/opt/ffmpeg --enable-pthreads --enable-shared --enable-gpl
make
sudo make install

You can now continue with ffmpeg-ruby.

git clone git://github.com/gwik/ffmpeg-ruby.git

cd ffmpeg-ruby
gem build ./ffmpeg-ruby.gemspec
sudo gem install ./ffmpeg-ruby-0.1.0.gem -- --with-ffmpeg-dir=/opt/ffmpeg

You can now test it :

irb
>> require 'rubygems'
=> false
>> require 'ffmpeg'
=> true
>> FFMPEG
=> FFMPEG

Tutorial

ffmpeg-ruby does not have real document YET (I promise it will change soom). You can take a look a specs for in depth usage.

Here is basic usage.

Video attributes

require 'rubygems'
require 'ffmpeg'

video = FFMPEG::InputFormat.new('alligator.mp4')
=> #<FFMPEG::InputFormat:0x5fa3c0>

video.public_methods - Object.public_instance_methods
=> ["bit_rate", "filename", "duration", "has_stream_with_codec_type?", "first_video_stream", "human_duration", "has_video?", "video_stream_count", "streams", "has_audio?", "first_audio_stream", "audio_stream_count"]

Streams

>> video.first_video_stream.public_methods - Object.public_instance_methods
=> ["position", "duration", "index", "codec", "decode_frame", "seek"]

Seeking in stream

video.first_video_stream.seek(10)
video.first_video_stream.position
=> 10.2333333333333

As you can see, seeking is not very precise.

Extracting frame

frame = video.first_video_stream.decode_frame
=> #<FFMPEG::Frame:0x5c9874>

"frame size #{frame.width}x#{frame.height}"
=> "frame size 240x176"

Animated GIF example with RMagick

See animated_gif_example.rb
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server