Skip to content

postmodern/v4l2.cr

Repository files navigation

v4l2.cr

Crystal bindings for V4L2 (Video for Linux 2 API).

Requirements

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      crystal-v4l2:
        github: postmodern/v4l2.cr
  2. 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

  1. sudo modprobe v4l2lloopback
  2. 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

  1. Fork it (https://github.com/postmodern/crystal-v4l2/fork)
  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

About

Crystal bindings for V4L2

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published