storyboard.frame module

Extract video frames.

Classes

Frame(timestamp, image) Video frame object containing a timestamp and an image.

Routines

extract_frame(video_path, timestamp[, params]) Extract a video frame from a given timestamp.

class storyboard.frame.Frame(timestamp, image)[source]

Bases: object

Video frame object containing a timestamp and an image.

Parameters:

timestamp : float

Timestamp of the frame, in seconds.

image : PIL.Image.Image

Image of the frame.

Attributes

timestamp (float)
image (PIL.Image.Image)
storyboard.frame.extract_frame(video_path, timestamp, params=None)[source]

Extract a video frame from a given timestamp.

Use FFmpeg to seek to the specified timestamp and decode the corresponding frame.

Parameters:

video_path : str

Path to the video file.

timestamp : float

Timestamp in seconds (as a nonnegative float).

params : dict, optional

Optional parameters enclosed in a dict. Default is None. See the “Other Parameters” section for understood key/value pairs.

Returns:

frame : Frame

Other Parameters:
 

ffmpeg_bin : str, optional

Name or path of FFmpeg binary. If None, make educated guess using storyboard.fflocate.guess_bins. Default is None.

codec : str, optional

Image codec used by FFmpeg when outputing the frame. Default is 'png'. There is no need to touch this option unless your FFmpeg cannot encode PNG, which is very unlikely.

frame_by_frame : bool, optional

Whether to seek frame by frame, i.e., whether to use output seeking (see https://trac.ffmpeg.org/wiki/Seeking). Default is False. Note that seeking frame by frame is extremely slow, but accurate. Only use this when the container metadata is wrong or missing, so that input seeking produces wrong image.

Raises:

OSError

If video file doesn’t exist, ffmpeg binary doesn’t exist or fails to run, or ffmpeg runs but generates no output (possibly due to an out of range timestamp).