How to monitor video while capturing to disk or transmitting over the network. A Capture Processor typically monitors video only when it is started. How does one monitor the captured video while waiting for the right instant in the video to start writing to the disk or to start transmitting?
There are several ways to monitor the captured video while saving or transmitting it simultaneously. One way is to create a clone of the capture datasource, so that one datasource can be monitored while the other is being processed. This can be slow due to data cloning and also response time of the first datasource consumer.
A second way to monitor the video is to use a MonitorControl provided by the DataSource. On Windows, this monitor is a native window that does not interact well with Java AWT/Swing components and cannot be finely controlled in terms of preview rate.
A third way is to use the MonitorControl provided by the Processor. This monitor, unfortunately, only works while the Processor is in the Started state because of the data flow semantics.
Another technique, which is slightly more involved, and is the one we will explore in this example, is to intercept the data carried from the capture data source to the Processor. Since the Processor only takes a DataSource as an input, the intercepting object needs to be a DataSource.
The solution program consists of several classes: CaptureUtil, MonitorCDS, MonitorStream and JVidCap.
MonitorCDS is a DataSource wrapper that intercepts the actual capture DataSource and becomes the new DataSource for the transcoding Processor.
MonitorStream is the SourceStream contained in MonitorCDS. This class does the actual interception of the data buffers from the capture device, displays them and passes them along to the Processor. MonitorStream also exports a MonitorControl object that the developer can use to monitor the captured video.
CaptureUtil is a utility class that provides a capture datasource, given an AudioFormat and a VideoFormat object. It creates the original capture datasources, wraps the video capture datasource with MonitorCDS and creates a merged datasource of the audio and video streams.
JVidCap is a sample capture-to-disk program that shows how to use the CaptureUtil and MonitorStream classes. The JVidCap GUI allows the user to select approximate audio and video capture formats. The user can start/pause/resume/end the capture using the provided buttons.
Everytime a format attribute is changed, the capture datasource is re-initialized and a new Processor is created. When the user hits Start, a DataSink to write the data is also created and captured data is written to disk. The file is always saved in the current directory as "capture.mov" or "capture.avi" based on the selected file type.
Please read the source code for further explanations and comments.