Skip to content

Latest commit

 

History

History

Chapter 11: Processing Video Sequences

| <Previous: Chapter 10 | Next: Chapter 15> |

To process a video sequence you need access to individual frames. In JavaCV frames are accessed using a FrameGrabber. There are several concrete frame grabber classes for dealing with different devices and video files. Examples here read video sequences from files using FFmpegFrameGrabber.

General pattern for processing a video sequence, here from a video file:

import org.bytedeco.javacv.FFmpegFrameGrabber
import scala.collection.Iterator.continually
  
val grabber = new FFmpegFrameGrabber("my_video.avi")
grabber.start()

// Read frame by frame till the end of the video file (indicated by `null` frame)
for (frame <- continually(grabber.grab()).takeWhile(_ != null)) {
  // Do some processing
}

// Close the video file
grabber.release()

Similarly in Java:

FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("my_video.avi");
// Open video video file
grabber.start();

// Read frame by frame till the end of the video file (indicated by `null` frame)
Frame frame;
while ((frame = grabber.grab()) != null) {
 // Do some processing
}

// Close the video file
grabber.release();

| <Previous: Chapter 10 | Chapter 11: Processing Video Sequences | Next: Chapter 15> |