Skip to main content

A Python tool to edit videos and automatically add CSS-styled subtitles to videos.

Project description

pycaps

Status PyPI License Python Version Hugging Face Spaces

pycaps is a Python tool for adding CSS styled subtitles to videos. It's designed as both a programmable library and a command-line interface (CLI), making it perfect for automating the creation of dynamic content for platforms like TikTok, YouTube Shorts, and Instagram Reels.

Note: This is a community fork published on PyPI as pycaps-ai. The original project is francozanardi/pycaps.

demo-1 demo-2

See more examples on pycaps.com

Try It Online (no installation needed!)

You have two options to test pycaps directly in your browser (hosted by the original project). Choose the one that best fits your needs.

1. Interactive Web Demo (on Hugging Face)

Ideal for a quick preview, testing built-in templates, and editing captions with a user-friendly interface.

Hugging Face Spaces

Keep in mind:

  • This demo runs on a shared, CPU-only environment, so it's best for short videos (< 60 seconds).
  • For a private, faster experience, you can duplicate the Space for free.

2. Full-Power Notebook (on Google Colab)

The best choice for processing longer videos with maximum transcription quality, using a free GPU provided by Google.

Open In Colab

Keep in mind:

  • The interface is a step-by-step code notebook, not a graphical UI.
  • You will be guided to enable the GPU for the best performance.

Key Features

  • Template System: Get started quickly with predefined templates. Create and share your own templates, packaging styles, animations, and configurations.
  • CSS Styling: Style subtitles using standard CSS. Target specific states like .word-being-narrated for dynamic effects, cleanly separating style from logic.
  • Word Tagging: Tag words or phrases using regular expressions, word lists, or AI. These tags act as powerful selectors for applying custom CSS, effects, or animations.
  • Advanced Animations & Effects: Bring words to life with a library of built-in animations (fades, pops, slides) and effects (typewriting, emoji insertion, sound effects).
  • Whisper-based Transcription: Automatically generate accurate, word-level timestamps for your videos using OpenAI's Whisper.
  • Dual Interface: Use it as a simple CLI for quick renders or as a comprehensive Python library for programmatic video creation.
  • Offline-First: The core transcription, styling, and rendering engine runs entirely on your local machine. An internet connection is only needed for optional AI-powered features that require contextual understanding of your script.

Prerequisites

Before installing, please ensure your environment meets the following requirements:

  • Python Version: pycaps was tested on Python 3.10, 3.11, and 3.12. Other versions may present issues.

  • FFmpeg: You need to have FFmpeg installed on your system and accessible from your command line's PATH. This is essential for all audio and video processing tasks.

    • You can download it from ffmpeg.org and follow a guide to add it to your system's PATH.

Installation

  1. Install FFmpeg: Ensure you have completed the prerequisite step above.

  2. Install from PyPI:

    Full installation (recommended):

    pip install "pycaps-ai[all]"
    

    Custom installation with specific features:

    # Whisper + Playwright + transcription editor (default setup)
    pip install "pycaps-ai[base]"
    
    # Lighter rendering: Google Speech + html2pic (no browser)
    pip install "pycaps-ai[fast]"
    

    Install from GitHub (latest dev):

    pip install "git+https://github.com/AleefBilal/pycaps.git#egg=pycaps-ai[all]"
    
  3. Install Browser Dependencies for Rendering: pycaps currently has two different options to render the subtitle images:

    • CssSubtitleRenderer, which is the original and default one. It uses Playwright to render CSS styles. So, you need to install its browser dependency to use it:
      playwright install chromium
      
    • PictexSubtitleRenderer, which is a light-weight option. It doesn't use a browser, but it only support a subset of CSS, and it may present some visual differences in the result (specially in the shadows, you should modify the CSS from the templates to get the same results). To use it, you must call with_custom_subtitle_renderer(PictexSubtitleRenderer()) when CapsPipelineBuilder() is created.

⚠️ Note: The first time you use pycaps, it will also download a Whisper AI model for transcription. This may take a few minutes and only happens once.

Quick Start

There are two primary ways to use pycaps: via the command line with a template or programmatically in a Python script.

1. Using the Command-Line (CLI)

The fastest way to get started is to use a built-in template.

pycaps render --input my_video.mp4 --template minimalist

This command will:

  1. Load the minimalist template.
  2. Transcribe the audio from my_video.mp4.
  3. Apply the template's styles and animations.
  4. Save the result in a new file.

If you already have a transcript from another tool, you can skip built-in transcription:

pycaps render --input my_video.mp4 --template minimalist --transcript transcript.json

Supported transcript formats: whisper_json, pycaps_json, srt, vtt (--transcript-format is optional and defaults to auto).

2. Using the Python Library

For full control, use the CapsPipelineBuilder in your Python code.

from pycaps import CapsPipelineBuilder

# The pipeline contains multiples stages to render the final video
pipeline = (
    CapsPipelineBuilder()
    .with_input_video("input.mp4")
    .add_css("css_file.css")
    .build()
)
pipeline.run() # When this is executed, it starts to render the video

You can also preload the builder using a Template.

from pycaps import *

# Load a template and configure it
builder = TemplateLoader("default").with_input_video("my_video.mp4").load(False)

# Programmatically add an animation
builder.add_animation(
    animation=FadeIn(),
    when=EventType.ON_NARRATION_STARTS,
    what=ElementType.SEGMENT
)

# Build and run the pipeline
pipeline = builder.build()
pipeline.run()

What's Next?

Contributing

This project is in active development. Contributions, bug reports, and feature requests are welcome! Please open an issue or pull request on our GitHub repository.

License

pycaps is licensed under the MIT License. Originally created by Franco Zanardi.

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

pycaps_ai-0.2.1.tar.gz (599.4 kB view details)

Uploaded Source

Built Distribution

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

pycaps_ai-0.2.1-py3-none-any.whl (635.7 kB view details)

Uploaded Python 3

File details

Details for the file pycaps_ai-0.2.1.tar.gz.

File metadata

  • Download URL: pycaps_ai-0.2.1.tar.gz
  • Upload date:
  • Size: 599.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for pycaps_ai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ca3111de1d29e8bd70bb6725d9ed43c3e7f5af5cac22d84d42c72bf8030b314a
MD5 ab858923d3a9572857fb1ba330078af4
BLAKE2b-256 b6ef6ead457fd1db20497c1c543840b9c1bc42ad5ceb35190657594cc0b80c93

See more details on using hashes here.

File details

Details for the file pycaps_ai-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pycaps_ai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 635.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for pycaps_ai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9fcb1359ac8e09e04a65d17e019f0ba3083ec28e969089eb93c72e175b191cea
MD5 d25dbfa35f1ed4a5b2644d64bf4c29ae
BLAKE2b-256 18102eb10af31a350d217a26f8d9480b5c3f54a0c670b42f945333da94e113c9

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