rewatchx 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rewatchx-0.2.0/PKG-INFO +121 -0
- rewatchx-0.2.0/README.md +106 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/pyproject.toml +1 -1
- rewatchx-0.2.0/src/rewatch/auto.py +25 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/src/rewatch/cli.py +12 -1
- rewatchx-0.2.0/src/rewatch/features.py +62 -0
- rewatchx-0.2.0/src/rewatch/highlights.py +66 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/src/rewatch/transcribe.py +4 -1
- rewatchx-0.2.0/src/rewatchx.egg-info/PKG-INFO +121 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/src/rewatchx.egg-info/SOURCES.txt +3 -0
- rewatchx-0.1.0/PKG-INFO +0 -78
- rewatchx-0.1.0/README.md +0 -63
- rewatchx-0.1.0/src/rewatchx.egg-info/PKG-INFO +0 -78
- {rewatchx-0.1.0 → rewatchx-0.2.0}/LICENSE +0 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/setup.cfg +0 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/src/rewatch/__init__.py +0 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/src/rewatch/burn.py +0 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/src/rewatch/captions.py +0 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/src/rewatch/cut.py +0 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/src/rewatchx.egg-info/dependency_links.txt +0 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/src/rewatchx.egg-info/entry_points.txt +0 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/src/rewatchx.egg-info/requires.txt +0 -0
- {rewatchx-0.1.0 → rewatchx-0.2.0}/src/rewatchx.egg-info/top_level.txt +0 -0
rewatchx-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rewatchx
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Turn long videos into short captioned clips, locally.
|
|
5
|
+
Author: Ashfaaq Hamja Shaik
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/shaikashfaaqhamja/rewatch
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: typer
|
|
12
|
+
Requires-Dist: faster-whisper
|
|
13
|
+
Requires-Dist: av<19
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# rewatch
|
|
17
|
+
|
|
18
|
+
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.
|
|
19
|
+
|
|
20
|
+
I'm building this from scratch to learn, so it's still early. This is v0.2.0.
|
|
21
|
+
|
|
22
|
+
## What it can do right now
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
rewatch auto episode.mp4
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
You can still cut a clip by hand, or put captions on a clip you already have.
|
|
33
|
+
|
|
34
|
+
## How it picks the moments (for now)
|
|
35
|
+
|
|
36
|
+
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:
|
|
37
|
+
|
|
38
|
+
1. Check how loud every second is, and how fast people are talking.
|
|
39
|
+
2. Slide a 30 second window over the whole video and score each one.
|
|
40
|
+
3. Keep the top 10 windows that don't overlap.
|
|
41
|
+
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.
|
|
42
|
+
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.
|
|
43
|
+
6. Merge clips that overlap, and if one goes over 60 seconds, cut it back to the last full sentence.
|
|
44
|
+
|
|
45
|
+
These rules are only the starting point.
|
|
46
|
+
|
|
47
|
+
## What's next
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
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.
|
|
52
|
+
|
|
53
|
+
## Before you install
|
|
54
|
+
|
|
55
|
+
You need Python 3.11 or newer, and FFmpeg.
|
|
56
|
+
|
|
57
|
+
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:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
brew install ffmpeg-full
|
|
61
|
+
brew unlink ffmpeg
|
|
62
|
+
brew link --force ffmpeg-full
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
To check, run `ffmpeg -hide_banner -filters | grep subtitles`. If nothing prints, captions won't work.
|
|
66
|
+
|
|
67
|
+
## Install
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
pip install rewatchx
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
It's `rewatchx` because someone already took `rewatch` on PyPI. The command is still just `rewatch`.
|
|
74
|
+
|
|
75
|
+
Or from source:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
git clone https://github.com/shaikashfaaqhamja/rewatch.git
|
|
79
|
+
cd rewatch
|
|
80
|
+
python3 -m venv .venv
|
|
81
|
+
source .venv/bin/activate
|
|
82
|
+
pip install -e .
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## How to use it
|
|
86
|
+
|
|
87
|
+
Let it find the moments and make the clips:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
rewatch auto episode.mp4
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Clips go into a folder called `clips`. If you want a different folder:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
rewatch auto episode.mp4 --out-dir my_clips
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
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).
|
|
100
|
+
|
|
101
|
+
Cut 30 seconds yourself, starting at 1:30:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
rewatch cut episode.mp4 90 120 clip.mp4
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Put captions on a clip:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
rewatch captions clip.mp4 clip_captioned.mp4
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
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.
|
|
114
|
+
|
|
115
|
+
## What happens inside
|
|
116
|
+
|
|
117
|
+
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.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
MIT, use it however you want. See [LICENSE](LICENSE).
|
rewatchx-0.2.0/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# rewatch
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
I'm building this from scratch to learn, so it's still early. This is v0.2.0.
|
|
6
|
+
|
|
7
|
+
## What it can do right now
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
rewatch auto episode.mp4
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
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.
|
|
16
|
+
|
|
17
|
+
You can still cut a clip by hand, or put captions on a clip you already have.
|
|
18
|
+
|
|
19
|
+
## How it picks the moments (for now)
|
|
20
|
+
|
|
21
|
+
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:
|
|
22
|
+
|
|
23
|
+
1. Check how loud every second is, and how fast people are talking.
|
|
24
|
+
2. Slide a 30 second window over the whole video and score each one.
|
|
25
|
+
3. Keep the top 10 windows that don't overlap.
|
|
26
|
+
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.
|
|
27
|
+
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.
|
|
28
|
+
6. Merge clips that overlap, and if one goes over 60 seconds, cut it back to the last full sentence.
|
|
29
|
+
|
|
30
|
+
These rules are only the starting point.
|
|
31
|
+
|
|
32
|
+
## What's next
|
|
33
|
+
|
|
34
|
+
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.
|
|
35
|
+
|
|
36
|
+
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.
|
|
37
|
+
|
|
38
|
+
## Before you install
|
|
39
|
+
|
|
40
|
+
You need Python 3.11 or newer, and FFmpeg.
|
|
41
|
+
|
|
42
|
+
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:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
brew install ffmpeg-full
|
|
46
|
+
brew unlink ffmpeg
|
|
47
|
+
brew link --force ffmpeg-full
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
To check, run `ffmpeg -hide_banner -filters | grep subtitles`. If nothing prints, captions won't work.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
pip install rewatchx
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
It's `rewatchx` because someone already took `rewatch` on PyPI. The command is still just `rewatch`.
|
|
59
|
+
|
|
60
|
+
Or from source:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
git clone https://github.com/shaikashfaaqhamja/rewatch.git
|
|
64
|
+
cd rewatch
|
|
65
|
+
python3 -m venv .venv
|
|
66
|
+
source .venv/bin/activate
|
|
67
|
+
pip install -e .
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## How to use it
|
|
71
|
+
|
|
72
|
+
Let it find the moments and make the clips:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
rewatch auto episode.mp4
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Clips go into a folder called `clips`. If you want a different folder:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
rewatch auto episode.mp4 --out-dir my_clips
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
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).
|
|
85
|
+
|
|
86
|
+
Cut 30 seconds yourself, starting at 1:30:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
rewatch cut episode.mp4 90 120 clip.mp4
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Put captions on a clip:
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
rewatch captions clip.mp4 clip_captioned.mp4
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
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.
|
|
99
|
+
|
|
100
|
+
## What happens inside
|
|
101
|
+
|
|
102
|
+
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.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT, use it however you want. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from rewatch.cut import cut
|
|
2
|
+
from rewatch.transcribe import Word
|
|
3
|
+
from rewatch.captions import group_words, write_srt
|
|
4
|
+
from rewatch.burn import burn
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
def make_clips(path, clips, words, out_dir):
|
|
8
|
+
Path(out_dir).mkdir(exist_ok=True)
|
|
9
|
+
for i, (start, end) in enumerate(clips, start=1):
|
|
10
|
+
print(i, start, end)
|
|
11
|
+
cut(path, start, end, f"{out_dir}/clip_{i}.mp4")
|
|
12
|
+
clip_words = []
|
|
13
|
+
for word in words:
|
|
14
|
+
if word.start >= end:
|
|
15
|
+
break
|
|
16
|
+
if word.end <= start:
|
|
17
|
+
continue
|
|
18
|
+
clip_words.append(Word(
|
|
19
|
+
text=word.text,
|
|
20
|
+
start=max(word.start, start) - start,
|
|
21
|
+
end=min(word.end, end) - start
|
|
22
|
+
))
|
|
23
|
+
grouped = group_words(clip_words)
|
|
24
|
+
write_srt(grouped, f"{out_dir}/clip_{i}.srt")
|
|
25
|
+
burn(f"{out_dir}/clip_{i}.mp4", f"{out_dir}/clip_{i}.srt", f"{out_dir}/clip_{i}_burned.mp4")
|
|
@@ -2,6 +2,8 @@ import typer
|
|
|
2
2
|
from rewatch.transcribe import transcribe
|
|
3
3
|
from rewatch.captions import group_words, write_srt
|
|
4
4
|
from rewatch.burn import burn
|
|
5
|
+
from rewatch.features import find_clips
|
|
6
|
+
from rewatch.auto import make_clips
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
from rewatch.cut import cut as cut_video
|
|
@@ -9,21 +11,30 @@ app = typer.Typer()
|
|
|
9
11
|
|
|
10
12
|
@app.callback()
|
|
11
13
|
def main():
|
|
12
|
-
"""
|
|
14
|
+
"""Turn long videos into short captioned clips, all on your own laptop."""
|
|
13
15
|
|
|
14
16
|
@app.command()
|
|
15
17
|
def cut(input_path: str, start: float, end: float, output_path: str):
|
|
18
|
+
"""Cut a part of a video into a clip that plays everywhere."""
|
|
16
19
|
cut_video(input_path, start, end, output_path)
|
|
17
20
|
typer.echo(f"Saved clip to {output_path}")
|
|
18
21
|
|
|
19
22
|
@app.command()
|
|
20
23
|
def captions(input_path: str, output_path: str):
|
|
24
|
+
"""Listen to a clip and put captions on it."""
|
|
21
25
|
words = transcribe(input_path)
|
|
22
26
|
lines = group_words(words)
|
|
23
27
|
write_srt(lines, "captions.srt")
|
|
24
28
|
burn(input_path, "captions.srt", output_path)
|
|
25
29
|
typer.echo(f"Saved captions to {output_path}")
|
|
26
30
|
|
|
31
|
+
@app.command()
|
|
32
|
+
def auto(input_path: str, out_dir: str = "clips"):
|
|
33
|
+
"""Find the good moments in a long video and turn them into captioned clips."""
|
|
34
|
+
clips, words = find_clips(input_path)
|
|
35
|
+
make_clips(input_path, clips, words, out_dir)
|
|
36
|
+
typer.echo(f"Saved clips {len(clips)} to {out_dir}")
|
|
37
|
+
|
|
27
38
|
|
|
28
39
|
|
|
29
40
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from faster_whisper.audio import decode_audio
|
|
2
|
+
import numpy as np
|
|
3
|
+
from rewatch.transcribe import transcribe
|
|
4
|
+
from rewatch.highlights import pick_top
|
|
5
|
+
from rewatch.highlights import snap_to_sentences
|
|
6
|
+
from rewatch.highlights import find_question_start
|
|
7
|
+
from rewatch.highlights import merge_intervals
|
|
8
|
+
from rewatch.highlights import cap_length
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
SAMPLE_RATE = 16000
|
|
12
|
+
|
|
13
|
+
def loudness_per_second(path):
|
|
14
|
+
audio = decode_audio(path, sampling_rate=SAMPLE_RATE)
|
|
15
|
+
seconds = len(audio) // SAMPLE_RATE
|
|
16
|
+
audio = audio[:seconds * SAMPLE_RATE]
|
|
17
|
+
grid = audio.reshape(seconds, SAMPLE_RATE)
|
|
18
|
+
return np.sqrt(np.mean(grid**2, axis=1))
|
|
19
|
+
|
|
20
|
+
def words_per_second(words, seconds):
|
|
21
|
+
counts = [0] * seconds
|
|
22
|
+
for word in words:
|
|
23
|
+
second = int(word.start)
|
|
24
|
+
if second < seconds:
|
|
25
|
+
counts[second] += 1
|
|
26
|
+
return counts
|
|
27
|
+
|
|
28
|
+
def scale(values):
|
|
29
|
+
values = np.array(values, dtype=float)
|
|
30
|
+
min_val = np.min(values)
|
|
31
|
+
max_val = np.max(values)
|
|
32
|
+
if max_val - min_val == 0:
|
|
33
|
+
return np.zeros_like(values)
|
|
34
|
+
return (values - min_val) / (max_val - min_val)
|
|
35
|
+
|
|
36
|
+
def window_scores(scores, size):
|
|
37
|
+
total = sum(scores[:size])
|
|
38
|
+
result = [total]
|
|
39
|
+
for i in range(size, len(scores)):
|
|
40
|
+
total += scores[i]
|
|
41
|
+
total -= scores[i - size]
|
|
42
|
+
result.append(total)
|
|
43
|
+
return result
|
|
44
|
+
|
|
45
|
+
def find_clips(path):
|
|
46
|
+
loud = loudness_per_second(path)
|
|
47
|
+
words = transcribe(path)
|
|
48
|
+
speed = words_per_second(words, len(loud))
|
|
49
|
+
score = scale(loud) + scale(speed)
|
|
50
|
+
windows = window_scores(score, 30)
|
|
51
|
+
|
|
52
|
+
clips = []
|
|
53
|
+
for start, end in pick_top(windows, 30):
|
|
54
|
+
s, e = snap_to_sentences(start, end, words)
|
|
55
|
+
s = find_question_start(s, words)
|
|
56
|
+
clips.append([s, e])
|
|
57
|
+
|
|
58
|
+
clips = merge_intervals(clips)
|
|
59
|
+
clips = [list(cap_length(s, e, words)) for s, e in clips]
|
|
60
|
+
return clips, words
|
|
61
|
+
|
|
62
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
import heapq
|
|
3
|
+
|
|
4
|
+
def merge_intervals(intervals):
|
|
5
|
+
intervals = sorted(intervals)
|
|
6
|
+
merged = [intervals[0][:]]
|
|
7
|
+
for start, end in intervals[1:]:
|
|
8
|
+
last_end = merged[-1][1]
|
|
9
|
+
if start <= last_end:
|
|
10
|
+
merged[-1][1] = max(last_end, end)
|
|
11
|
+
else:
|
|
12
|
+
merged.append([start, end])
|
|
13
|
+
return merged
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# def find_highlights(windows, size, keep=0.2):
|
|
17
|
+
# cutoff = np.quantile(windows, 1 - keep)
|
|
18
|
+
# hot = [[i, i + size] for i, s in enumerate(windows) if s >= cutoff]
|
|
19
|
+
# return merge_intervals(hot)
|
|
20
|
+
|
|
21
|
+
def pick_top(windows, size, k=10):
|
|
22
|
+
heap = [(-score, start) for start, score in enumerate(windows)]
|
|
23
|
+
heapq.heapify(heap)
|
|
24
|
+
picked = []
|
|
25
|
+
while heap and len(picked) < k:
|
|
26
|
+
neg_score, start = heapq.heappop(heap)
|
|
27
|
+
if all(abs(start - p_start) >= size for p_start in picked):
|
|
28
|
+
picked.append(start)
|
|
29
|
+
return sorted([[s, s + size] for s in picked])
|
|
30
|
+
|
|
31
|
+
def snap_to_sentences(start, end, words, max_shift=15):
|
|
32
|
+
ends = (".", "?", "!")
|
|
33
|
+
sentence_starts = [words[0].start] + [
|
|
34
|
+
words[i].start for i in range(1, len(words))
|
|
35
|
+
if words[i - 1].text.endswith(ends)
|
|
36
|
+
]
|
|
37
|
+
sentence_ends = [w.end for w in words if w.text.endswith(ends)]
|
|
38
|
+
new_start = max([s for s in sentence_starts if start - max_shift <= s <= start], default=start)
|
|
39
|
+
new_end = min([e for e in sentence_ends if end <= e <= end + max_shift], default=end)
|
|
40
|
+
return new_start, new_end
|
|
41
|
+
|
|
42
|
+
def find_question_start(start, words, max_back=30):
|
|
43
|
+
ends = (".", "?", "!")
|
|
44
|
+
for i in range(len(words) - 1, -1, -1):
|
|
45
|
+
w = words[i]
|
|
46
|
+
if w.end > start:
|
|
47
|
+
continue
|
|
48
|
+
if start - w.end > max_back:
|
|
49
|
+
break
|
|
50
|
+
if w.text.endswith("?"):
|
|
51
|
+
j = i
|
|
52
|
+
while j > 0 and not words[j - 1].text.endswith(ends):
|
|
53
|
+
j -= 1
|
|
54
|
+
return words[j].start
|
|
55
|
+
return start
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def cap_length(start, end, words, max_length=60):
|
|
59
|
+
if end - start <= max_length:
|
|
60
|
+
return start, end
|
|
61
|
+
limit = start + max_length
|
|
62
|
+
ends = [
|
|
63
|
+
w.end for w in words
|
|
64
|
+
if w.text.endswith((".", "?", "!")) and start < w.end <= limit
|
|
65
|
+
]
|
|
66
|
+
return start, max(ends, default=limit)
|
|
@@ -2,6 +2,8 @@ from faster_whisper import WhisperModel
|
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
4
|
|
|
5
|
+
import ctranslate2
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
@dataclass
|
|
7
9
|
class Word:
|
|
@@ -12,7 +14,8 @@ class Word:
|
|
|
12
14
|
|
|
13
15
|
def transcribe(path):
|
|
14
16
|
model = WhisperModel("tiny", device="cpu", compute_type="int8")
|
|
15
|
-
segments, info = model.transcribe(
|
|
17
|
+
segments, info = model.transcribe(path, word_timestamps=True)
|
|
18
|
+
ctranslate2.set_random_seed(42)
|
|
16
19
|
|
|
17
20
|
words = []
|
|
18
21
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rewatchx
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Turn long videos into short captioned clips, locally.
|
|
5
|
+
Author: Ashfaaq Hamja Shaik
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/shaikashfaaqhamja/rewatch
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: typer
|
|
12
|
+
Requires-Dist: faster-whisper
|
|
13
|
+
Requires-Dist: av<19
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# rewatch
|
|
17
|
+
|
|
18
|
+
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.
|
|
19
|
+
|
|
20
|
+
I'm building this from scratch to learn, so it's still early. This is v0.2.0.
|
|
21
|
+
|
|
22
|
+
## What it can do right now
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
rewatch auto episode.mp4
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
You can still cut a clip by hand, or put captions on a clip you already have.
|
|
33
|
+
|
|
34
|
+
## How it picks the moments (for now)
|
|
35
|
+
|
|
36
|
+
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:
|
|
37
|
+
|
|
38
|
+
1. Check how loud every second is, and how fast people are talking.
|
|
39
|
+
2. Slide a 30 second window over the whole video and score each one.
|
|
40
|
+
3. Keep the top 10 windows that don't overlap.
|
|
41
|
+
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.
|
|
42
|
+
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.
|
|
43
|
+
6. Merge clips that overlap, and if one goes over 60 seconds, cut it back to the last full sentence.
|
|
44
|
+
|
|
45
|
+
These rules are only the starting point.
|
|
46
|
+
|
|
47
|
+
## What's next
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
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.
|
|
52
|
+
|
|
53
|
+
## Before you install
|
|
54
|
+
|
|
55
|
+
You need Python 3.11 or newer, and FFmpeg.
|
|
56
|
+
|
|
57
|
+
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:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
brew install ffmpeg-full
|
|
61
|
+
brew unlink ffmpeg
|
|
62
|
+
brew link --force ffmpeg-full
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
To check, run `ffmpeg -hide_banner -filters | grep subtitles`. If nothing prints, captions won't work.
|
|
66
|
+
|
|
67
|
+
## Install
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
pip install rewatchx
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
It's `rewatchx` because someone already took `rewatch` on PyPI. The command is still just `rewatch`.
|
|
74
|
+
|
|
75
|
+
Or from source:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
git clone https://github.com/shaikashfaaqhamja/rewatch.git
|
|
79
|
+
cd rewatch
|
|
80
|
+
python3 -m venv .venv
|
|
81
|
+
source .venv/bin/activate
|
|
82
|
+
pip install -e .
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## How to use it
|
|
86
|
+
|
|
87
|
+
Let it find the moments and make the clips:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
rewatch auto episode.mp4
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Clips go into a folder called `clips`. If you want a different folder:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
rewatch auto episode.mp4 --out-dir my_clips
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
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).
|
|
100
|
+
|
|
101
|
+
Cut 30 seconds yourself, starting at 1:30:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
rewatch cut episode.mp4 90 120 clip.mp4
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Put captions on a clip:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
rewatch captions clip.mp4 clip_captioned.mp4
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
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.
|
|
114
|
+
|
|
115
|
+
## What happens inside
|
|
116
|
+
|
|
117
|
+
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.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
MIT, use it however you want. See [LICENSE](LICENSE).
|
|
@@ -2,10 +2,13 @@ LICENSE
|
|
|
2
2
|
README.md
|
|
3
3
|
pyproject.toml
|
|
4
4
|
src/rewatch/__init__.py
|
|
5
|
+
src/rewatch/auto.py
|
|
5
6
|
src/rewatch/burn.py
|
|
6
7
|
src/rewatch/captions.py
|
|
7
8
|
src/rewatch/cli.py
|
|
8
9
|
src/rewatch/cut.py
|
|
10
|
+
src/rewatch/features.py
|
|
11
|
+
src/rewatch/highlights.py
|
|
9
12
|
src/rewatch/transcribe.py
|
|
10
13
|
src/rewatchx.egg-info/PKG-INFO
|
|
11
14
|
src/rewatchx.egg-info/SOURCES.txt
|
rewatchx-0.1.0/PKG-INFO
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: rewatchx
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Turn long videos into short captioned clips, locally.
|
|
5
|
-
Author: Ashfaaq Hamja Shaik
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/shaikashfaaqhamja/rewatch
|
|
8
|
-
Requires-Python: >=3.11
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Requires-Dist: typer
|
|
12
|
-
Requires-Dist: faster-whisper
|
|
13
|
-
Requires-Dist: av<19
|
|
14
|
-
Dynamic: license-file
|
|
15
|
-
|
|
16
|
-
# rewatch
|
|
17
|
-
|
|
18
|
-
rewatch takes a long video and turns it into short clips with captions. It all runs on your own laptop. No API keys, no uploading your videos anywhere, no paying per clip.
|
|
19
|
-
|
|
20
|
-
I'm building this from scratch to learn, so it's early. This is version 0.1.0.
|
|
21
|
-
|
|
22
|
-
## What works right now
|
|
23
|
-
|
|
24
|
-
You can cut any part of a video into a clip that plays everywhere (phones, Macs, Windows, Instagram, WhatsApp). You can also give it a clip and it will listen to the speech, write captions and put them on the video. The listening part uses Whisper, running locally.
|
|
25
|
-
|
|
26
|
-
## What I'm working on next
|
|
27
|
-
|
|
28
|
-
The big one: finding the best moments in a long video by itself. A lot of clipping tools just ask an AI chatbot "what's interesting here?". I want to train a model on what people actually rewatch on YouTube and use that instead.
|
|
29
|
-
|
|
30
|
-
After that, a vertical crop that follows whoever is talking, and captions in Hindi and Telugu.
|
|
31
|
-
|
|
32
|
-
## Before you install
|
|
33
|
-
|
|
34
|
-
You need Python 3.11 or newer, and FFmpeg.
|
|
35
|
-
|
|
36
|
-
One thing that took me a while to figure out: on a Mac, the normal `brew install ffmpeg` can't draw captions, because it's built without a library called libass. You need `ffmpeg-full`:
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
brew install ffmpeg-full
|
|
40
|
-
brew unlink ffmpeg
|
|
41
|
-
brew link --force ffmpeg-full
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
To check, run `ffmpeg -hide_banner -filters | grep subtitles`. If it prints nothing, captions won't work.
|
|
45
|
-
|
|
46
|
-
## Install
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
git clone https://github.com/shaikashfaaqhamja/rewatch.git
|
|
50
|
-
cd rewatch
|
|
51
|
-
python3 -m venv .venv
|
|
52
|
-
source .venv/bin/activate
|
|
53
|
-
pip install -e .
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## How to use it
|
|
57
|
-
|
|
58
|
-
Cut 30 seconds, starting at 1:30:
|
|
59
|
-
|
|
60
|
-
```
|
|
61
|
-
rewatch cut episode.mp4 90 120 clip.mp4
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
Put captions on a clip:
|
|
65
|
-
|
|
66
|
-
```
|
|
67
|
-
rewatch captions clip.mp4 clip_captioned.mp4
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
The first time you run captions it downloads the Whisper model, so give it a minute.
|
|
71
|
-
|
|
72
|
-
## What happens inside
|
|
73
|
-
|
|
74
|
-
FFmpeg cuts the clip and converts it to H.264 video and AAC audio, which is what plays everywhere. Then faster-whisper listens to it and gives back every word with the time it was said. I group those words into short lines of up to five words, and a line also ends wherever a sentence ends. The lines go into an SRT file, and FFmpeg draws them onto every frame.
|
|
75
|
-
|
|
76
|
-
## License
|
|
77
|
-
|
|
78
|
-
MIT, so you can use it however you want. See [LICENSE](LICENSE).
|
rewatchx-0.1.0/README.md
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# rewatch
|
|
2
|
-
|
|
3
|
-
rewatch takes a long video and turns it into short clips with captions. It all runs on your own laptop. No API keys, no uploading your videos anywhere, no paying per clip.
|
|
4
|
-
|
|
5
|
-
I'm building this from scratch to learn, so it's early. This is version 0.1.0.
|
|
6
|
-
|
|
7
|
-
## What works right now
|
|
8
|
-
|
|
9
|
-
You can cut any part of a video into a clip that plays everywhere (phones, Macs, Windows, Instagram, WhatsApp). You can also give it a clip and it will listen to the speech, write captions and put them on the video. The listening part uses Whisper, running locally.
|
|
10
|
-
|
|
11
|
-
## What I'm working on next
|
|
12
|
-
|
|
13
|
-
The big one: finding the best moments in a long video by itself. A lot of clipping tools just ask an AI chatbot "what's interesting here?". I want to train a model on what people actually rewatch on YouTube and use that instead.
|
|
14
|
-
|
|
15
|
-
After that, a vertical crop that follows whoever is talking, and captions in Hindi and Telugu.
|
|
16
|
-
|
|
17
|
-
## Before you install
|
|
18
|
-
|
|
19
|
-
You need Python 3.11 or newer, and FFmpeg.
|
|
20
|
-
|
|
21
|
-
One thing that took me a while to figure out: on a Mac, the normal `brew install ffmpeg` can't draw captions, because it's built without a library called libass. You need `ffmpeg-full`:
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
brew install ffmpeg-full
|
|
25
|
-
brew unlink ffmpeg
|
|
26
|
-
brew link --force ffmpeg-full
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
To check, run `ffmpeg -hide_banner -filters | grep subtitles`. If it prints nothing, captions won't work.
|
|
30
|
-
|
|
31
|
-
## Install
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
git clone https://github.com/shaikashfaaqhamja/rewatch.git
|
|
35
|
-
cd rewatch
|
|
36
|
-
python3 -m venv .venv
|
|
37
|
-
source .venv/bin/activate
|
|
38
|
-
pip install -e .
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## How to use it
|
|
42
|
-
|
|
43
|
-
Cut 30 seconds, starting at 1:30:
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
rewatch cut episode.mp4 90 120 clip.mp4
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Put captions on a clip:
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
rewatch captions clip.mp4 clip_captioned.mp4
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
The first time you run captions it downloads the Whisper model, so give it a minute.
|
|
56
|
-
|
|
57
|
-
## What happens inside
|
|
58
|
-
|
|
59
|
-
FFmpeg cuts the clip and converts it to H.264 video and AAC audio, which is what plays everywhere. Then faster-whisper listens to it and gives back every word with the time it was said. I group those words into short lines of up to five words, and a line also ends wherever a sentence ends. The lines go into an SRT file, and FFmpeg draws them onto every frame.
|
|
60
|
-
|
|
61
|
-
## License
|
|
62
|
-
|
|
63
|
-
MIT, so you can use it however you want. See [LICENSE](LICENSE).
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: rewatchx
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Turn long videos into short captioned clips, locally.
|
|
5
|
-
Author: Ashfaaq Hamja Shaik
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/shaikashfaaqhamja/rewatch
|
|
8
|
-
Requires-Python: >=3.11
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Requires-Dist: typer
|
|
12
|
-
Requires-Dist: faster-whisper
|
|
13
|
-
Requires-Dist: av<19
|
|
14
|
-
Dynamic: license-file
|
|
15
|
-
|
|
16
|
-
# rewatch
|
|
17
|
-
|
|
18
|
-
rewatch takes a long video and turns it into short clips with captions. It all runs on your own laptop. No API keys, no uploading your videos anywhere, no paying per clip.
|
|
19
|
-
|
|
20
|
-
I'm building this from scratch to learn, so it's early. This is version 0.1.0.
|
|
21
|
-
|
|
22
|
-
## What works right now
|
|
23
|
-
|
|
24
|
-
You can cut any part of a video into a clip that plays everywhere (phones, Macs, Windows, Instagram, WhatsApp). You can also give it a clip and it will listen to the speech, write captions and put them on the video. The listening part uses Whisper, running locally.
|
|
25
|
-
|
|
26
|
-
## What I'm working on next
|
|
27
|
-
|
|
28
|
-
The big one: finding the best moments in a long video by itself. A lot of clipping tools just ask an AI chatbot "what's interesting here?". I want to train a model on what people actually rewatch on YouTube and use that instead.
|
|
29
|
-
|
|
30
|
-
After that, a vertical crop that follows whoever is talking, and captions in Hindi and Telugu.
|
|
31
|
-
|
|
32
|
-
## Before you install
|
|
33
|
-
|
|
34
|
-
You need Python 3.11 or newer, and FFmpeg.
|
|
35
|
-
|
|
36
|
-
One thing that took me a while to figure out: on a Mac, the normal `brew install ffmpeg` can't draw captions, because it's built without a library called libass. You need `ffmpeg-full`:
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
brew install ffmpeg-full
|
|
40
|
-
brew unlink ffmpeg
|
|
41
|
-
brew link --force ffmpeg-full
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
To check, run `ffmpeg -hide_banner -filters | grep subtitles`. If it prints nothing, captions won't work.
|
|
45
|
-
|
|
46
|
-
## Install
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
git clone https://github.com/shaikashfaaqhamja/rewatch.git
|
|
50
|
-
cd rewatch
|
|
51
|
-
python3 -m venv .venv
|
|
52
|
-
source .venv/bin/activate
|
|
53
|
-
pip install -e .
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## How to use it
|
|
57
|
-
|
|
58
|
-
Cut 30 seconds, starting at 1:30:
|
|
59
|
-
|
|
60
|
-
```
|
|
61
|
-
rewatch cut episode.mp4 90 120 clip.mp4
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
Put captions on a clip:
|
|
65
|
-
|
|
66
|
-
```
|
|
67
|
-
rewatch captions clip.mp4 clip_captioned.mp4
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
The first time you run captions it downloads the Whisper model, so give it a minute.
|
|
71
|
-
|
|
72
|
-
## What happens inside
|
|
73
|
-
|
|
74
|
-
FFmpeg cuts the clip and converts it to H.264 video and AAC audio, which is what plays everywhere. Then faster-whisper listens to it and gives back every word with the time it was said. I group those words into short lines of up to five words, and a line also ends wherever a sentence ends. The lines go into an SRT file, and FFmpeg draws them onto every frame.
|
|
75
|
-
|
|
76
|
-
## License
|
|
77
|
-
|
|
78
|
-
MIT, so you can use it however you want. See [LICENSE](LICENSE).
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|