Skip to main content

Video Frame Extractor - Extract frames from videos using FFmpeg

Project description

Video Frame Extractor Tool

A command-line tool and Python library to extract frames from video files using FFmpeg.

PyPI version

Features

  • Extract frames at custom frame rates (e.g., 1 fps, 5 fps, or original)
  • Support for multiple output formats: JPG, PNG, WebP
  • Adjustable image quality settings
  • Extract from specific time ranges
  • Resize/scale output frames
  • Simple CLI and Python API
  • No Python dependencies (uses built-in modules only)

Requirements

  • Python 3.7+
  • FFmpeg installed and available in PATH

Installing FFmpeg

macOS:

brew install ffmpeg

Ubuntu/Debian:

sudo apt update && sudo apt install ffmpeg

Windows: Download from ffmpeg.org and add to PATH.

Installation

pip install video-frame-extractor-tool

Quick Start

Command Line

# Extract 1 frame per second as JPG (default)
video2frames video.mp4 -o frames/

# Extract at 5 fps as PNG
video2frames video.mp4 -o frames/ -f 5 --format png

# Extract frames from 10s to 30s
video2frames video.mp4 -o frames/ --start 10 --end 30

# Show video information
video2frames video.mp4 --info

Python API

from video2frames import extract_frames, get_video_info

# Get video information
info = get_video_info("video.mp4")
print(f"Resolution: {info.width}x{info.height}")
print(f"Duration: {info.duration} seconds")
print(f"FPS: {info.fps}")

# Extract frames
frames = extract_frames(
    "video.mp4",
    output_dir="frames",
    fps=2,
    format="png",
    quality=95
)
print(f"Extracted {len(frames)} frames")

CLI Options

Option Description Default
video Path to input video file (required)
-o, --output Output directory frames
-f, --fps Frames per second to extract 1
--format Output format: jpg, png, webp jpg
-q, --quality Image quality (1-100) 90
--start Start time in seconds None
--end End time in seconds None
--prefix Filename prefix frame
--scale Output resolution (e.g., -1:720) None
--info Show video info and exit False
-v, --verbose Verbose output False

Examples

Extract at Different Frame Rates

# 1 frame per second (good for long videos)
video2frames video.mp4 -o frames/ -f 1

# 5 frames per second
video2frames video.mp4 -o frames/ -f 5

# Original frame rate (e.g., 30 fps)
video2frames video.mp4 -o frames/ -f 30

Different Output Formats

# JPEG (smaller files)
video2frames video.mp4 -o frames/ --format jpg

# PNG (lossless)
video2frames video.mp4 -o frames/ --format png

# WebP (modern, good compression)
video2frames video.mp4 -o frames/ --format webp

Extract Specific Time Range

# Extract from 1:00 to 2:00
video2frames video.mp4 -o frames/ --start 60 --end 120

# First 30 seconds only
video2frames video.mp4 -o frames/ --end 30

Resize Output

# Resize to 720p (keep aspect ratio)
video2frames video.mp4 -o frames/ --scale -1:720

# Resize to specific dimensions
video2frames video.mp4 -o frames/ --scale 1280:720

Batch Processing

# Process multiple videos
for video in *.mp4; do
    video2frames "$video" -o "${video%.mp4}_frames/"
done

Python API Reference

extract_frames()

extract_frames(
    video_path: str,
    output_dir: str = "frames",
    fps: float = 1.0,
    format: str = "jpg",
    quality: int = 90,
    start_time: Optional[float] = None,
    end_time: Optional[float] = None,
    prefix: str = "frame",
    scale: Optional[str] = None,
    overwrite: bool = True,
    verbose: bool = False
) -> List[Path]

get_video_info()

get_video_info(video_path: str) -> Optional[VideoInfo]

Returns a VideoInfo object with:

  • width: Video width in pixels
  • height: Video height in pixels
  • fps: Frame rate
  • duration: Duration in seconds
  • total_frames: Estimated total frames

check_ffmpeg()

check_ffmpeg() -> bool

Returns True if FFmpeg is available.

License

MIT License - see LICENSE file.

Links

  • VideoToJPG.com - Online video frame extractor with sharpness detection
  • FFmpeg - The multimedia framework used by this tool

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

video_frame_extractor_tool-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

video_frame_extractor_tool-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file video_frame_extractor_tool-0.1.0.tar.gz.

File metadata

File hashes

Hashes for video_frame_extractor_tool-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0b76b3b98b1859c5f5e4ef3018d3d0b5508821c7ef44d8a3c354dfcbd334e5a9
MD5 a48eb3e9f867529f3b707d76b5798405
BLAKE2b-256 bcb5369b9a3387f10ecff16210fd2ea18b8d0194289d3a3adedfbc3bc6c8c407

See more details on using hashes here.

File details

Details for the file video_frame_extractor_tool-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for video_frame_extractor_tool-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38ae5ee82c20a99756b8e89884d2995ac26fc8729c42bd68dd59a38da94f03a4
MD5 3a5ece2d93f42fb0188c1e0bb13b7fd0
BLAKE2b-256 7c87ffe19aeb1add476d22d928b6ceddade0f03384d336ceaf329fe8c6e92373

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page