Select page from this chapter: omAnnotatedVideo, omNaiveMeanAngle, omSnoutData, omWhiskerBaseAngles

omAnnotatedVideo

Overview

This method creates a video file based on the original video file, but with selected tracking overlaid, and various other manipulations. The file usually covers the frame range from the first tracking to the last tracking available in the job. This overlaying of additional information is known as "annotation", hence the method name.

Advice on Encoding

A variety of options are provided for video encoding. The main one is whether to use Matlab's avifile or VideoWriter to write the video. Depending on this choice, different compression methods will be available.

avifile is available in all Matlab versions as far as I know. It uses facilities from the OS to write the video file (e.g. DirectShow on Windows), and so it can use any codec that is appropriately installed on the machine. On the downside, there is often limited control over those codecs since Matlab does not know how to interact with them.

VideoWriter is only available in R2011a or later, but is more robust to use since Mathworks supply the codecs themselves. On the downside, it offers a limited set of codecs (in fact, only None or Motion JPEG, if you want to write an AVI file rather than an MJ2 file).

On Windows, at least, a highly recommended approach to encoding is to use avifile with the codec "Xvid" (an implementation of MPEG4-2, find it using Google). Files encoded with Xvid are readable on any system that can read MPEG4-2 (e.g. systems with DivX installed, which includes many DVD players!) and are thus highly compatible.

On Linux, the situation is different. Matlab (at least older versions) will not use any codec other than "None" with avifile. VideoWriter should work, according to the documentation, but I've not tried it. However, you can take another approach on Linux. This is to use avifile with "None", and then use the Post-encode Operation to do the compression post hoc. If you are familiar with ffmpeg, you should find this fairly transparent - see below for details.

On OSX, I have not had the opportunity to try. Let me know your experiences and I'll post them here.

Encoding Parameters

Video writer

Choose which video writer to use when generating the output file. avifile is the old-fashioned one; if you have Matlab R2011a or later, you can have a go with VideoWriter, which provides different compression options.

Codec (avifile)

If you have selected avifile as the video writer, choose a codec from those listed. The codec you choose must, of course, be installed on your machine. If you have a codec installed that is not listed and you want to use that, please contact the developers. We will let you know how to try it out and, if it works ok, we will add it to the list in future releases.

Codec (VideoWriter)

If you have selected VideoWriter as the video writer, choose a codec from those listed. Try help VideoWriter in Matlab for details.

Compression quality (%)

For some codecs, this quality setting will influence the size of the output file. For some others, this setting is currently ignored. Which it works for, and which it doesn't, is up to Mathworks. On Windows, I know that it works correctly for the VideoWriter/Motion JPEG and avifile/Indeo5 combinations, and does not work for avifile/Xvid. Note that Indeo5 is not even offered, because this codec is so old and so bad.

Compression factor

For the VideoWriter/Motion Jpeg 2000 combination, this quality setting will influence the size of the output file. See help VideoWriter for details.

Post-encode operation

This is a command-line (OS shell) string to be run after the video file has been written - typically, you would use this if you want to use your own compression (like ffmpeg). The tokens $src and $dst are expanded to the input and output files. An example would be

ffmpeg -i "$src" -vcodec mpeg "$dst"

in which case you should probably choose "None" as the video writer codec.

Other Parameters

Show progress

Select whether to show the frames as they are added to the video. This makes no difference to the video file.

Playback rate (FPS)

Influences only the rate at which the resulting video will play back in your video player.

Translate item to center

If this value is set to Snout center or Nose tip, each video frame is translated so that the specified item is at the center of the frame. Some blank space will be introduced at the frame edge, so you may want to crop the video using Crop factor.

Rotate head to face...

If this value is set to a direction (anything other than Do not rotate), the video is rotated around its center so that the animal snout faces in the specified direction. This setting is best used along with Translate item to center. Some blank space will be introduced at the frame edge, so you may want to crop the video using Crop factor.

Crop factor

Crop the video along all edges to leave the specified percentage of its original size.

Scale factor

Scale the video to the specified percentage of its original size.

Normalise image histogram

If this flag is set, the image is normalised (2/98 histogram equalisation) on a per-frame basis.

Skip interposed frames

This method writes only the range of the video that contains some results. If some early frames have results, and some late frames, but the frames in the middle do not, this flag decideds whether to include them in the video. If the flag is set, videos will consist solely of contiguous frames from the original video, but may have (possibly, large) regions within them that have no annotation.

Include frame index

Overlay the frame index in the corner of each image.

Include nose tip

Overlay the tip of the nose (in frames where snout tracking is available).

Include snout center

Overlay the snout center (in frames where snout tracking is available).

Include snout tracking

Overlay the snout contour (in frames where snout tracking is available).

Include whisker tracking

Overlay the whisker contours (in frames where whisker tracking is available).