Git Product home page Git Product logo

ffmpeg-ruby's Introduction

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

ffmpeg-ruby's People

Contributors

gwik avatar

Stargazers

 avatar

Watchers

 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.