
External multimedia libraries and frameworks
There are several open source multimedia frameworks available for multimedia application development. The Python bindings for most of these are readily available. We will discuss a few of the most popular multimedia frameworks here. In the chapters that follow, we will make use of many of these libraries to create some useful multimedia applications.
Python Imaging Library
Python Imaging Library provides image processing functionality in Python. It supports several image formats. Later in this book, a number of image processing techniques using PIL will be discussed thoroughly. We will learn things such as image format conversion and various image manipulation and enhancement techniques using the Python Imaging Library.
PyMedia
PyMedia is a popular open source media library that supports audio/video manipulation of a wide range of multimedia formats.
GStreamer
This framework enables multimedia manipulation. It is a framework on top of which one can develop multimedia applications. The rich set of libraries it provides makes it easier to develop applications with complex audio/video processing capabilities. GStreamer is written in C programming language and provides bindings for some other programming languages including Python. Several open source projects use GStreamer framework to develop their own multimedia application. Comprehensive documentation is available on the GStreamer project website. GStreamer Application Development Manual is a very good starting point. This framework will be extensively used later in this group to develop audio and video applications.
Pyglet
Interested in animations and gaming applications? Pyglet is here to help. Pyglet provides an API for developing multimedia applications using Python. It is an OpenGL-based library that works on multiple platforms. It is one of the popular multimedia frameworks for development of games and other graphically intense applications. It supports multiple monitor configuration typically needed for gaming application development. Later in this book, we will be extensively using this Pyglet framework for creating animations.
PyGame
PyGame (www.pygame.org) is another very popular open source framework that provides an API for gaming application development needs. It provides a rich set of graphics and sound libraries. We won't be using PyGame in this book. But since it is a prominent multimedia framework, we will briefly discuss some of its most important modules and work out a simple example. The PyGame website provides ample resources on use of this framework for animation and game programming.
Sprite
The Sprite
module contains several classes; out of these, Sprite
and Group
are the most important. Sprite
is the super class of all the visible game objects. A Group
object is a container for several instances of Sprite.
Display
As the name suggests, the Display
module has functionality dealing with the display. It is used to create a Surface instance for displaying the Pygame window. Some of the important methods of this module include flip
and update
. The former is called to make sure that everything drawn is properly displayed on the screen. Whereas the latter is used if you just want to update a portion of the screen.
Surface
This module is used to display an image. The instance of Surface
represents an image. The following line of code creates such an instance.
surf = pygame.display.set_mode((800,600))
The API method, display.set_mode
, is used to create this instance. The width and height of the window are specified as arguments to this method.
Draw
With the Draw
module, one can render several basic shapes within the Surface
. Examples include circles, rectangles, lines, and so on.
Event
This is another important module of PyGame. An event is said to occur when, for instance, the user clicks a mouse button or presses a key and so on. The event information is used to instruct the program to execute in a certain way.
Image
The Image
module is used to process images with different file formats. The loaded image is represented by a surface.
Music
Pygame.mixer.music
provides convenient methods for controlling playback such as play, reverse, stop, and so on.
The following is a simple program that highlights some of the fundamental concepts of animation and game programming. It shows how to display objects in an application window and then interactively modify their positions. We will use PyGame to accomplish this task. Later in this book, we will use a different multimedia framework, Pyglet, for creating animations.