DVR#
QDVRWidget#
Composite DVR widget for recording and playing back video streams.
- class QVideo.dvr.QDVRWidget.QDVRWidget(*args, source=None, filename='', **kwargs)[source]#
Bases:
QFrameWidget providing record, play, pause, stop and rewind controls for a digital video recorder.
Connects to a
QVideoSourceto capture incoming frames to a file, and can play back previously recorded files. Supported formats are determined by theWriterandPlayerclass attributes; by default AVI (.avi), MKV (.mkv), and MP4 (.mp4) are supported; HDF5 (.h5) is also supported whenh5pyis installed. Requesting an unsupported extension is logged as an error and silently ignored.Recording and playback stop automatically when the widget is closed or the application is about to quit.
- Parameters:
source (QVideoSource or None) – Video source supplying frames to record.
filename (str or None) – Default file path for saving. If
None, defaults to~/default.mkv.*args – Forwarded to
QFrame.**kwargs – Forwarded to
QFrame.Signals
——-
newFrame(Image) – Emitted for each frame during playback.
recording(bool) – Emitted when recording starts (
True) or stops (False).playing(bool) – Emitted when playback starts (
True) or stops (False).
- newFrame#
Emitted for each frame during playback.
- recording#
Emitted when recording starts (
True) or stops (False).
- playing#
Emitted when playback starts (
True) or stops (False).
- FILENAME = 'default.mkv'#
- Writer: dict[str, type] = {'.avi': <class 'QVideo.dvr.QOpenCVWriter.QOpenCVWriter'>, '.mkv': <class 'QVideo.dvr.QOpenCVWriter.QOpenCVWriter'>, '.mp4': <class 'QVideo.dvr.QOpenCVWriter.QOpenCVWriter'>}#
- Player: dict[str, type] = {'.avi': <class 'QVideo.dvr.QOpenCVReader.QOpenCVSource'>, '.mkv': <class 'QVideo.dvr.QOpenCVReader.QOpenCVSource'>, '.mp4': <class 'QVideo.dvr.QOpenCVReader.QOpenCVSource'>}#
- getFileName(save=False)[source]#
Open a file dialog and update the filename fields.
- Parameters:
save (bool) – If
True, open a save dialog; otherwise open an open dialog.- Return type:
- Returns:
str – Selected filename, or empty string if cancelled.
- record()[source]#
Start recording, or stop if already recording.
Does nothing if
sourceisNone, if playback is active, or if the save filename has an unsupported extension.- Return type:
- play()[source]#
Start playback, or resume if paused.
Does nothing if recording is active, if playback is already running, or if the playback filename has an unsupported extension.
- Return type:
- property source: QVideoSource | None#
The
QVideoSourcebeing recorded.
- property player: QVideoSource | None#
The active playback source, or
Nonewhen not playing.
- filename#
- pyqtProperty(type, fget=None, fset=None, freset=None, fdel=None, doc=None,
designable=True, scriptable=True, stored=True, user=False, constant=False, final=False, notify=None, revision=0) -> property attribute
type is the type of the property. It is either a type object or a string that is the name of a C++ type. freset is a function for resetting an attribute to its default value. designable sets the DESIGNABLE flag (the default is True for writable properties and False otherwise). scriptable sets the SCRIPTABLE flag. stored sets the STORED flag. user sets the USER flag. constant sets the CONSTANT flag. final sets the FINAL flag. notify is the NOTIFY signal. revision is the REVISION. The other parameters are the same as those required by the standard Python property type. Properties defined using pyqtProperty behave as both Python and Qt properties. Decorators can be used to define new properties or to modify existing ones.
- playname#
- pyqtProperty(type, fget=None, fset=None, freset=None, fdel=None, doc=None,
designable=True, scriptable=True, stored=True, user=False, constant=False, final=False, notify=None, revision=0) -> property attribute
type is the type of the property. It is either a type object or a string that is the name of a C++ type. freset is a function for resetting an attribute to its default value. designable sets the DESIGNABLE flag (the default is True for writable properties and False otherwise). scriptable sets the SCRIPTABLE flag. stored sets the STORED flag. user sets the USER flag. constant sets the CONSTANT flag. final sets the FINAL flag. notify is the NOTIFY signal. revision is the REVISION. The other parameters are the same as those required by the standard Python property type. Properties defined using pyqtProperty behave as both Python and Qt properties. Decorators can be used to define new properties or to modify existing ones.
Current frame number displayed in the LCD.
QOpenCVWriter#
OpenCV-backed video file writer supporting AVI, MKV, and MP4.
- class QVideo.dvr.QOpenCVWriter.QOpenCVWriter(*args, codec=None, **kwargs)[source]#
Bases:
QVideoWriterOpenCV-backed video file writer supporting AVI, MKV, and MP4.
Writes frames to a video file using
cv2.VideoWriter. The file is opened lazily on the first frame so that frame dimensions and color mode can be determined automatically.Codecs are selected based on the file extension using
CODEC_MAP. When no codec is specified, the preference-ordered list for the extension is probed and the first one OpenCV accepts is used. Specifying codec explicitly bypasses probing.If the shape of a subsequent frame differs from the first, recording stops immediately and
finishedis emitted.- Parameters:
filename (str) – Path to the output video file.
codec (str or None) – Four-character codec code passed to
cv2.VideoWriter_fourcc. IfNone, codecs are chosen fromCODEC_MAPbased on the file extension.*args – Forwarded to
QVideoWriter.**kwargs – Forwarded to
QVideoWriter.
- CODEC_MAP: dict[str, tuple[str, ...]] = {'.avi': ('FFV1', 'HFYU'), '.mkv': ('FFV1', 'HFYU'), '.mp4': ('avc1', 'mp4v')}#
- open(frame)[source]#
Open the video file using the first available codec.
Called automatically by
write()on the first frame. Frame dimensions and color mode are determined from frame; codecs are probed via_getWriter().- Parameters:
frame (Image) – The first video frame, used to determine dimensions and color mode.
- Return type:
- Returns:
bool –
Trueif a codec was found and the file was opened;Falseotherwise.
QOpenCVReader#
OpenCV video reader and threaded playback source.
- class QVideo.dvr.QOpenCVReader.QOpenCVReader(filename)[source]#
Bases:
QVideoReaderVideo reader for common video file formats (AVI, MKV, MP4, etc.).
Reads frames from a video file using OpenCV’s
VideoCapture. Frames are converted from BGR (OpenCV native) to RGB on read.- Parameters:
filename (str) – Path to the video file to read.
- FRAMENUMBER = 1#
- WIDTH = 3#
- HEIGHT = 4#
- LENGTH = 7#
- FPS = 5#
- read()[source]#
Read the next frame from the video file.
Frames are converted from BGR (OpenCV native) to RGB on read.
Index of the next frame to be returned by
read().
- class QVideo.dvr.QOpenCVReader.QOpenCVSource(reader)[source]#
Bases:
QVideoSourceVideo source for common video file formats (AVI, MKV, MP4, etc.).
- Parameters:
reader (str, Path, or QOpenCVReader) – Path to the video file to read, or an existing
QOpenCVReaderinstance.
QHDF5Writer#
HDF5 video writer with per-frame timestamps.
- class QVideo.dvr.QHDF5Writer.QHDF5Writer(*args, **kwargs)[source]#
Bases:
QVideoWriterVideo writer for HDF5 files.
Writes frames to an HDF5 file as a group of timestamped datasets. Each frame is stored under a key equal to its elapsed time in seconds since recording began. A
Timestampattribute on the file records the absolute start time (UNIX epoch).The file is created on the first frame and closed explicitly by
close(). If the file cannot be created,open()returnsFalseand no data are written.- Parameters:
filename (str) – Path to the output HDF5 file.
*args – Forwarded to
QVideoWriter.**kwargs – Forwarded to
QVideoWriter.
- open(frame)[source]#
Open the HDF5 file for writing.
Called automatically by
write()on the first frame.- Parameters:
frame (Image) – The first video frame (used only to trigger file creation; dimensions are not required in advance for HDF5).
- Return type:
- Returns:
bool –
Trueif the file was opened successfully;Falseif the file could not be created.
QHDF5Reader#
HDF5 video reader and threaded playback source.
- class QVideo.dvr.QHDF5Reader.QHDF5Reader(filename)[source]#
Bases:
QVideoReaderVideo reader for HDF5 files.
Reads frames from an HDF5 file containing an
imagesgroup of timestamped datasets, as written byQHDF5Writer.- Parameters:
filename (str) – Path to the HDF5 file to read.
- property fps: float#
Estimated frame rate derived from the recorded timestamps [fps].
Computed as
(n_frames - 1) / total_duration. Falls back to 30 fps when fewer than two frames are present or the timestamps span zero time.
Index of the next frame to be returned by
read().
- class QVideo.dvr.QHDF5Reader.QHDF5Source(reader)[source]#
Bases:
QVideoSourceVideo source for HDF5 files.
- Parameters:
reader (str, Path, or QHDF5Reader) – Path to the HDF5 file to read, or an existing
QHDF5Readerinstance.