Recorder
Provides the base class for video recorders.
- class cpl_media.recorder.BaseRecorder(**kwargs)
Bases:
EventDispatcher
,KivyMediaBase
Records images from :class:cpl_media.player.BasePlayer` to a recorder.
- _config_props_: Tuple[str] = ('metadata_record', 'requested_record_duration')
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 recorder.
- can_record
Whether the recorder source can record now.
- complete_start(*largs)
After
record()
, this is called to set the recorder into recordingrecord_state
.
- complete_stop(*largs)
After
stop()
, this is called to set the recorder into nonerecord_state
.
- data_rate
The estimated rate in B/s at which we’re recording.
- elapsed_record_time
Number of seconds we have been recording since
record()
ifrequested_record_duration
is zero, otherwise it’srequested_record_duration
minus the elapsed time.Automatically computed and updated a few times a second.
- frame_last_t_record = 0
The frame time of the device of the last recorded frame.
- frame_ts_record = 0
The frame time of the device of the first recorded frame.
- get_config_property(name)
(internal) used by the config system to get the special config data of the recorder.
- image_queue = None
The queue used to communicate with the internal recording thread.
- metadata_player
Describes the video metadata of the video player when we started recording.
- metadata_record
(internal) Describes the video metadata of the recorder. This is the requested format, or best guess of the metadata.
Read only.
- metadata_record_used
(internal) Describes the video metadata of the recorder that is actually used by the recorder.
Read only.
- player: BasePlayer = None
The :class:cpl_media.player.BasePlayer` this is being recorded from.
- record(player: BasePlayer)
Starts recording from the provided player and sets the
record_state
to starting.May be called from main kivy thread only.
May only be called when
record_state
is none, otherwise an exception is raised. Similarly, only when the player’s play state is playing. The players metadata_play_used, must also have been set to the value it’s using.Recorders need to eventually call
complete_start()
to finish starting recording.
- record_state
The current state of the state machine of the recorder.
Can be one of none, starting, recording, stopping.
State management:
All state changes happen in the kivy main thread. It starts in none state. Requesting to record takes us out of none - we cannot get back to none until the internal thread requests it and we then get back to none.
I.e. once out of none, the only way we could be back to none state is if all the internal thread requests has been processed. And only the internal thread is allowed to request we be back to none.
- record_thread = None
The internal thread that records the frames from the player.
- record_thread_run(*largs)
The method that runs in the internal record thread.
- recorder_summery
Textual summary of the recorder type and config options.
- requested_record_duration
The total duration that we should record.
If zero, duration was not set.
- static save_image(fname, img, codec='bmp', pix_fmt='', lib_opts={})
Saves the given image to disk in the format requested.
- Parameters:
fname – The filename where to save the image.
img – The
ffpyplayer.pic.Image
to save.codec – The codec to pass to
ffpyplayer.writer.MediaWriter
that determines the image type. Defaults to ‘bmp’.pix_fmt – The pixel format into which to convert the image before saving. If empty, the original pixel format is used. If the codec doesn’t support the image format, we first convert it to the closest supported format.
lib_opts – Any additional lib_opts options to pass to
ffpyplayer.writer.MediaWriter
.
- Returns:
The estimated size of the image on disk.
- stop(*largs, join=False)
Stops recording from the player, if it is recording and sets the
record_state
to stopping.Recorders need to eventually call
complete_stop()
to finish stopping recording.- Parameters:
join – whether to block the thread until the internal record thread has exited.
- Returns:
Whether we stopped recording (True) or were already stop(ping/ed) recording.
- 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_record
The time when the camera started recording.
- class cpl_media.recorder.ImageFileRecordSettingsWidget(recorder=None, **kwargs)
Bases:
BoxLayout
Settings widget for
ImageFileRecorder
.- recorder: ImageFileRecorder = None
The recorder.
- set_filename(text_wid, paths)
Called by the GUI to set the directory.
- class cpl_media.recorder.ImageFileRecorder(**kwargs)
Bases:
BaseRecorder
Records images as files to disk.
- _config_props_: Tuple[str] = ('record_directory', 'record_prefix', 'compression', 'extension')
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.
- extension
The extension of the images being saved.
- record(player: BasePlayer)
Starts recording from the provided player and sets the
record_state
to starting.May be called from main kivy thread only.
May only be called when
record_state
is none, otherwise an exception is raised. Similarly, only when the player’s play state is playing. The players metadata_play_used, must also have been set to the value it’s using.Recorders need to eventually call
complete_start()
to finish starting recording.
- record_directory
The directory into which videos should be saved.
- record_prefix
The prefix to the filename of the images being saved.
- record_thread_run(record_directory, record_prefix, compression, extension, requested_record_duration)
The method that runs in the internal record thread.
- send_image_to_recorder(image)
Sends the image to the recorder queue to save the image.
- Parameters:
image – A tuple of the image and metadata as provided to
cpl_media.player.BasePlayer.frame_callbacks
.
- stop(*largs, join=False)
Stops recording from the player, if it is recording and sets the
record_state
to stopping.Recorders need to eventually call
complete_stop()
to finish stopping recording.- Parameters:
join – whether to block the thread until the internal record thread has exited.
- Returns:
Whether we stopped recording (True) or were already stop(ping/ed) recording.
- class cpl_media.recorder.VideoRecordSettingsWidget(recorder=None, **kwargs)
Bases:
BoxLayout
Settings widget for
VideoRecorder
.- recorder: VideoRecorder = None
The recorder.
- set_filename(text_wid, paths)
Called by the GUI to set the directory.
- class cpl_media.recorder.VideoRecorder(**kwargs)
Bases:
BaseRecorder
Records images to a video file on disk.
Cannot start recording until the player fps is known. Otherwise, an error is raised.
- _config_props_: Tuple[str] = ('record_directory', 'record_fname', 'record_fname_count', 'estimate_record_rate')
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.
- compute_recording_opts(ifmt=None, iw=None, ih=None)
Computes the recording metadata to use, from the provided options and from the player’s metadata.
- estimate_record_rate
Whether to use
cpl_media.player.BasePlayer.real_rate
for the recorder frame rate, as opposed to the one initially provided by the player.
- record(player: BasePlayer)
Starts recording from the provided player and sets the
record_state
to starting.May be called from main kivy thread only.
May only be called when
record_state
is none, otherwise an exception is raised. Similarly, only when the player’s play state is playing. The players metadata_play_used, must also have been set to the value it’s using.Recorders need to eventually call
complete_start()
to finish starting recording.
- record_directory
The directory into which videos should be saved.
- record_filename
The full filename of the video that will be saved as computed by the configuration options of the instance.
- record_fname
The filename to be used to record the next video.
If
{}
is present in the filename, it’ll be replaced with the value ofrecord_fname_count
which auto increments after every video, when used. We use Python’sformat
machinery for this.
- record_fname_count
A counter that auto increments by one after every recorded video.
Used to give unique filenames for each video file. See
record_fname
.
- record_thread_run(filename, requested_record_duration)
The method that runs in the internal record thread.
- send_image_to_recorder(image)
Sends the image to the recorder queue to save the image in the video.
- Parameters:
image – A tuple of the image and metadata as provided to
cpl_media.player.BasePlayer.frame_callbacks
.
- stop(*largs, join=False)
Stops recording from the player, if it is recording and sets the
record_state
to stopping.Recorders need to eventually call
complete_stop()
to finish stopping recording.- Parameters:
join – whether to block the thread until the internal record thread has exited.
- Returns:
Whether we stopped recording (True) or were already stop(ping/ed) recording.