Version

Quick search

Video

Core class for reading video files and managing the video Texture.

Changed in version 3.0.0: Extended VideoBase with:

  • VideoBase.generate_thumbnail() classmethod for creating a Texture from a frame at a given timestamp without instantiating / playing the video.

  • VideoBase.buffering observable boolean that is True while playback is delayed/stalled while trying to satisfy state='play', and the VideoBase.on_buffering event that fires whenever it changes.

  • VideoBase.options provider-specific options dict so apps can pass opaque configuration through to the backend implementation. Each provider documents the keys it honors.

Changed in version 1.10.0: The pyglet, pygst and gi providers have been removed.

Changed in version 1.8.0: There are now 2 distinct Gstreamer implementations: one using Gi/Gst working for both Python 2+3 with Gstreamer 1.0, and one using PyGST working only for Python 2 + Gstreamer 0.10.

Note

Recording is not supported.

class kivy.core.video.VideoBase(**kwargs)

Bases: kivy.event.EventDispatcher

VideoBase, a class used to implement a video reader.

Parameters:
filename: str

Filename of the video. Can be a file or an URI.

eos: str, defaults to ‘pause’

Action to take when EOS is hit. Can be one of ‘pause’, ‘stop’ or ‘loop’.

Changed in version 1.4.0: added ‘pause’

async: bool, defaults to True

Load the video asynchronously (may be not supported by all providers).

autoplay: bool, defaults to False

Auto play the video on init.

options: dict, defaults to {}

Provider-specific options forwarded opaquely to the underlying implementation. The base class consumes the documented kwargs above; any other keys are placed in options for the selected provider to consume. Each provider documents the keys it honors. Keys not recognized by the selected provider are typically logged as a warning and ignored.

New in version 3.0.0.

Events:
on_eos

Fired when EOS is hit.

on_load

Fired when the video is loaded and the texture is available.

on_frame

Fired when a new frame is written to the texture.

on_buffering

Fired when buffering changes. Strictly a transition event; the boolean is also readable as a property.

New in version 3.0.0.

property buffering

Whether playback is currently delayed/stalled while trying to satisfy state='play'. Always False while state is 'pause' or 'stop' (the player is doing what was asked; there is no delay relative to intent). True covers both the initial pre-playback wait (asset still loading, buffer still filling) and any mid-stream rebuffer. Providers update this from their own authoritative signal; providers that cannot detect stalls leave it False. Apps that want a loading overlay can use not video.loaded or video.buffering as the gate.

New in version 3.0.0.

property duration

Get the video duration (in seconds)

property filename

Get/set the filename/uri of the current video

classmethod generate_thumbnail(filename, time, size=None)

Generate a thumbnail Texture from the given video file at the given timestamp, without requiring playback.

Parameters:
filename: str

Path or URI to the video.

time: float

Timestamp in seconds at which to grab the thumbnail.

size: tuple of (int, int), optional

Target (width, height). When None the source video’s native frame size is used.

Returns:

A Texture containing the decoded frame, or None if the provider does not support thumbnail generation or could not decode the asset at the requested time.

Providers should override this. The default implementation logs an informational message and returns None.

New in version 3.0.0.

load()

Load the video from the current filename

on_buffering(value)

Fired when buffering transitions.

value is the new buffering state (True or False).

New in version 3.0.0.

property options

Get the provider-specific options dict that was passed to the provider at construction time. Read-only at the base class level; providers may mutate it during their lifetime.

New in version 3.0.0.

pause()

Pause the video

New in version 1.4.0.

play()

Play the video

property position

Get/set the position in the video (in seconds)

seek(percent, precise=True)

Move to position as percentage (strictly, a proportion from 0 - 1) of the duration

property state

Get the video playing status

stop()

Stop the video playing

property texture

Get the video texture

unload()

Unload the actual video

property volume

Get/set the volume in the video (1.0 = 100%)