Crystal bindings for V4L2 (Video for Linux 2 API).
- Linux
- Crystal >= 0.35.1
-
Add the dependency to your
shard.yml
:dependencies: crystal-v4l2: github: postmodern/v4l2.cr
-
Run
shards install
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.
sudo modprobe v4l2lloopback
VIDEO_DEV=/dev/videoX crystal spec
- Document public API.
- Write specs meant to be ran manually with a webcam.
- Tag a 0.1.0 release.
- 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
- Postmodern - creator and maintainer