FFmpeg Video Processor

FFmpeg-based video processing implementation.

This module provides video processing capabilities using FFmpeg as the backend.

class langchain_memvid.video.ffmpeg.FFmpegProcessor(fps, resolution, codec, ffmpeg_options=None)[source]

Bases: object

FFmpeg-based video processor for MemVid.

  • Encodes and decodes video frames using FFmpeg.

  • Used for efficient frame-level operations and video manipulation.

Parameters:
__init__(fps, resolution, codec, ffmpeg_options=None)[source]

Initialize FFmpeg processor.

Parameters:
  • fps (int) – Frames per second

  • resolution (tuple[int, int]) – Video resolution (width, height)

  • codec (str) – Video codec to use

  • ffmpeg_options (Optional[Dict[str, Any]]) – Additional FFmpeg options

_get_ffmpeg_command(input_path=None)[source]

Get FFmpeg command with configured options.

Parameters:

input_path (Optional[Path]) – Optional input file path

Return type:

List[str]

Returns:

List of command arguments

decode_video(video_path)[source]

Decode frames from a video file using FFmpeg.

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 using FFmpeg.

Parameters:
  • frames (List[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

get_video_info(video_path)[source]

Get information about a video file using FFmpeg.

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)[source]

Remove specific frames from a video file using FFmpeg.

This method uses FFmpeg’s select filter to efficiently remove frames without re-encoding 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 (Path) – Path to the output video file

Return type:

Path

Returns:

Path to the new video file without the specified frames

Raises:

VideoProcessingError – If frame removal fails