v4l2.cr
Crystal bindings for V4L2 (Video for Linux 2 API).
Requirements
- Linux
- Crystal >= 0.35.1
Installation
-
Add the dependency to your
shard.yml
:dependencies: crystal-v4l2: github: postmodern/v4l2.cr
-
Run
shards install
Examples
Reading a single JPEG frame:
require "v4l2"
V4L2::Device.open("/dev/video0") do |device|
device.video_capture.format do |format|
format.width = 640
format.height = 480
format.pixel_format = V4L2::PixFmt::MJPEG
end
format = device.video_capture.format
puts "Format: #{format.pixel_format} #{format.width}x#{format.height}"
device.video_capture.malloc_buffers!(4, format.size_image)
device.video_capture.capture! do
device.video_capture.read_frame do |frame|
File.write("image.jpg",frame.bytes)
end
end
end
See examples for additional examples.
Testing
sudo modprobe v4l2lloopback
VIDEO_DEV=/dev/videoX crystal spec
TODO
- Document public API.
- Write specs meant to be ran manually with a webcam.
- Tag a 0.1.0 release.
Contributing
- Fork it (https://github.com/postmodern/crystal-v4l2/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Postmodern - creator and maintainer