Skip to main content

FirstFrame is a simple command-line tool for extracting the first frame from MP4 video files using OpenCV (cv2)

Project description

FirstFrame

Overview

FirstFrame is a lightweight command-line tool that extracts the first frame from MP4 video files using OpenCV (cv2).

It automatically scans the current directory for .mp4 files (case-insensitive), displays an interactive numbered list with file sizes, lets the user select a video, and saves the first frame as an image file (PNG by default; supports JPG, JPEG, BMP, TIFF).

The tool features clear prompts, basic error handling, and a pause at the end — perfect for quick thumbnail generation, cover image creation, or inspecting video starts without loading the entire file.

Features

  • Finds all .mp4 / .MP4 / .Mp4 files in the current folder using glob
  • Shows numbered list with file sizes (in MB) for easy selection
  • Extracts the very first frame reliably with a single cap.read() call
  • Smart default output filename: output.png (if free) or {video_name}_first.png
  • Automatically adds .png extension if user input lacks an image suffix
  • Clean resource handling (cap.release()) — no temporary files
  • User-friendly success/error messages and final confirmation

Prerequisites

  • Python 3.8+ (recommended: 3.10–3.12)
  • opencv-python (installed via pip)
  • Optional: virtual environment (venv or uv)

No C compiler or Cython is required for normal usage — the project is currently pure Python.

Installation

Development / Source Install (Editable)

# 1. Clone or download the repo
git clone <your-repo-url>
cd FirstFrame

# 2. (Recommended) Create & activate virtual environment
python3 -m venv venv
source venv/bin/activate    # Windows: venv\Scripts\activate

# 3. Install dependencies
pip install opencv-python
# If you later add ChronicleLogger or others → add them here

# 4. Install project in editable mode
pip install -e .

Now you can run it with:

python -m FirstFrame

Future PyPI Release (when ready)

pip install firstframe

(You would then publish it via python -m build + twine, and configure console_scripts in pyproject.toml for a firstframe command.)

Usage

Place your MP4 videos in the current directory and run:

python -m FirstFrame

Example session:

Found MP4 videos:

  1. intro.mp4   (12.4 MB)
  2. demo.MP4    (45.8 MB)

Enter video number (1-2): 1

Selected: intro.mp4
Enter output image filename [default: output.png]: 

Extracting first frame from 'intro.mp4'...
Success: First frame saved as 'output.png'

Done! Image saved as: output.png

Press Enter to exit...

Or specify a custom name:

Enter output image filename [default: intro_first.png]: cover.jpg

The tool saves the image and waits for you to press Enter before closing.

For scripting / automation:

from FirstFrame.__main__ import main
main()

Project Structure

Follows modern Python packaging conventions with src/ layout:

FirstFrame/
├── README.md
├── pyproject.toml            # (add when packaging properly)
├── src/
│   └── FirstFrame/
│       ├── __init__.py
│       └── __main__.py       # Main logic + entry point
└── (optional future folders)
    ├── tests/
    └── docs/

Development Notes

  • The core logic lives in src/FirstFrame/__main__.py
  • To add features (batch mode, other formats, progress bar…): edit the main() and get_first_frame() functions
  • Logging: ChronicleLogger is imported but unused — either integrate it or remove the import
  • Tests: Consider adding tests/ folder + pytest later
  • Packaging: When ready, add pyproject.toml with build-system = {requires = ["hatchling"], build-backend = "hatchling.build"} (or setuptools)

Troubleshooting

  • Cannot open video → Check file path, integrity, and codec support in your OpenCV build
  • No MP4 files found → Make sure videos are in the current working directory (pwd)
  • OpenCV not foundpip install opencv-python
  • Permission denied on save → Check write permissions in current folder

License

MIT License
(Add a LICENSE file with the standard MIT text when you publish or share the repo.)

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

firstframe-1.0.6.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

firstframe-1.0.6-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file firstframe-1.0.6.tar.gz.

File metadata

  • Download URL: firstframe-1.0.6.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for firstframe-1.0.6.tar.gz
Algorithm Hash digest
SHA256 3b7b5c465cd5b55f2f9850b41e9f62806a0f999ef2f58ca80374d1eb17d550c3
MD5 9ff2c5b477c87e765ded041ccea9f2dc
BLAKE2b-256 1424ed648584154b5eebfbc4fa0ecb29033e21d64aa84c671d0c5fdb613f9903

See more details on using hashes here.

File details

Details for the file firstframe-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: firstframe-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for firstframe-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ced525b0cfb74870c580400fc7fc50356626e2a4306b0d5e615ff3889ffe4735
MD5 28cc8f0fbfa152159a0a959ad0b8dd6e
BLAKE2b-256 b9de52eb279c47b3adf3ba4a67cc7d40a28513b2cea31e444b79dddf1335f57b

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