Project

rff

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
This gem provides a simple Ruby interface to FFmpeg enabling users to convert audio and video to HTML5 supported formats and monitor the process as it goes.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

rff - A Ruby gem for simple audio and video conversion for HTML5 using FFmpeg¶ ↑


Introduction¶ ↑

Are you tired of outdated, not working gems for dealing with audio and video conversion? Are you looking for something simple to convert media files in your Rails application to HTML5 formats? If so, then rff is just what you need!

The idea behind rff is to be simple media converting gem based on FFmpeg providing basic functionality for converting various media files so they can be displayed in HTML5 audio and video tags, providing command output and also parsing it to extract information about the status of conversion process (eg. percentage done, length of processed file etc.).


Changelog¶ ↑

  • version 0.1 - Written the gem classes (DO NOT USE THIS VERSION)

  • version 0.2 - Got rid of the bug with mixing outputs in OutputReader’ s buffer (was a static variable, now it is instance variable. Yeah, WHAT WAS I THINKING then?). Documented the code. Made small bugfixes.

  • version 0.2.1 - Wrapped the paths into “” to allow whitespaces and other strange characters. Added the -sn option to the FFmpeg command and disable_subtitles_decoding parameter to Processor and handlers to bypass subtitle decoding errors with some format combinations.

  • version 0.2.2 - FFmpeg existence is ensured on installation time. (DO NOT USE THIS VERSION)

  • version 0.2.3 - Bugfix on extconf.rb. (DO NOT USE THIS VERSION)

  • version 0.2.4 - Added dummy Makefile to gem specification. (DO NOT USE THIS VERSION)

  • version 0.2.5 - Fix of whitespaces in dummy Makefile.

  • version 0.2.6 - If input file is in one of needed formats and is not converted, copy it to the output directory - in handlers. Added output directory creation in handlers.

  • version 0.2.7 - There is one more possible “faulty” time that prevents rff from counting percentage - “N/A”.

  • version 0.2.8 - “N/A” bug strikes again! Fixed hopefully.

  • version 0.2.9 - Fixed bug with nil metadata values.


Installation¶ ↑

As rff is available on www.rubygems.org, all you have to do is to add:

gem 'rff'

to your Gemfile. Alternatively you can install it via:

gem install rff

command.


Usage¶ ↑

The piece of code below converts a wav file to ogg, displaying the percentage of process completion along:

proc = RFF::Processor.new("file.wav", :ogg)
proc.fire
while proc.processing_percentage < 100
  print "Completed: " + proc.format_processing_percentage
end

The Processor class construction above implies that the ogg file is placed in the same directory that the wav file and the default options are used - they provide good quality of conversion. If you want to change this behaviour, please read the documentation. You can input every format supported by FFmpeg, output format must be one of HTML5 compliant media formats - mp3, ogg or wav for audio and mp4, ogv or webm for video. The Processor class also parses a wide variety of information about input and output files - read the documentation to learn how to get it.

The piece of code below converts a wav audio file to all formats needed by HTML5 to correctly handle media with audio tag and display the overall and partial completion percentages along:

ah = RFF::AudioHandler.new("file.wav")
ah.fire_all
while ah.processing_percentage == nil || ah.processing_percentage < 100
  if ah.mp3_processor != nil
    puts "MP3 status: " + ah.mp3_processor.format_processing_percentage
  end
  if ah.ogg_processor != nil
    puts "OGG status: " + ah.ogg_processor.format_processing_percentage
  end
  if ah.wav_processor != nil
    puts "WAV status: " + ah.wav_processor.format_processing_percentage
  end
  puts "Overall status: " + ah.format_processing_percentage
  sleep(1)
end

The constructor of AudioHandler takes the same parameters that this of Processor, except of output type and video quality. If a given file is already in the HTML5 compliant format, the processor to this format is not created (as the original file can be used as a source then). To learn more, read the documentation.

The piece of code below converts a ogv video file to all formats needed by HTML5 to correctly handle media with video tag and display the overall and partial completion percentages along:

vh = RFF::VideoHandler.new("file.ogv")
vh.fire_all
while vh.processing_percentage == nil || vh.processing_percentage < 100
  if vh.mp4_processor != nil
    puts "MP4 status: " + vh.mp4_processor.format_processing_percentage
  end
  if vh.ogv_processor != nil
    puts "OGV status: " + vh.ogv_processor.format_processing_percentage
  end
  if vh.webm_processor != nil
    puts "WEBM status: " + vh.webm_processor.format_processing_percentage
  end
  puts "Overall status: " + vh.format_processing_percentage
  sleep(1)
end

The constructor of VideoHandler takes the same parameters that this of Processor, except of output type. If a given file is already in the HTML5 compliant format, the processor to this format is not created (as the original file can be used as a source then). To learn more, read the documentation.


Gem status¶ ↑

Version 0.2.9 fixes a bug with empty metadata values.


Important information¶ ↑

  • The default arguments of the processor and handlers have been set to provide quite good quality of audio and video by default (unlike FFmpeg’ s defaults). However, they are fully customizable by method options.

  • The handlers are now safe to use.

  • There are automatic RSpec tests in spec subdirectory and also some manual/custom tests in simpletests directory.

  • Any help with the known and not yet known issues is appreciated, even simple feedback.


I hope you find rff useful and enjoyable to use!