This package contains code to read, write and view FlyMovieFormat files, which end with extension .fmf.
The primary design goals of FlyMovieFormat were:
These goals are acheived via using a very simple format. After an initial header containing meta-data such as image size and color coding scheme (e.g. monochromatic 8 bits per pixel, YUV422, etc.), repeated chunks of raw image data and timestamp are saved. Because the raw image data from the native camera driver is saved, no additional processing is performed. Thus, streaming of movies from camera to disk will keep the CPU free for other tasks, but it will require a lot of disk space. Furthermore, the disk bandwidth required is equivalent to the camera bandwidth (unless you save only a region of the images, or if you only save a fraction of the incoming frames).
The command ffmpeg2fmf will use avbin (part of Pyglet) to read a variety of movie formats and save them as .fmf files. Use it like so:
ffmpeg2fmf --format=mono8 /path/to/my/movie.mp4
# or
ffmpeg2fmf --format=mono8 /path/to/my/movie.avi
This will save a file /path/to/my/movie.fmf.
This module contains code to read and write FlyMovieFormat files, which end with extension .fmf.
Users may like to use these classes:
- FlyMovie : read .fmf files
- FlyMovieSaver : write .fmf files
The following Exception types may sometimes be raised:
In Python accessing frames from an .fmf files is as easy as:
import motmot.FlyMovieFormat.FlyMovieFormat as FMF
import sys
fname = sys.argv[1]
fmf = FMF.FlyMovie(fname)
for frame_number in range(10):
frame,timestamp = fmf.get_frame(frame_number)
Writing frames to an .fmf file is also easy:
import motmot.FlyMovieFormat.FlyMovieFormat as FMF
import sys
import numpy as np
fname = sys.argv[1]
fmf_saver = FMF.FlyMovieSaver(fname)
width, height = 640,480
for i in range(10):
fake_image = np.zeros( (height,width), dtype=np.uint8)
fake_timestamp = 0.0
fmf_saver.add_frame(fake_image,fake_timestamp)
fmf_saver.close()
.fmf file reader
Optional keyword arguments:
return all timestamps in .fmf file
Returns: - all_timestamps : array of timestamps
get the number of bits per pixel
Returns: - bits_per_pixel : integer, number of bits per pixel (e.g. 8)
returns height of data, in pixels
Returns: - height : integer, height of image, in pixels
get the number of frames
Returns: - n_frames : integer, number of frames
return image data for frame number
Returns:
returns width of data, in bytes
Returns: - width : integer, width of image, in bytes
Note, to get the width of underlying image, do this:
image_width = fmf.get_width()//(fmf.get_bits_per_pixel()//8)
.fmf file writer
Keyword arguments:
save a single image frame to the file
Optional keyword arguments:
add multiple image frames
Optional keyword arguments:
Bases: exceptions.Exception
The file is not a valid movie file
Bases: exceptions.Exception
A frame was requested, but no more frames exist
map .fmf file to RAM
Note: make mmap does not currently work with RGB images.
Note: to map a 4 GB or larger file to RAM, a 64 bit computer is required.