User Guide

This package provides support for dealing with videos in an equivalent way to dealing with other data files in Bob, i.e., by using and

>>> my_video = numpy.random.random_integers(0,255,(30,3,256,256))
>>>'uint8'), 'testvideo.avi') # saving the video avi format with a default codec
>>> my_video_copy ='testvideo.avi')

Video reading and writing is performed using an FFmpeg (or libav if FFmpeg is not available) bridge. Bob’s method will allow you to choose the output format with the same extension mechanism as mentioned earlier. FFmpeg will then choose a default codec for the format and perform encoding. The output file can be as easily loaded using

For finer control over the loading, saving, format and codecs used for a specific encoding or decoding operation, you must directly use either or classes. For example, it is possible to use to read videos frame by frame and avoid overloading your machine’s memory. In the following example you can see how to create a video, save it using the class and load it again using the class The created video will have 30 frames generated randomly.


Due to FFmpeg constrains, the width and height of the video need to be multiples of two.

>>> width = 50; height = 50;
>>> framerate = 24
>>> outv ='testvideo.avi', height, width, framerate, codec='mpeg1video') # output video
>>> for i in range(0, 30):
...   newframe = (numpy.random.random_integers(0,255,(3,height,width)))
...   outv.append(newframe.astype('uint8'))
>>> outv.close()
>>> input ='testvideo.avi')
>>> input.number_of_frames
>>> inv = input.load()
>>> inv.shape
(30, 3, 50, 50)
>>> type(inv)
<... 'numpy.ndarray'>

Videos in Bob are represented as sequences of colored images, i.e. 4D arrays of type uint8. All the extensions and formats for videos supported in version of Bob installed on your machine can be listed using the Bob’s utility


Please read Using Videos with Bob for details on choosing codecs and formats that are adequate to your application, as well as drawbacks and pitfalls with video encoding and decoding.