Player

Provides the base class for video players.

class cpl_media.player.BasePlayer(**kwargs)

Bases: EventDispatcher, KivyMediaBase

Base class for every player.

_config_props_: Tuple[str] = ('metadata_play', 'metadata_play_used')

A list of configurable property names of the class that is set/read by the configuration API.

Each sub/super-class can define this and the properties are accumulated across all the sub/super-classes.

apply_config_property(name, value)

(internal) used by the config system to set the special config data of the player.

can_play

Whether the video source can play now.

complete_start(*largs)

After play(), this is called to set the player into playing play_state.

complete_stop(*largs)

After stop(), this is called to set the player into none play_state.

If the thread is ending before stop() was called, this may be called without stop() being called.

data_rate

The estimated rate in B/s at which the camera is playing.

display_frame = None

Called from kivy thread to display the frame whenever a new image arrives. This is called once per kivy frame, so if multiple images arrive during a kivy frame, it is called only for the last one.

This callback takes two arguments: (image, metadata), where image is the ffpyplayer.pic.Image, and metadata is a dict with metadata.

display_trigger = None

Clock trigger to call display_frame() in the kivy thread.

frame_callbacks = []

A list of callbacks that are called from the internal thread whenever a new image is available.

All the callbacks are called with a single tuple argument (image, metadata), where image is the ffpyplayer.pic.Image, and metadata is a dict with metadata.

It always contains at least the key 't' indicating the timestamp of the image, but it may also contains other metadata keys specific to the player such as 'count' for the frame number, when sent by the camera.

frames_played

The number of frames that have been played since play() was called.

get_config_property(name)

(internal) used by the config system to get the special config data of the player.

last_image = None

The last ffpyplayer.pic.Image received by the camera.

last_image_metadata = {'t': 0}

The metadata of the last image received by the camera.

metadata_play

(internal) Describes the video metadata of the video player. This is the requested format, or best guess of the metadata.

Read only.

metadata_play_used

(internal) Describes the video metadata of the video player that is actually used by the player. This must be set before recorders may allow recording the player.

Depending on the metadata needed by the recorder, it may refuse to record until the needed metadata is given.

Read only.

play()

Starts playing the video source and sets the play_state to starting.

May be called from main kivy thread only.

May only be called when play_state is none, otherwise an exception is raised.

Players need to eventually call complete_start() to finish starting playing.

play_state

The current state of the state machine of the player.

Can be one of none, starting, playing, stopping.

play_thread = None

The thread that plays the camera.

play_thread_run()

The method that runs in the internal play thread.

player_summery

Textual summary of the camera type and config options.

process_frame(frame, metadata)

Called from internal thread to process a new image frame received.

Parameters
real_rate

The estimated real fps of the video source being played.

stop(*largs, join=False)

Stops playing the video source, if it is playing and sets the play_state to stopping.

Players need to eventually call complete_stop() to finish stopping playing.

Parameters

join – whether to block the thread until the internal play thread has exited.

Returns

Whether we stopped playing (True) or were already stop(ping/ed) playing.

stop_all(join=False)

Causes all internal threads to stop and exit.

Parameters

join – Whether to wait and block the calling thread until the internal threads exit.

ts_play

The time when the camera started playing.

update_metadata(fmt=None, w=None, h=None, rate=None)

Sets metadata_play_used based on metadata_play and any values provided to the function, if not None.

use_real_time = False

Whether the video should use the current real time when we got the image, e.g. when the camera provided timestamp is not reliable.

class cpl_media.player.VideoMetadata(fmt, w, h, rate)

Bases: tuple

Namedtuple type describing a video stream.

fmt

Alias for field number 0

h

Alias for field number 2

rate

Alias for field number 3

w

Alias for field number 1