shortcap
Add automatic captions to YouTube & TikTok Shorts (and other videos) using Whisper and MoviePy.
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 videoposition = "center": Centers the text horizontally and places it at the center of the videoposition = "bottom": Centers the text horizontally and places it at the bottom of the videoposition = 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.
Metadata
Release files for shortcap 1.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| shortcap-1.0.8.tar.gz | 39.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| shortcap-1.0.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 78.1 kB
Release files / shortcap-1.0.8.tar.gz
| Download URL | shortcap-1.0.8.tar.gz |
|---|---|
| Size | 39.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26752aaec645850b4b1af0f95ae3208b0e36fb3fcfcc4cb773225946f914521d
|
|
BLAKE2b-256 checksum How to use checksums |
0f0b7eddc38bf42aad04c56a4837fb932f036fbecf8b631556039fecfcc83b20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.0
|
Release files / shortcap-1.0.8-py3-none-any.whl
| Download URL | shortcap-1.0.8-py3-none-any.whl |
|---|---|
| Size | 38.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
748e9fb778b5fb32ea96af3c57c936b091aaaddec6b0104ea4e6ef79eaa37e29
|
|
BLAKE2b-256 checksum How to use checksums |
34547ef4e7864800d52a5e2a771a7f67c2c0fd4212e76446540e635181bfc24a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.0
|