videopython 0.3.0__tar.gz → 0.4.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.
Potentially problematic release.
This version of videopython might be problematic. Click here for more details.
- {videopython-0.3.0 → videopython-0.4.0}/PKG-INFO +12 -12
- {videopython-0.3.0 → videopython-0.4.0}/README.md +10 -10
- {videopython-0.3.0 → videopython-0.4.0}/pyproject.toml +24 -5
- {videopython-0.3.0/src/videopython → videopython-0.4.0/src/videopython/ai}/generation/image.py +0 -3
- videopython-0.4.0/src/videopython/ai/understanding/transcribe.py +37 -0
- {videopython-0.3.0 → videopython-0.4.0}/src/videopython/base/effects.py +3 -3
- videopython-0.4.0/src/videopython/base/transcription.py +13 -0
- {videopython-0.3.0 → videopython-0.4.0}/src/videopython/base/transforms.py +0 -2
- videopython-0.4.0/src/videopython/base/video.py +440 -0
- videopython-0.4.0/src/videopython/py.typed +0 -0
- videopython-0.4.0/src/videopython/utils/__init__.py +3 -0
- videopython-0.4.0/src/videopython/utils/image.py +47 -0
- videopython-0.4.0/src/videopython/utils/text.py +727 -0
- videopython-0.3.0/src/videopython/base/video.py +0 -345
- videopython-0.3.0/src/videopython/utils/image.py +0 -279
- {videopython-0.3.0 → videopython-0.4.0}/.gitignore +0 -0
- {videopython-0.3.0 → videopython-0.4.0}/LICENSE +0 -0
- {videopython-0.3.0 → videopython-0.4.0}/src/videopython/__init__.py +0 -0
- {videopython-0.3.0/src/videopython/base → videopython-0.4.0/src/videopython/ai}/__init__.py +0 -0
- {videopython-0.3.0/src/videopython → videopython-0.4.0/src/videopython/ai}/generation/__init__.py +0 -0
- {videopython-0.3.0/src/videopython → videopython-0.4.0/src/videopython/ai}/generation/audio.py +0 -0
- {videopython-0.3.0/src/videopython → videopython-0.4.0/src/videopython/ai}/generation/video.py +0 -0
- {videopython-0.3.0/src/videopython/utils → videopython-0.4.0/src/videopython/ai/understanding}/__init__.py +0 -0
- /videopython-0.3.0/src/videopython/py.typed → /videopython-0.4.0/src/videopython/base/__init__.py +0 -0
- {videopython-0.3.0 → videopython-0.4.0}/src/videopython/base/compose.py +0 -0
- {videopython-0.3.0 → videopython-0.4.0}/src/videopython/base/exceptions.py +0 -0
- {videopython-0.3.0 → videopython-0.4.0}/src/videopython/base/transitions.py +0 -0
- {videopython-0.3.0 → videopython-0.4.0}/src/videopython/utils/common.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: videopython
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Minimal video generation and processing library.
|
|
5
5
|
Project-URL: Homepage, https://github.com/bartwojtowicz/videopython/
|
|
6
6
|
Project-URL: Repository, https://github.com/bartwojtowicz/videopython/
|
|
@@ -19,7 +19,7 @@ Requires-Dist: numpy>=1.25.2
|
|
|
19
19
|
Requires-Dist: opencv-python>=4.9.0.80
|
|
20
20
|
Requires-Dist: pillow>=10.3.0
|
|
21
21
|
Requires-Dist: pydub>=0.25.1
|
|
22
|
-
Requires-Dist: soundpython>=0.1.
|
|
22
|
+
Requires-Dist: soundpython>=0.1.11
|
|
23
23
|
Requires-Dist: tqdm>=4.66.3
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
|
|
@@ -39,10 +39,10 @@ sudo apt-get install ffmpeg
|
|
|
39
39
|
|
|
40
40
|
### Install with pip
|
|
41
41
|
```bash
|
|
42
|
-
pip install videopython[
|
|
42
|
+
pip install videopython[ai]
|
|
43
43
|
```
|
|
44
|
-
> You can install without `[
|
|
45
|
-
> The funcionalities found in `videopython.
|
|
44
|
+
> You can install without `[ai]` dependencies for basic video handling and processing.
|
|
45
|
+
> The funcionalities found in `videopython.ai` won't work.
|
|
46
46
|
|
|
47
47
|
## Basic Usage
|
|
48
48
|
|
|
@@ -52,10 +52,10 @@ pip install videopython[generation]
|
|
|
52
52
|
from videopython.base.video import Video
|
|
53
53
|
|
|
54
54
|
# Load videos and print metadata
|
|
55
|
-
video1 = Video.from_path("tests/test_data/
|
|
55
|
+
video1 = Video.from_path("tests/test_data/small_video.mp4")
|
|
56
56
|
print(video1)
|
|
57
57
|
|
|
58
|
-
video2 = Video.from_path("tests/test_data/
|
|
58
|
+
video2 = Video.from_path("tests/test_data/big_video.mp4")
|
|
59
59
|
print(video2)
|
|
60
60
|
|
|
61
61
|
# Define the transformations
|
|
@@ -79,18 +79,18 @@ savepath = video.save()
|
|
|
79
79
|
|
|
80
80
|
### Video Generation
|
|
81
81
|
|
|
82
|
-
> Using Nvidia A40 or better is recommended for the `videopython.
|
|
82
|
+
> Using Nvidia A40 or better is recommended for the `videopython.ai` module.
|
|
83
83
|
```python
|
|
84
84
|
# Generate image and animate it
|
|
85
|
-
from videopython.generation import ImageToVideo
|
|
86
|
-
from videopython.generation import TextToImage
|
|
87
|
-
from videopython.generation import TextToMusic
|
|
85
|
+
from videopython.ai.generation import ImageToVideo
|
|
86
|
+
from videopython.ai.generation import TextToImage
|
|
87
|
+
from videopython.ai.generation import TextToMusic
|
|
88
88
|
|
|
89
89
|
image = TextToImage().generate_image(prompt="Golden Retriever playing in the park")
|
|
90
90
|
video = ImageToVideo().generate_video(image=image, fps=24)
|
|
91
91
|
|
|
92
92
|
# Video generation directly from prompt
|
|
93
|
-
from videopython.generation import TextToVideo
|
|
93
|
+
from videopython.ai.generation import TextToVideo
|
|
94
94
|
video_gen = TextToVideo()
|
|
95
95
|
video = video_gen.generate_video("Dogs playing in the snow")
|
|
96
96
|
for _ in range(10):
|
|
@@ -14,10 +14,10 @@ sudo apt-get install ffmpeg
|
|
|
14
14
|
|
|
15
15
|
### Install with pip
|
|
16
16
|
```bash
|
|
17
|
-
pip install videopython[
|
|
17
|
+
pip install videopython[ai]
|
|
18
18
|
```
|
|
19
|
-
> You can install without `[
|
|
20
|
-
> The funcionalities found in `videopython.
|
|
19
|
+
> You can install without `[ai]` dependencies for basic video handling and processing.
|
|
20
|
+
> The funcionalities found in `videopython.ai` won't work.
|
|
21
21
|
|
|
22
22
|
## Basic Usage
|
|
23
23
|
|
|
@@ -27,10 +27,10 @@ pip install videopython[generation]
|
|
|
27
27
|
from videopython.base.video import Video
|
|
28
28
|
|
|
29
29
|
# Load videos and print metadata
|
|
30
|
-
video1 = Video.from_path("tests/test_data/
|
|
30
|
+
video1 = Video.from_path("tests/test_data/small_video.mp4")
|
|
31
31
|
print(video1)
|
|
32
32
|
|
|
33
|
-
video2 = Video.from_path("tests/test_data/
|
|
33
|
+
video2 = Video.from_path("tests/test_data/big_video.mp4")
|
|
34
34
|
print(video2)
|
|
35
35
|
|
|
36
36
|
# Define the transformations
|
|
@@ -54,18 +54,18 @@ savepath = video.save()
|
|
|
54
54
|
|
|
55
55
|
### Video Generation
|
|
56
56
|
|
|
57
|
-
> Using Nvidia A40 or better is recommended for the `videopython.
|
|
57
|
+
> Using Nvidia A40 or better is recommended for the `videopython.ai` module.
|
|
58
58
|
```python
|
|
59
59
|
# Generate image and animate it
|
|
60
|
-
from videopython.generation import ImageToVideo
|
|
61
|
-
from videopython.generation import TextToImage
|
|
62
|
-
from videopython.generation import TextToMusic
|
|
60
|
+
from videopython.ai.generation import ImageToVideo
|
|
61
|
+
from videopython.ai.generation import TextToImage
|
|
62
|
+
from videopython.ai.generation import TextToMusic
|
|
63
63
|
|
|
64
64
|
image = TextToImage().generate_image(prompt="Golden Retriever playing in the park")
|
|
65
65
|
video = ImageToVideo().generate_video(image=image, fps=24)
|
|
66
66
|
|
|
67
67
|
# Video generation directly from prompt
|
|
68
|
-
from videopython.generation import TextToVideo
|
|
68
|
+
from videopython.ai.generation import TextToVideo
|
|
69
69
|
video_gen = TextToVideo()
|
|
70
70
|
video = video_gen.generate_video("Dogs playing in the snow")
|
|
71
71
|
for _ in range(10):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "videopython"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.0"
|
|
4
4
|
description = "Minimal video generation and processing library."
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Bartosz Wójtowicz", email = "bartoszwojtowicz@outlook.com" },
|
|
@@ -24,24 +24,27 @@ dependencies = [
|
|
|
24
24
|
"opencv-python>=4.9.0.80",
|
|
25
25
|
"pillow>=10.3.0",
|
|
26
26
|
"pydub>=0.25.1",
|
|
27
|
-
"soundpython>=0.1.
|
|
27
|
+
"soundpython>=0.1.11",
|
|
28
28
|
"tqdm>=4.66.3",
|
|
29
|
+
|
|
29
30
|
]
|
|
30
31
|
|
|
31
32
|
[dependency-groups]
|
|
32
33
|
dev = [
|
|
33
|
-
"
|
|
34
|
-
"isort>=5.12.0",
|
|
34
|
+
"ruff>=0.1.14",
|
|
35
35
|
"mypy>=1.8.0",
|
|
36
36
|
"pytest>=7.4.0",
|
|
37
37
|
"types-Pillow>=10.2.0.20240213",
|
|
38
38
|
"types-tqdm>=4.66.0.20240106",
|
|
39
|
+
"pytest-cov>=6.1.1",
|
|
39
40
|
]
|
|
40
|
-
|
|
41
|
+
ai = [
|
|
41
42
|
"accelerate>=0.29.2",
|
|
42
43
|
"diffusers>=0.26.3",
|
|
43
44
|
"torch>=2.1.0",
|
|
44
45
|
"transformers>=4.38.1",
|
|
46
|
+
"openai-whisper>=20240930",
|
|
47
|
+
"numba>=0.61.0",
|
|
45
48
|
]
|
|
46
49
|
|
|
47
50
|
[project.urls]
|
|
@@ -67,3 +70,19 @@ pythonpath = [".src/"]
|
|
|
67
70
|
testpaths = ["src/tests"]
|
|
68
71
|
python_files = ["test_*.py"]
|
|
69
72
|
addopts = "-v --tb=short"
|
|
73
|
+
|
|
74
|
+
[tool.ruff]
|
|
75
|
+
line-length = 120
|
|
76
|
+
target-version = "py310"
|
|
77
|
+
|
|
78
|
+
[tool.ruff.lint]
|
|
79
|
+
select = [
|
|
80
|
+
"E", # pycodestyle errors
|
|
81
|
+
"F", # pyflakes
|
|
82
|
+
"I", # isort
|
|
83
|
+
]
|
|
84
|
+
isort.known-first-party = ["videopython"]
|
|
85
|
+
|
|
86
|
+
[tool.ruff.format]
|
|
87
|
+
indent-style = "space"
|
|
88
|
+
quote-style = "double"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
import whisper
|
|
4
|
+
|
|
5
|
+
from videopython.base.transcription import Transcription, TranscriptionSegment
|
|
6
|
+
from videopython.base.video import Video
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class VideoTranscription:
|
|
10
|
+
def __init__(self, model_name: Literal["tiny", "base", "small", "medium", "large", "turbo"] = "small") -> None:
|
|
11
|
+
self.model = whisper.load_model(name=model_name)
|
|
12
|
+
|
|
13
|
+
def transcribe_video(self, video: Video) -> Transcription:
|
|
14
|
+
"""Transcribes video to text.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
video: Video to transcribe.
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
List of dictionaries with segments of text and their start and end times.
|
|
21
|
+
"""
|
|
22
|
+
if video.audio.is_silent:
|
|
23
|
+
return Transcription(segments=[])
|
|
24
|
+
|
|
25
|
+
audio = video.audio.to_mono()
|
|
26
|
+
audio = audio.resample(whisper.audio.SAMPLE_RATE)
|
|
27
|
+
audio_data = audio.data
|
|
28
|
+
|
|
29
|
+
transcription = self.model.transcribe(audio=audio_data, word_timestamps=True)
|
|
30
|
+
|
|
31
|
+
transcription_segments = [
|
|
32
|
+
TranscriptionSegment(start=segment["start"], end=segment["end"], text=segment["text"])
|
|
33
|
+
for segment in transcription["segments"]
|
|
34
|
+
]
|
|
35
|
+
result = Transcription(segments=transcription_segments)
|
|
36
|
+
|
|
37
|
+
return result
|
|
@@ -156,13 +156,13 @@ class Zoom(Effect):
|
|
|
156
156
|
|
|
157
157
|
width = video.metadata.width
|
|
158
158
|
height = video.metadata.height
|
|
159
|
-
crop_sizes_w, crop_sizes_h =
|
|
160
|
-
|
|
159
|
+
crop_sizes_w, crop_sizes_h = (
|
|
160
|
+
np.linspace(width // self.zoom_factor, width, n_frames),
|
|
161
|
+
np.linspace(height // self.zoom_factor, height, n_frames),
|
|
161
162
|
)
|
|
162
163
|
|
|
163
164
|
if self.mode == "in":
|
|
164
165
|
for frame, w, h in tqdm(zip(video.frames, reversed(crop_sizes_w), reversed(crop_sizes_h))):
|
|
165
|
-
|
|
166
166
|
x = width / 2 - w / 2
|
|
167
167
|
y = height / 2 - h / 2
|
|
168
168
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from enum import Enum
|
|
3
3
|
from multiprocessing import Pool
|
|
4
|
-
from typing import Literal
|
|
5
4
|
|
|
6
5
|
import cv2
|
|
7
6
|
import numpy as np
|
|
@@ -154,7 +153,6 @@ class CropMode(Enum):
|
|
|
154
153
|
|
|
155
154
|
|
|
156
155
|
class Crop(Transformation):
|
|
157
|
-
|
|
158
156
|
def __init__(self, width: int, height: int, mode: CropMode = CropMode.CENTER):
|
|
159
157
|
self.width = width
|
|
160
158
|
self.height = height
|