OpenMediaLib User and Development Guide

High Level Use

NB: The following relies on code which is currently placed in test/openmedialib/python

The following snippet is a python example that provides a transcoder from an avi file to an mpeg file:

import bootstrap
import openpluginlib
import openmedialib

openpluginlib.init( “” )
	input = openmedialib.create_input( “input.avi” )
	frame = input.fetch( )
	store = openmedialib.create_store( “output.mpg”, frame )
	if store.init( ):
		i = 1
		while i < input.get_frames( ):
			if not store.push( frame ):
				print “failed to push frame”
				break
			input.seek( i, False )
			frame = input.fetch( )
			i += 1
		store.complete( )

Note that the the general interface to our input is simply via 'fetch' and 'seek' methods, and a store has a 'push' method.

A more interesting example is in the generation of a filter graph – this example simply composites the video given as an input on to a black background such that the video itself doesn't get cropped:

import bootstrap
import openpluginlib
import openmedialib
import stacks
import common

openpluginlib.init( “” )
rpn = stacks.stack( )
rpn.push_args( [ "colour:" ] )
rpn.push_args( sys.argv )
rpn.push_args( [ "filter:composite", “slot=1” ] )
input = rpn.pop( )
common.play( input )

In this example, we introduce a new OML class – the 'stack'.

The stack provides a non-ambiguous grammar for the construction of complex filter graphs – it is responsible for acquiring and connecting OML nodes. The theory behind this and more examples of use are shown in the following sections.

Also note that common.play is a convenience function which is just a reiteration of the fetch/push loop in the previous example – it attempts to locate a video playout surface (sdl, glew or caca are supported) and an audio playout component (currently, this is restricted to openal).