Metadata-Version: 2.4
Name: rewatchx
Version: 0.2.1
Summary: Turn long videos into short captioned clips, locally.
Author: Ashfaaq Hamja Shaik
License-Expression: MIT
Project-URL: Homepage, https://github.com/shaikashfaaqhamja/rewatch
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typer
Requires-Dist: faster-whisper
Requires-Dist: av<19
Dynamic: license-file

# rewatch

You give rewatch a long video, it gives you short clips with captions. Everything runs on your own laptop. No API keys, no uploading your videos anywhere, no paying per clip.

I'm building this from scratch to learn, so it's still early. This is v0.2.0.

## What it can do right now

It finds the good moments in a long video by itself. Every moment becomes its own clip, under a minute, with captions already on it.

```
rewatch auto episode.mp4
```

I tried it on a 2 hr 12 min podcast and got 7 clips. The moments it picked were actually nice, I'd say it's about 80% there.

You can still cut a clip by hand, or put captions on a clip you already have.

## How it picks the moments (for now)

There's no AI chatbot in here. For now it's just rules I wrote, and I kept tweaking them by watching what came out:

1. Check how loud every second is, and how fast people are talking.
2. Slide a 30 second window over the whole video and score each one.
3. Keep the top 10 windows that don't overlap.
4. Move the edges so the clip starts where a sentence starts and ends where one ends. Clips starting in the middle of a word look bad.
5. If someone asked a question right before the moment, start the clip from the question. I added this because it kept cutting off the host's question and only showing the answer lol.
6. Merge clips that overlap, and if one goes over 60 seconds, cut it back to the last full sentence.

These rules are only the starting point.

## What's next

I want to train a model on what people actually rewatch on YouTube, using the "Most Replayed" graph. Then I can check if it does better than these rules, and better than just asking a chatbot.

After that: a vertical crop that follows whoever is talking, and proper Hindi and Telugu captions. The tiny Whisper model I'm using messes up Hinglish a lot right now.

## Before you install

You need Python 3.11 or newer, and FFmpeg.

On a Mac, the normal `brew install ffmpeg` can't draw captions because it doesn't come with a library called libass (took me a while to figure this out). Install `ffmpeg-full` instead:

```
brew install ffmpeg-full
brew unlink ffmpeg
brew link --force ffmpeg-full
```

To check, run `ffmpeg -hide_banner -filters | grep subtitles`. If nothing prints, captions won't work.

## Install

```
pip install rewatchx
```

It's `rewatchx` because someone already took `rewatch` on PyPI. The command is still just `rewatch`.

Or from source:

```
git clone https://github.com/shaikashfaaqhamja/rewatch.git
cd rewatch
python3 -m venv .venv
source .venv/bin/activate
pip install -e .
```

## How to use it

Let it find the moments and make the clips:

```
rewatch auto episode.mp4
```

Clips go into a folder called `clips`. If you want a different folder:

```
rewatch auto episode.mp4 --out-dir my_clips
```

You get 3 files for every moment: `clip_1.mp4` is the plain cut, `clip_1.srt` has the captions, and `clip_1_burned.mp4` is the one with captions on it (the one you'd actually post).

Cut 30 seconds yourself, starting at 1:30:

```
rewatch cut episode.mp4 90 120 clip.mp4
```

Put captions on a clip:

```
rewatch captions clip.mp4 clip_captioned.mp4
```

The first run downloads the Whisper model, so give it a minute. `auto` on a long video takes a few minutes because it has to listen to the whole thing.

## What happens inside

FFmpeg cuts the clip and turns it into H.264 video with AAC audio, because that plays everywhere. faster-whisper listens to the video and gives back every word with the exact time it was said. In `auto`, it listens to the full video only once, and each clip reuses those words with the times shifted so they start from zero. I group the words into lines of up to 5 words, and a line also ends wherever a sentence ends. The lines go into an SRT file and FFmpeg draws them onto the video.

## License

MIT, use it however you want. See [LICENSE](LICENSE).
