# ffmpeg-ruby **Repository Path**: anycell/ffmpeg-ruby ## Basic Information - **Project Name**: ffmpeg-ruby - **Description**: Ruby interface to the ffmpeg C library. It is able to extract images from videos but do not allow to encode full video. - **Primary Language**: C - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-11-19 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ffmpeg-ruby [project home on github](http://github.com/gwik/ffmpeg-ruby) ## 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 from git: git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg 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/kikokikoTHU/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 ```ruby require 'rubygems' require 'ffmpeg' video = FFMPEG::InputFormat.new('alligator.mp4') # => # 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 ```ruby video.first_video_stream.public_methods - Object.public_instance_methods # => ["position", "duration", "index", "codec", "decode_frame", "seek"] ``` ### Seeking in stream ```ruby video.first_video_stream.seek(10) video.first_video_stream.position # => 10.2333333333333 ``` As you can see, seeking is not very precise. ### Extracting frame ```ruby frame = video.first_video_stream.decode_frame # => # "frame size #{frame.width}x#{frame.height}" # => "frame size 240x176" ``` ### Animated GIF example with RMagick See animated_gif_example.rb