Default Video Processor
Default video processing implementation using OpenCV.
This module provides video processing capabilities using OpenCV as the backend.
- class langchain_memvid.video.default.QRCodeDetection(retval, decoded_info, points, straight_qrcode)[source]
Bases:
NamedTuple
- Parameters:
-
straight_qrcode:
ndarray
Alias for field number 3
- class langchain_memvid.video.default.VideoProcessor(video_config, qrcode_config)[source]
Bases:
object
Handles video processing operations for MemVid.
Encodes and decodes QR codes in video frames.
Supports both OpenCV and FFmpeg backends for video operations.
- Parameters:
video_config (VideoConfig)
qrcode_config (QRCodeConfig)
- __init__(video_config, qrcode_config)[source]
Initialize the video processor.
- Parameters:
video_config (
VideoConfig
) – Configuration for video processingqrcode_config (
QRCodeConfig
) – Configuration for QR code generation
- _prepare_frame(frame)[source]
Prepare a frame for video encoding.
- Parameters:
frame (
Image
) – PIL Image to prepare- Return type:
ndarray
- Returns:
OpenCV-compatible numpy array
- _remove_frames_opencv(video_path, frame_numbers, output_path)[source]
Remove frames using OpenCV (fallback method).
- _validate_output_path(output_path)[source]
Validate and adjust output path based on codec file type.
- Parameters:
output_path (
Path
) – Original output path- Return type:
- Returns:
Adjusted output path with correct extension
- Raises:
VideoProcessingError – If the codec doesn’t support the requested extension
- create_qr_code(data)[source]
Create a QR code image from data.
- Parameters:
data (
str
) – Data to encode in QR code- Return type:
BaseImage
- Returns:
QR code image in binary mode
- Raises:
QRCodeError – If QR code generation fails
- decode_video(video_path)[source]
Decode frames from a video file.
- Parameters:
video_path (
Path
) – Path to the video file- Yields:
PIL Images from the video frames
- Raises:
VideoProcessingError – If video decoding fails
- Return type:
- encode_video(frames, output_path)[source]
Encode frames into a video file.
- Parameters:
- Raises:
VideoProcessingError – If video encoding fails
- Return type:
- extract_qr_codes(frame)[source]
Extract QR codes from a frame.
- Parameters:
frame (
Image
) – PIL Image to extract QR codes from- Return type:
- Returns:
List of decoded QR code data
- Raises:
QRCodeError – If QR code extraction fails
- get_video_info(video_path)[source]
Get information about a video file.
- Parameters:
video_path (
Path
) – Path to the video file- Returns:
Information about the video file
- Return type:
VideoInfo
- Raises:
VideoProcessingError – If getting video info fails
- remove_frames_from_video(video_path, frame_numbers, output_path=None)[source]
Remove specific frames from a video file.
This method creates a new video file without the specified frames. It’s more efficient than rebuilding the entire video.
- Parameters:
- Return type:
- Returns:
Path to the new video file without the specified frames
- Raises:
VideoProcessingError – If frame removal fails