Skip to main content

ViT Captioner

PyPI version License: MIT

A Python package for extracting keyframes from videos and generating captions using the ViT-GPT2 model.

Features

  • Extract keyframes from videos using Katna or uniform sampling
  • Generate captions for images using the ViT-GPT2 model
  • Match keyframes with timestamps in a video
  • Convert videos to SRT subtitle files with captions
  • Visualize keyframes and timeline data
  • Performance optimized with smart resource management
  • Thread-safe image processing and visualization

Installation

pip install vit-captioner

Command Line Usage

Extract keyframes from a video:

vit-captioner extract -V /path/to/video.mp4 -N 10 -v

Generate caption for an image:

vit-captioner caption-image -I /path/to/image.jpg

Convert video to captions:

vit-captioner caption-video -V /path/to/video.mp4 -N 10 -v

The -v flag enables verbose output with progress bars.

Find matching timestamps for keyframes:

vit-captioner find-timestamps -V /path/to/video.mp4 -K /path/to/keyframes_folder -v

Python API Usage

from vit_captioner.keyframes.extractor import KeyFrameExtractor
from vit_captioner.captioning.image import ImageCaptioner
from vit_captioner.captioning.video import VideoToCaption

# Extract keyframes
extractor = KeyFrameExtractor("/path/to/video.mp4")
extractor.extract_key_frames("/path/to/video.mp4", 10)

# Generate caption for an image
captioner = ImageCaptioner()
caption = captioner.predict_caption("/path/to/image.jpg")

# Convert video to captions
# Note: verbose flag enables progress bars
converter = VideoToCaption("/path/to/video.mp4", num_frames=10, verbose=True)
converter.convert()

Performance Optimizations

  • Smart resource management with proper cleanup
  • Single model loading for multiple frames (improved memory usage)
  • Thread-safe image processing with error fallbacks
  • Progress bars for tracking long-running operations
  • Limited number of concurrent workers to prevent memory issues

Requirements

  • Python 3.6+
  • OpenCV
  • PyTorch
  • Transformers
  • Katna
  • Matplotlib
  • tqdm

Source Code

Source code is available on GitHub: https://github.com/lachlanchen/VideoCaptionerWithVit

License

MIT

Metadata

Release files for vit-captioner 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vit-captioner 0.1.2
File Size Uploaded Provenance Actions
vit_captioner-0.1.2.tar.gz 15.7 kB With provenance Details for vit_captioner-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vit-captioner 0.1.2
File Interpreter ABI Platform Actions
vit_captioner-0.1.2-py3-none-any.whl Python 3 none any Details for vit_captioner-0.1.2-py3-none-any.whl

Total release size: 34.3 kB

Release files / vit_captioner-0.1.2.tar.gz

Download URL vit_captioner-0.1.2.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6c34b173457b2cef4e150f1a86e3f6142a35f9a5475654abdb67110c8b014fd5
BLAKE2b-256 checksum
How to use checksums
897bc545567fe8bc8759c9b73435a832d7e84aab9ed75f70d6df542d1ee7c5fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 18, 2025.

Transparency log

Release files / vit_captioner-0.1.2-py3-none-any.whl

Download URL vit_captioner-0.1.2-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c302eeec7ec1ca1989397db57c0cefbb0aad283a6a16f7b6379e55cf247246d
BLAKE2b-256 checksum
How to use checksums
13158bac14a2287fc1bc7b129bc971c9a9bbd8fdfa393296f3d36bad0c3a4a64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 18, 2025.

Transparency log

Security for vit-captioner 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for vit_captioner-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 18, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page