Project

ogg-ruby

0.0
No release in over 3 years
A Ruby FFI binding library for libogg, providing OGG container format stream operations (page read/write, packet assembly/disassembly).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 1.15
 Project Readme

ogg-ruby Gem Version Ruby

Ruby FFI bindings for libogg, the OGG container format library.

Requirements

  • Ruby 3.1+
  • libogg installed on your system

Installing libogg

macOS:

brew install libogg

Debian/Ubuntu:

sudo apt-get install libogg-dev

Fedora/RHEL:

sudo dnf install libogg-devel

Installation

Add this line to your application's Gemfile:

gem "ogg-ruby"

And then execute:

bundle install

Or install it yourself as:

gem install ogg-ruby

Usage

Encoding (Packet → StreamState → Page)

require "ogg"

stream = Ogg::StreamState.new(1) # serial number

# Add packets to the stream
packet = Ogg::Packet.new(data: "Hello, OGG!", bos: true, granulepos: 0, packetno: 0)
stream.packetin(packet)

packet2 = Ogg::Packet.new(data: "More data", eos: true, granulepos: 1, packetno: 1)
stream.packetin(packet2)

# Extract pages
pages = []
while (page = stream.flush)
  pages << page.to_s
end

stream.clear

Decoding (SyncState → Page → StreamState → Packet)

require "ogg"

sync = Ogg::SyncState.new

# Write encoded data into sync
sync.write(encoded_page_data)

# Extract pages
while (page = sync.pageout)
  # Create a stream decoder with the same serial number
  stream = Ogg::StreamState.new(page.serialno)
  stream.pagein(page)

  # Extract packets
  while (packet = stream.packetout)
    puts packet.data
  end

  stream.clear
end

sync.clear

Thread Safety

libogg functions are not thread-safe. Do not share SyncState or StreamState objects across threads without external synchronization.

License

The gem is available as open source under the terms of the MIT License.