Kamaelia docs : Kamaelia.Video.CropAndScale

Video frame cropping and scaling

This component applies a crop and/or scaling operation to frames of RGB video.

Requires PIL - the python imaging library.

Example Usage

Crop and scale a YUV4MPEG format uncompressed video file so that the output is the region (100,100) ->(400,300), scaled up to 720x576:

from Kamaelia.File.Reading import RateControlledFileReader

Pipeline( RateControlledFileReader("input.yuv4mpeg", ... ),
          CropAndScale(newsize=(720,576), cropbounds=(100,100,400,300)),

More details

Initialise this component specifying the region of the incoming video frames to crop to, and the size of the desired output (the cropped region will be scaled up/down to match this).

Send frame data structures to the "inbox" inbox of this component. The frames will be cropped and scaled and output from the "outbox" outbox. Only frames with one of the following pixel formats are currently supported:

"RGB_interleaved" "RGBA_interleaved" "Y_planar"

See below for a description of the uncompressed frame data structure format. Send uncompressed video frames, in the format described below,

This component supports sending data out of its outbox to a size limited inbox. If the size limited inbox is full, this component will pause until it is able to send out the data. Data will not be consumed from the inbox if this component is waiting to send to the outbox.

If a producerFinished message is received on the "control" inbox, this component will complete parsing any data pending in its inbox, and finish sending any resulting data to its outbox. It will then send the producerFinished message on out of its "signal" outbox and terminate.

If a shutdownMicroprocess message is received on the "control" inbox, this component will immediately send it on out of its "signal" outbox and immediately terminate. It will not complete processing, or sending on any pending data.


A frame is a dictionary data structure, containing at minimum one of these combinations:

  "yuv" : luminance_data
  "pixformat" :  pixelformat        # format of raw video data
  "size" : (width, height)          # in pixels

  "rgb" : rgb_interleaved_data
  "pixformat" :  pixelformat        # format of raw video data
  "size" : (width, height)          # in pixels

CropAndScale only guarantees to fill in the fields above. Any other fields will be transparently passed through, unmodified.


class CropAndScale(Axon.Component.component)

CropAndScale(newsize, cropbounds) -> new CropAndScale component.

Crops and scales frames of video in RGB format.

Keyword arguments:

  • newsize -- (width, height) of the resulting output video frames (in pixels)
  • cropbounds -- (x0,y0,x1,y1) region to crop out from the incoming video frames (in pixels)

Methods defined here


You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.


Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!

Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.

-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT

Kamaelia is an open source project originated from and guided by BBC Research. For more information browse the site or get in contact.

This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)

(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved.

This web site is powered by the same code created for the bicker manor project. For more details, contact Michael Sparks at BBC Research directly (cf contact)