ExAct Futures Repository

This page is a repository for selected ExAct Futures applications and source code, primarily java.

These may be useful in the form presented, or the source code may be helpful in part or whole.

Everything presented is absolutely without any warranties, and subject in some cases to licenses.

Enjoy.


Extracting Frames from Video

This is one of a number of solutions based on reading frames from a video source. It can be used for video files or a webcam or via an url, and each image is saved as a jpeg with a timestamp. The java source has some interesting methods but is essentially straightforward. All frames are extracted from a video, and none are skipped. This can otherwise occur if using a player for grabbing frames, and this can result in incomplete frames for mpeg streams.

The file should be unzipped, and it is assumed that Sun's java is installed, and Sun's JMF. The zip also includes FOBS4JMF which extends JMF to allow reading of further video types such as mp4. The properties file included is set for Logitech webcams and for Windows. It is recommended that you install FOBS4JMF via the instructions on their site at http://fobs.sourceforge.net/f4jmf_first.html but it is possible that run.bat or sun.bat or cam.bat or runjmstudio.bat will work directly from the zipped file's contents. If not then compile and run the vid2jpg source in another folder and install FOBS by its documentation, or if you want to read videos based upon standard JMF codecs or only by a compatible webcam then you do not need FOBS. If cam.bat fails then run runjmstudio.bat and in File/Preferences/Capture Devices use Detect Capture Devices and then Commit once done.

The easiest way forward may simply be directly to compile the vid2jpg.java source and look through the code to see how to run it. It defaults to an enclosed avi file, but via the command line arguments you can set that to a webcam or url or the example avi or mp4, or other video files. It is set to save the first 1000 frames. It will run as fast as it can and will not play to the video's timestamps. The source can be amended to run using Microsoft's JVM which may be a little faster & smoother, although it cannot then be used with FOBS, but does open up being used as a COM object. Ensure you have a folder called images where the jpegs are saved. Note too the included jpg2vid.zip resource for jpeg images to MOV or AVI.

Download the source from http://www.exactfutures.com/vid2jpg.zip. Good luck.


Video Scene Change Detection

The vid2jpg above has been amended to include a simple algorithm to recognise scene changes. It has also been simplified to run using only sun's java, and FOBS on a PC. There are example .bat files for capturing from a webcam or video. The algorithm is a very simple calculation to measure a feature count in each frame, and if this changes instantly or over a number of frames it will suggest a scene change. This is no more than an introductory path into this science for those with an interest. Stronger solutions may include motion analysis or a frame colour signature or object recognition. The difficulties include defining what is a scene change when that can be an immediate total change, or one being blended in over a few frames, or one arising simply from camera motion. It may be that a simple solution yields good enough results in practice, depending upon the actual purpose and desired accuracy, and it may also be useful for video thumbnails. This code finds those scene changes that have a feature count significantly different from the previous, be that change on one frame or many, and so includes the effect of camera movement. This is just one practical implementation, and you are free to amend or enhance this code as you wish. It is similar to vid2jpg and you can download from http://www.exactfutures.com/scenechange2jpg.zip. It will also produce a jpeg for every frame if you remove one line of code. The preferred example is runfobs.bat which uses the video lotr.mp4, whilst cam.bat is also interesting because it captures a webcam in realtime and delivers a jpeg on motion detection or camera movement.


Fast Webcam Frame Grabbing and inter frame Pixel Processing

The following is a simple JMF program for capturing the video stream from a webcam and modifying by bespoke filter or effect, including adding text or graphics. It is purely for example only and to illustrate some fast methods for doing this directly. Download the classes and source from http://www.exactfutures.com/simplecam.zip. These are useful for solutions requiring fast frame processing and inter frame data manipulation. The method process(int[] prepix, int[] postpix) can be amended to filter or grab the pixel data, whilst one can also overlay graphics on the rendered panel. The Microsoft JVM may yield better performance on PCs. Bundled in with this is DrawEffect.zip which is a more conventional approach to capture a webcam, but includes though a Codec/Effect which draws on top of the video stream while it is being played. DrawEffect.zip includes the source code, and note that because it uses BufferedImage this will not run using Microsoft’s JVM. See also that the DrawEffect.java exposes the pixels integer array, and so offering scope for further modification.


Motion Detection using JMF Effect PlugIns

The link that follows includes an Effect Codec which can be simply included in the Java Media Framework post processing for motion detection & tracking. This is the same underlying code as you will discover in these pages as the Pure Motion Filter, except that this is a full JMF plugin effect. The plugin source is at http://www.exactfutures.com/ActivityEffect.zip and there is also a JMF Effect plugin GaussianEffect which improves the performance of the simple motion filter, albeit at a cost to frame speed. The source can be adapted to video streams or is set up for compatible webcams - it also includes code to preset the webcam image size and the framerate. The Gaussian works well as set, which is to 100 (the standard normal distribution sd=1.0), but of course including it in the codec list means it renders with the respective blur. The standard deviation can be reset; eg to 0, in the Player’s PlugIn Settings, else in the code, when included. The code as is does not set the Gaussian, you would need to edit and recompile. The Microsoft JVM seems fastest and smoothest on my PC. You will be interested if webcam java code or programming Effects is useful to you, or if you simply want to process the pixel stream. It may also contribute to those who need fast frame on the fly accurate motion detection for intelligent video analytics or robotics. This version is fairly feature rich and some documentation is within this site or by references. There are also links here to higher specification executables. To use simply download and unzip, then hit run.bat assuming you have already installed Java & JMF, and have a webcam recognised by the latter’s JMStudio. Note that the sensitivity can be adjusted, and that it can run in several rectangles within the frame. Enjoy, and see other notes via links on how to use.


JMF Video Server Codec

The solution offered by JMF to stream video can offer mixed results. However, with increasingly fast broadband it is possible to get reasonable results by jpeg feeds from video servers, such as those one finds built into the likes of Axis cams. The link that follows below includes a JMF Plugin Effect which does not alter the video data but does allow one to capture a jpeg frame by http. One simply adds a final ServerEffect Codec by using setCodecChain on a source video track - see example java source code – do include ServerEffect.class and ServerEffect$SvrControl.class and ServerEffect$clientThread.class in the classpath or application directory - and then any url ending in jpg will read a frame; eg in your browser enter http://localhost:8080/a.jpg or similar. There are many examples on the internet of how to stream jpeg frames by http, and on a LAN (changing localhost to an IP address) this can perform like true video. Over a network it depends upon the available bandwidth but it generally offers very acceptable results given the simplicity. The port to serve and the jpeg quality can be set in the calling code, see the source. You may have to adjust your router or firewall or security settings for the port, especially for remote access. If you enter in your browser http://localhost:8080/camapplet.htm then a simple demo applet will load which will read the video server jpeg images being served by a running TestEffect. This can be found at http://www.exactfutures.com/ServerEffect.zip and on a PC with JMF installed this can run from that folder by editing as need be & hitting the run.bat file. Once running then you can then also use the web page shortcut in this folder which will load with a link to the streaming applet.


Other JMF based Java Source for Video or Webcam Frame Analysis

Example webcam to video java source and executable http://www.exactfutures.com/webcam2vid.zip
Example IP Cam to video modification of JpegImagesToMovie.java http://www.exactfutures.com/IpImagesToMovie.zip

Links :-
http://www.exactfutures.com/index01.htm
http://www.codeproject.com/vista/activity.asp


Copyright © 2006 ExAct Futures
Last modified: May 03, 2009