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:
decoded_info: List[str]

Alias for field number 1

points: List[List[int]]

Alias for field number 2

retval: bool

Alias for field number 0

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:
__init__(video_config, qrcode_config)[source]

Initialize the video processor.

Parameters:
  • video_config (VideoConfig) – Configuration for video processing

  • qrcode_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

_prepare_frames_batch(frames)[source]

Prepare a batch of frames for video encoding.

Parameters:

frames (Iterable[Image]) – List of PIL Images to prepare

Return type:

Generator[ndarray, None, None]

Returns:

List of OpenCV-compatible numpy arrays

_remove_frames_opencv(video_path, frame_numbers, output_path)[source]

Remove frames using OpenCV (fallback method).

Parameters:
  • video_path (Path) – Path to the input video file

  • frame_numbers (List[int]) – List of frame numbers to remove

  • output_path (Path) – Path to the output video file

Return type:

Path

Returns:

Path to the new video file

Raises:

VideoProcessingError – If frame removal fails

_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:

Path

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:

Generator[Image, None, None]

encode_video(frames, output_path)[source]

Encode frames into a video file.

Parameters:
  • frames (Iterable[Image]) – List of PIL Images to encode

  • output_path (Path) – Path to save the video file

Raises:

VideoProcessingError – If video encoding fails

Return type:

None

extract_qr_codes(frame)[source]

Extract QR codes from a frame.

Parameters:

frame (Image) – PIL Image to extract QR codes from

Return type:

List[str]

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:
  • video_path (Path) – Path to the input video file

  • frame_numbers (List[int]) – List of frame numbers to remove (0-indexed)

  • output_path (Optional[Path]) – Optional output path. If None, creates a temporary file

Return type:

Path

Returns:

Path to the new video file without the specified frames

Raises:

VideoProcessingError – If frame removal fails