Project

torchcodec

0.0
No release in over 3 years
Media encoding and decoding for Torch.rb
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 0.23
 Project Readme

TorchCodec Ruby

🔥 Media encoding and decoding for Torch.rb

Build Status

Installation

First, install FFmpeg. For Homebrew, use:

brew install ffmpeg

Add this line to your application’s Gemfile:

gem "torchcodec"

Getting Started

This library follows the Python API. Some functionality is missing at the moment. PRs welcome!

Audio

Encoding

encoder = TorchCodec::Encoders::AudioEncoder.new(samples, sample_rate: 8000)
encoder.to_file("file.mp3")
tensor = encoder.to_tensor("mp3")

Decoding

decoder = TorchCodec::Decoders::AudioDecoder.new("file.mp3")
decoder.metadata
decoder.get_all_samples
decoder.get_samples_played_in_range(start_seconds: 0, stop_seconds: 1)

Video

Encoding

encoder = TorchCodec::Encoders::VideoEncoder.new(frames, frame_rate: 24)
encoder.to_file("file.mp4")
tensor = encoder.to_tensor("mp4")

Decoding

decoder = TorchCodec::Decoders::VideoDecoder.new("file.mp4")
decoder.metadata
decoder.get_frame_at(0)
decoder.get_frame_played_at(0)
decoder.get_frames_at(Torch.tensor([0, 1, 2]))
decoder.get_frames_played_at(Torch.tensor([0, 1, 2], dtype: :float64))
decoder.get_frames_in_range(0, 10, step: 3)
decoder.get_frames_played_in_range(0, 10)

FFmpeg Installation

Linux

For Ubuntu, use:

sudo apt install libavcodec-dev libavdevice-dev libavfilter-dev libavutil-dev

Mac

brew install ffmpeg

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/torchcodec-ruby.git
cd torchcodec-ruby
bundle install
bundle exec rake compile
bundle exec rake download:files
bundle exec rake test