Skip to main content

Add Automatic Captions to Short Videos with AI

Project description

shortcap

Add automatic captions to YouTube & TikTok Shorts (and other videos) using Whisper and MoviePy.

Demo

Demo

Quick Start

Install shortcap:

pip install shortcap

Set required environment variables for OpenAI API:

export OPENAI_BASE_URL="your_openai_base_url"
export OPENAI_API_KEY="your_openai_api_key"

Use the command-line interface:

shortcap <video_file> <output_file>

Features

  • Automatic speech recognition using OpenAI's Whisper
  • Customizable caption styling
  • Support for local Whisper model or OpenAI API
  • Command-line interface and programmatic usage

Example

shortcap input.mp4 output.mp4 --font-size 80 --font-color white --stroke-width 2 --stroke-color black --highlight-current-word --word-highlight-color yellow --line-count 2 --verbose

Programmatic Usage

import shortcap
shortcap.add_captions(
    video_file="my_short.mp4",
    output_file="my_short_with_captions.mp4",
)

Custom Configuration

You can customize various aspects of the captions:

import shortcap
shortcap.add_captions(
    video_file="my_short.mp4",
    output_file="my_short_with_captions.mp4",
    font = "/path/to/your/font.ttf",
    font_size = 130,
    font_color = "yellow",
    stroke_width = 3,
    stroke_color = "black",
    shadow_strength = 1.0,
    shadow_blur = 0.1,
    highlight_current_word = True,
    word_highlight_color = "red",
    line_count=1,
    padding = 50,
    position = "center"
)

The position parameter allows you to control where the captions appear on the video.

Vertical position: "top", "center", "bottom", or an integer value

For example:

  • position = "top": Centers the text horizontally and places it at the top of the video
  • position = "center": Centers the text horizontally and places it at the center of the video
  • position = "bottom": Centers the text horizontally and places it at the bottom of the video
  • position = 100: Centers the text horizontally and places it 100 pixels from the top of the video

The default value is "center", which centers the text both horizontally and vertically.

Using Whisper Locally

By default, OpenAI Whisper is used locally if the openai-whisper package is installed. Otherwise, the OpenAI Whisper API is used. To force the use of the API:

shortcap.add_captions(
video_file="my_short.mp4",
output_file="my_short_with_captions.mp4",
use_local_whisper=False,
)

Install shortcap with local Whisper support:

pip install shortcap[local_whisper]

Command-line Options

For a full list of command-line options, run:

shortcap --help

Changelog

For a detailed list of changes and version updates, please refer to the CHANGELOG.md file.

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any problems or have any questions, please open an issue on the GitHub repository.


For more detailed information on usage and configuration, please refer to the documentation.

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

shortcap-1.0.8.tar.gz (39.2 kB view details)

Uploaded Source

Built Distribution

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

shortcap-1.0.8-py3-none-any.whl (38.9 kB view details)

Uploaded Python 3

File details

Details for the file shortcap-1.0.8.tar.gz.

File metadata

  • Download URL: shortcap-1.0.8.tar.gz
  • Upload date:
  • Size: 39.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for shortcap-1.0.8.tar.gz
Algorithm Hash digest
SHA256 26752aaec645850b4b1af0f95ae3208b0e36fb3fcfcc4cb773225946f914521d
MD5 b6c4e02fdc378a7fcde1738bc2905ca3
BLAKE2b-256 0f0b7eddc38bf42aad04c56a4837fb932f036fbecf8b631556039fecfcc83b20

See more details on using hashes here.

File details

Details for the file shortcap-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: shortcap-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 38.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for shortcap-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 748e9fb778b5fb32ea96af3c57c936b091aaaddec6b0104ea4e6ef79eaa37e29
MD5 2fb5c1393cb056b27f1a325d808612b5
BLAKE2b-256 34547ef4e7864800d52a5e2a771a7f67c2c0fd4212e76446540e635181bfc24a

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