VideoWriter

class VideoWriter(output_path='output.avi', fps=30, color=True, codec='MJPG')

Save a video clip to a file.

VideoWriter can be instantiated as a context manager:

with edgeiq.VideoWriter('/path/to/output/video.avi') as video_writer:
    ...

To use VideoWriter directly, make sure to call close() when usage is complete:

video_writer = edgeiq.VideoWriter('/path/to/output/video.avi')
...
video_writer.close()

Typical usage:

with edgeiq.VideoWriter('/path/to/output/video.avi') as video_writer:
    while True:
        <read and process frame>
        video_writer.write_frame(frame)
Parameters
  • output_path (string) – The path to save the video file at.

  • fps (integer) – The number of frames per second to save.

  • color (boolean) – If True, save the video in color.

  • codec (string) – The video codec to use for saving the video clip.

write_frame(frame)

Save the frame to the video clip.

Parameters

frame (numpy array of frame) – The video frame to save.

close()

Finish creating the video clip.

class EventVideoWriterState(value)

States of the EventVideoWriter

IDLE = 'Idle'
RECORDING = 'Recording'
POST_ROLL = 'Post-roll'
class EventVideoWriter(pre_roll=150, post_roll=150, fps=30, color=True, codec='MJPG')

Save a segment of a video stream based upon an event trigger.

EventVideoWriter can be instantiated as a context manager:

with edgeiq.EventVideoWriter() as video_writer:
    ...

To use EventVideoWriter directly, make sure to call close() when usage is complete:

video_writer = edgeiq.EventVideoWriter()
...
video_writer.close()

Typical usage:

def video_writer_callback(event_name):
    print('Event {} has completed'.format(event_name))


with edgeiq.EventVideoWriter() as video_writer:
    while True:
        <read and process frame>
        ...
        video_writer.update(frame)

        if event_started:
            video_writer.start_event(
                '/path/to/output/video.avi', video_writer_callback, 'Event 1')

        if event_ended:
            video_writer.finish_event()
Parameters
  • pre_roll (integer) – The number of frames to capture preceding the event trigger.

  • post_roll (integer) – The number of frames to capture after the event completes.

  • fps (integer) – The number of frames per second to save.

  • color (boolean) – If True, save the video with color.

  • codec (string) – The video codec to use for saving the video clip.

property state

The current recording state.

Type

EventVideoWriterState

update(frame)

Provide a frame to be written to the video file if recording.

Parameters

frame (numpy array) – The frame to save.

start_event(output_path, callback_function=None, callback_args=())

Start a video clip recording.

Parameters
  • output_path (string) – The path to save the video.

  • callback_function (function) – A function to be called upon completing this video write. When set to None no callback is called. Actions in callback_function must be thread-safe.

  • callback_args (tuple) – Arguments to be passed to the callback function. Arguments must be thread-safe.

finish_event()

Finish a recording for an event. Note that recording continues for post_roll frames.

close()

Close the EventVideoWriter.

If a video recording is ongoing, it will be stopped and the recording will be saved.