Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spider-gazelle/ffmpeg
ffmpeg crystal bindings
https://github.com/spider-gazelle/ffmpeg
Last synced: 3 months ago
JSON representation
ffmpeg crystal bindings
- Host: GitHub
- URL: https://github.com/spider-gazelle/ffmpeg
- Owner: spider-gazelle
- License: mit
- Created: 2022-12-12T10:50:19.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-30T08:53:09.000Z (3 months ago)
- Last Synced: 2024-07-30T11:57:08.777Z (3 months ago)
- Language: Crystal
- Homepage:
- Size: 69.3 KB
- Stars: 19
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - ffmpeg - FFmpeg bindings that works with StumpyPNG to extract frames (Image processing)
README
# ffmpeg bindings for crystal lang
[![CI](https://github.com/spider-gazelle/ffmpeg/actions/workflows/ci.yml/badge.svg)](https://github.com/spider-gazelle/ffmpeg/actions/workflows/ci.yml)
Primarily to extract video frames from streams and files for processing by AI.
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
ffmpeg:
github: spider-gazelle/ffmpeg
```2. Run `shards install`
3. ensure the required libraries are installed
* `sudo apt install libswscale-dev`
* `sudo apt install libav-tools` or `sudo apt install ffmpeg`## Usage
parsing a video file, outputs [StumpyCore Canvas](https://github.com/stumpycr/stumpy_core#stumpy_core)
```crystal
require "ffmpeg"
video = Video::File.new("./test.mp4")
video.each_frame do |frame|
puts "key frame? #{frame.key_frame?}"
frame # => FFmpeg::Frame
frame.to_canvas # => StumpyCore::Canvas
end```
also supports UDP streams (unicast or multicast)
```crystal
require "ffmpeg"
video = Video::UDP.new("udp://239.0.0.2:1234")
video.each_frame do |frame|
frame # => FFmpeg::Frame
frame.to_canvas # => StumpyCore::Canvas
end```
You can also scale the frames
```crystal
require "ffmpeg"
video = Video::File.new("./test.mp4")
# the scaler context
scaler = uninitialized FFmpeg::SWScale# scaled frame we'll use for storing the scaling output
scaled_frame = uninitialized FFmpeg::Framevideo.on_codec do |codec|
# scale by 50%
width = codec.width // 2
height = codec.height // 2
scaler = FFmpeg::SWScale.new(codec, width, height, codec.pixel_format)
scaled_frame = FFmpeg::Frame.new width, height, codec.pixel_format
endvideo.each_frame do |frame|
scaler.scale frame, scaled_frame# do something with the scaled frame
scaled_frame.to_canvas
end```
See the specs for more detailed usage
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Contributors
- [Stephen von Takach](https://github.com/stakach) - creator and maintainer