Video

Video Streams

class av.video.stream.VideoStream

Bases: av.stream.Stream

average_rate

The average frame rate of this stream.

Type:fractions.Fraction

Video Codecs

class av.video.codeccontext.VideoCodecContext

Bases: av.codec.context.CodecContext

coded_height
coded_width
display_aspect_ratio
encoded_frame_count
format
framerate

The frame rate, in frames per second.

Type:fractions.Fraction
gop_size
has_b_frames
height
pix_fmt
rate

Another name for framerate.

reformatter
sample_aspect_ratio
width

Video Formats

class av.video.format.VideoFormat

Bases: object

>>> format = VideoFormat('rgb24')
>>> format.name
'rgb24'
chroma_height(luma_height=0)

Height of a chroma plane relative to a luma plane.

Parameters:luma_height (int) – Height of the luma plane; defaults to self.height.
chroma_width(luma_width=0)

Width of a chroma plane relative to a luma plane.

Parameters:luma_width (int) – Width of the luma plane; defaults to self.width.
components
has_palette

Pixel format has a palette in data[1], values are indexes in this palette.

height
is_big_endian

Pixel format is big-endian.

is_bit_stream

All values of a component are bit-wise packed end to end.

is_planar

At least one pixel component is not in the first data plane.

is_rgb

The pixel format contains RGB-like data (as opposed to YUV/grayscale).

name

Canonical name of the pixel format.

width
class av.video.format.VideoFormatComponent

Bases: object

bits

Number of bits in the component.

height

The height of this component’s plane.

Requires the parent VideoFormat to have a height.

index
is_alpha

Is this component an alpha channel?

is_chroma

Is this component a chroma channel?

is_luma

Is this compoment a luma channel?

plane

The index of the plane which contains this component.

width

The width of this component’s plane.

Requires the parent VideoFormat to have a width.

Video Frames

class av.video.frame.VideoFrame

Bases: av.frame.Frame

A frame of video.

>>> frame = VideoFrame(1920, 1080, 'rgb24')
width

Width of the image, in pixels.

height

Height of the image, in pixels.

format
static from_image(img)

Construct a frame from a PIL.Image.

static from_ndarray(array, format='rgb24')

Construct a frame from a numpy array.

interlaced_frame

Is this frame an interlaced or progressive?

key_frame

Is this frame a key frame?

pict_type
reformat(width=None, height=None, format=None, src_colorspace=None, dst_colorspace=None)

Create a new VideoFrame with the given width/height/format/colorspace.

Parameters:
  • width (int) – New width, or None for the same width.
  • height (int) – New height, or None for the same height.
  • format (str) – New format, or None for the same format; see VideoFrame.format.
  • src_colorspace (str) – Current colorspace.
  • dst_colorspace (str) – Desired colorspace.
Supported colorspaces are currently:
  • 'itu709'
  • 'fcc'
  • 'itu601'
  • 'itu624'
  • 'smpte240'
  • 'default' or None
to_image(**kwargs)

Get an RGB PIL.Image of this frame.

Any **kwargs are passed to VideoFrame.reformat().

Note

PIL or Pillow must be installed.

to_ndarray(**kwargs)

Get a numpy array of this frame.

Any **kwargs are passed to VideoFrame.reformat().

Note

Numpy must be installed.

to_rgb(**kwargs)

Get an RGB version of this frame.

Any **kwargs are passed to VideoFrame.reformat().

>>> frame = VideoFrame(1920, 1080)
>>> frame.format.name
'yuv420p'
>>> frame.to_rgb().format.name
'rgb24'

Video Planes

class av.video.plane.VideoPlane

Bases: av.plane.Plane

buffer_size

The size of the buffer in bytes.

height

Pixel height of this plane.

line_size

Bytes per horizontal line in this plane.

Type:int
width

Pixel width of this plane.

Video Reformatters

class av.video.reformatter.VideoReformatter

Bases: object