rewatchx 0.1.0__py3-none-any.whl
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.
- rewatch/__init__.py +0 -0
- rewatch/burn.py +19 -0
- rewatch/captions.py +50 -0
- rewatch/cli.py +29 -0
- rewatch/cut.py +36 -0
- rewatch/transcribe.py +28 -0
- rewatchx-0.1.0.dist-info/METADATA +78 -0
- rewatchx-0.1.0.dist-info/RECORD +12 -0
- rewatchx-0.1.0.dist-info/WHEEL +5 -0
- rewatchx-0.1.0.dist-info/entry_points.txt +2 -0
- rewatchx-0.1.0.dist-info/licenses/LICENSE +22 -0
- rewatchx-0.1.0.dist-info/top_level.txt +1 -0
rewatch/__init__.py
ADDED
|
File without changes
|
rewatch/burn.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def burn(input_path, srt_path, output_path):
|
|
5
|
+
command = [
|
|
6
|
+
"ffmpeg", "-y", "-hide_banner", "-loglevel", "error",
|
|
7
|
+
"-i", input_path,
|
|
8
|
+
"-vf", f"subtitles={srt_path}",
|
|
9
|
+
"-c:v", "libx264", "-crf", "18",
|
|
10
|
+
"-c:a", "copy",
|
|
11
|
+
"-pix_fmt", "yuv420p",
|
|
12
|
+
"-movflags", "+faststart",
|
|
13
|
+
output_path,
|
|
14
|
+
]
|
|
15
|
+
subprocess.run(command, check=True)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__":
|
|
19
|
+
burn("clip.mp4", "clip.srt", "clip_captioned.mp4")
|
rewatch/captions.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from rewatch.transcribe import Word
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class Caption:
|
|
6
|
+
text: str
|
|
7
|
+
start: float
|
|
8
|
+
end: float
|
|
9
|
+
|
|
10
|
+
def group_words(words, max_words = 5):
|
|
11
|
+
captions = []
|
|
12
|
+
current = []
|
|
13
|
+
for word in words:
|
|
14
|
+
current.append(word)
|
|
15
|
+
if len(current) >= max_words or word.text.endswith(('.', '?', '!')):
|
|
16
|
+
text = " ".join([w.text for w in current])
|
|
17
|
+
start = current[0].start
|
|
18
|
+
end = current[-1].end
|
|
19
|
+
captions.append(Caption(text, start, end))
|
|
20
|
+
current = []
|
|
21
|
+
if current:
|
|
22
|
+
text = " ".join([w.text for w in current])
|
|
23
|
+
start = current[0].start
|
|
24
|
+
end = current[-1].end
|
|
25
|
+
captions.append(Caption(text, start, end))
|
|
26
|
+
return captions
|
|
27
|
+
|
|
28
|
+
def srt_time(seconds):
|
|
29
|
+
ms = round(seconds * 1000)
|
|
30
|
+
hours = ms // 3600000
|
|
31
|
+
minutes = (ms % 3600000) // 60000
|
|
32
|
+
secs = (ms % 60000) // 1000
|
|
33
|
+
millis = ms % 1000
|
|
34
|
+
return f"{hours:02}:{minutes:02}:{secs:02},{millis:03}"
|
|
35
|
+
|
|
36
|
+
def write_srt(captions, path):
|
|
37
|
+
with open(path, 'w', encoding='utf-8') as f:
|
|
38
|
+
for i, c in enumerate(captions, start=1):
|
|
39
|
+
f.write(f"{i}\n")
|
|
40
|
+
f.write(f"{srt_time(c.start)} --> {srt_time(c.end)}\n")
|
|
41
|
+
f.write(f"{c.text}\n\n")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
print(srt_time(1.14), srt_time(75.5))
|
|
46
|
+
from rewatch.transcribe import transcribe
|
|
47
|
+
|
|
48
|
+
captions = group_words(transcribe("clip.mp4"))
|
|
49
|
+
write_srt(captions, "clip.srt")
|
|
50
|
+
|
rewatch/cli.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
from rewatch.transcribe import transcribe
|
|
3
|
+
from rewatch.captions import group_words, write_srt
|
|
4
|
+
from rewatch.burn import burn
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from rewatch.cut import cut as cut_video
|
|
8
|
+
app = typer.Typer()
|
|
9
|
+
|
|
10
|
+
@app.callback()
|
|
11
|
+
def main():
|
|
12
|
+
"""rewatch turn long videos into short clips"""
|
|
13
|
+
|
|
14
|
+
@app.command()
|
|
15
|
+
def cut(input_path: str, start: float, end: float, output_path: str):
|
|
16
|
+
cut_video(input_path, start, end, output_path)
|
|
17
|
+
typer.echo(f"Saved clip to {output_path}")
|
|
18
|
+
|
|
19
|
+
@app.command()
|
|
20
|
+
def captions(input_path: str, output_path: str):
|
|
21
|
+
words = transcribe(input_path)
|
|
22
|
+
lines = group_words(words)
|
|
23
|
+
write_srt(lines, "captions.srt")
|
|
24
|
+
burn(input_path, "captions.srt", output_path)
|
|
25
|
+
typer.echo(f"Saved captions to {output_path}")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
rewatch/cut.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import sys
|
|
3
|
+
def cut(input_path, start, end, output_path):
|
|
4
|
+
command = [
|
|
5
|
+
"ffmpeg",
|
|
6
|
+
"-hide_banner",
|
|
7
|
+
"-loglevel",
|
|
8
|
+
"error",
|
|
9
|
+
"-y",
|
|
10
|
+
"-ss",
|
|
11
|
+
str(start),
|
|
12
|
+
"-to",
|
|
13
|
+
str(end),
|
|
14
|
+
"-i",
|
|
15
|
+
input_path,
|
|
16
|
+
"-c:v",
|
|
17
|
+
"libx264",
|
|
18
|
+
"-crf",
|
|
19
|
+
"18",
|
|
20
|
+
"-c:a",
|
|
21
|
+
"aac",
|
|
22
|
+
"-pix_fmt",
|
|
23
|
+
"yuv420p",
|
|
24
|
+
"-movflags",
|
|
25
|
+
"+faststart",
|
|
26
|
+
output_path
|
|
27
|
+
]
|
|
28
|
+
subprocess.run(command,check=True)
|
|
29
|
+
|
|
30
|
+
if __name__ == "__main__":
|
|
31
|
+
if len(sys.argv) != 5:
|
|
32
|
+
print("Usage: python cut.py <input_path> <start_time> <end_time> <output_path>")
|
|
33
|
+
sys.exit(1)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
cut(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
|
rewatch/transcribe.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from faster_whisper import WhisperModel
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class Word:
|
|
8
|
+
text: str
|
|
9
|
+
start: float
|
|
10
|
+
end: float
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def transcribe(path):
|
|
14
|
+
model = WhisperModel("tiny", device="cpu", compute_type="int8")
|
|
15
|
+
segments, info = model.transcribe("clip.mp4", word_timestamps=True)
|
|
16
|
+
|
|
17
|
+
words = []
|
|
18
|
+
|
|
19
|
+
for segment in segments:
|
|
20
|
+
for word in segment.words:
|
|
21
|
+
words.append(Word(word.word.strip(), float(round(word.start, 2)), float(round(word.end, 2))))
|
|
22
|
+
|
|
23
|
+
return words
|
|
24
|
+
|
|
25
|
+
if __name__ == "__main__":
|
|
26
|
+
words = transcribe("clip.mp4")
|
|
27
|
+
for w in words:
|
|
28
|
+
print(w)
|
|
@@ -0,0 +1,78 @@
|
|
|
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).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
rewatch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
rewatch/burn.py,sha256=Fj0dJZOsWn-N2rxSSJ3lEknT-WTWJShx4w1Q8hxwIIY,491
|
|
3
|
+
rewatch/captions.py,sha256=fZugt_GVfATstSKu9trJC1xemcEJKG4ZQA5msf87pC0,1460
|
|
4
|
+
rewatch/cli.py,sha256=czTBAcuDkQUYuNIN-OW1Vu6g_VhlHkjKn17tXBGHqHw,738
|
|
5
|
+
rewatch/cut.py,sha256=azJEIGsZFNLrqxtoQ57hSs4ACgxNruZmAvpvobWibdU,755
|
|
6
|
+
rewatch/transcribe.py,sha256=kOArXo2evB-x9tXeS7C7wlPuvPJxNsKqtttLEIMuYNY,618
|
|
7
|
+
rewatchx-0.1.0.dist-info/licenses/LICENSE,sha256=Hmr5L_SicBukp4FHTmk90kRd4XavSvdrC4SShar3es8,1081
|
|
8
|
+
rewatchx-0.1.0.dist-info/METADATA,sha256=fDuKjU-kR3JOwchWWqW-FZQBXvDCMABk0v2KHHLLSH4,2658
|
|
9
|
+
rewatchx-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
10
|
+
rewatchx-0.1.0.dist-info/entry_points.txt,sha256=QukhIVztVDtFkgbAvE1XT-8OJ3GeP6-7VNaT16q2GOs,44
|
|
11
|
+
rewatchx-0.1.0.dist-info/top_level.txt,sha256=MdgnZ0UdeWl4q9nq9pW_y-bTDGsRiPxjBKKMXWkJnOg,8
|
|
12
|
+
rewatchx-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ashfaaq Hamja Shaik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rewatch
|