visualkit 0.0.1__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.
- visualkit-0.0.1/AUTHORS.rst +4 -0
- visualkit-0.0.1/LICENSE +9 -0
- visualkit-0.0.1/PKG-INFO +53 -0
- visualkit-0.0.1/README.md +40 -0
- visualkit-0.0.1/pyproject.toml +30 -0
- visualkit-0.0.1/setup.cfg +4 -0
- visualkit-0.0.1/src/visualkit/__init__.py +6 -0
- visualkit-0.0.1/src/visualkit/__main__.py +5 -0
- visualkit-0.0.1/src/visualkit/config.py +26 -0
- visualkit-0.0.1/src/visualkit/editor.py +183 -0
- visualkit-0.0.1/src/visualkit/enums.py +7 -0
- visualkit-0.0.1/src/visualkit/media_element.py +1356 -0
- visualkit-0.0.1/src/visualkit/project_creator.py +130 -0
- visualkit-0.0.1/src/visualkit/text_element.py +277 -0
- visualkit-0.0.1/src/visualkit/timeline.py +47 -0
- visualkit-0.0.1/src/visualkit/transitions.py +595 -0
- visualkit-0.0.1/src/visualkit/utils.py +5 -0
- visualkit-0.0.1/src/visualkit.egg-info/PKG-INFO +53 -0
- visualkit-0.0.1/src/visualkit.egg-info/SOURCES.txt +20 -0
- visualkit-0.0.1/src/visualkit.egg-info/dependency_links.txt +1 -0
- visualkit-0.0.1/src/visualkit.egg-info/requires.txt +1 -0
- visualkit-0.0.1/src/visualkit.egg-info/top_level.txt +1 -0
visualkit-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Suraj Airi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
visualkit-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: visualkit
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Lightning-fast Python package for video frame effects and transitions. Comprehensive collection of visual effects with optimized OpenCV backend for maximum rendering speed.
|
|
5
|
+
Author-email: Suraj Airi <surajairi.ml@gmail.com>
|
|
6
|
+
License: MIT license
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: AUTHORS.rst
|
|
11
|
+
Requires-Dist: opencv-python>=4.12.0.88
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# VisualKit
|
|
15
|
+
|
|
16
|
+
## Overview
|
|
17
|
+
Lightning-fast Python package for video frame effects and transitions. Comprehensive collection of visual effects with optimized OpenCV backend for maximum rendering speed.
|
|
18
|
+
|
|
19
|
+
## Getting Started
|
|
20
|
+
|
|
21
|
+
### Prerequisites
|
|
22
|
+
- List your requirements here
|
|
23
|
+
|
|
24
|
+
### Installation
|
|
25
|
+
```bash
|
|
26
|
+
# Add installation commands
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Usage
|
|
30
|
+
```bash
|
|
31
|
+
# Add usage examples
|
|
32
|
+
```bash
|
|
33
|
+
# Add usage examples
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Project Structure
|
|
37
|
+
```
|
|
38
|
+
├── src/
|
|
39
|
+
├── tests/
|
|
40
|
+
├── docs/
|
|
41
|
+
└── README.md
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
For detailed architecture information, see [docs/architecture.md](docs/architecture.md).
|
|
45
|
+
|
|
46
|
+
## Contributing
|
|
47
|
+
1. Fork the repository
|
|
48
|
+
2. Create a feature branch
|
|
49
|
+
3. Make your changes
|
|
50
|
+
4. Submit a pull request
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
This project is licensed under the [LICENSE](LICENSE) file in the root directory.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# VisualKit
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
Lightning-fast Python package for video frame effects and transitions. Comprehensive collection of visual effects with optimized OpenCV backend for maximum rendering speed.
|
|
5
|
+
|
|
6
|
+
## Getting Started
|
|
7
|
+
|
|
8
|
+
### Prerequisites
|
|
9
|
+
- List your requirements here
|
|
10
|
+
|
|
11
|
+
### Installation
|
|
12
|
+
```bash
|
|
13
|
+
# Add installation commands
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Usage
|
|
17
|
+
```bash
|
|
18
|
+
# Add usage examples
|
|
19
|
+
```bash
|
|
20
|
+
# Add usage examples
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Project Structure
|
|
24
|
+
```
|
|
25
|
+
├── src/
|
|
26
|
+
├── tests/
|
|
27
|
+
├── docs/
|
|
28
|
+
└── README.md
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
For detailed architecture information, see [docs/architecture.md](docs/architecture.md).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
1. Fork the repository
|
|
35
|
+
2. Create a feature branch
|
|
36
|
+
3. Make your changes
|
|
37
|
+
4. Submit a pull request
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
This project is licensed under the [LICENSE](LICENSE) file in the root directory.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=45", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "visualkit"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "Lightning-fast Python package for video frame effects and transitions. Comprehensive collection of visual effects with optimized OpenCV backend for maximum rendering speed."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Suraj Airi", email = "surajairi.ml@gmail.com" }
|
|
12
|
+
]
|
|
13
|
+
license = { text = "MIT license" }
|
|
14
|
+
requires-python = ">=3.9"
|
|
15
|
+
dependencies = [
|
|
16
|
+
"opencv-python>=4.12.0.88",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[dependency-groups]
|
|
20
|
+
dev = [
|
|
21
|
+
"ruff>=0.12.1",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.package-dir]
|
|
29
|
+
"" = "src"
|
|
30
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class VideoConfig:
|
|
6
|
+
"""Video configuration for the video editor.
|
|
7
|
+
Attributes:
|
|
8
|
+
width (int): Width of the video in pixels.
|
|
9
|
+
height (int): Height of the video in pixels.
|
|
10
|
+
fps (int): Frames per second for the video.
|
|
11
|
+
codec (str): Codec to use for video encoding.
|
|
12
|
+
resize_method (str): Method to use for resizing images. [adaptive (default)] Options: smart, adaptive, gradual, aspect_ratio.
|
|
13
|
+
""" # noqa: E501
|
|
14
|
+
|
|
15
|
+
width: int = 1280
|
|
16
|
+
height: int = 720
|
|
17
|
+
fps: int = 30
|
|
18
|
+
codec: str = "avc1"
|
|
19
|
+
resize_method: str = "adaptive" # Options: smart, adaptive, gradual, aspect_ratio
|
|
20
|
+
|
|
21
|
+
def __post_init__(self):
|
|
22
|
+
"""Validate configuration parameters"""
|
|
23
|
+
if self.width <= 0 or self.height <= 0:
|
|
24
|
+
raise ValueError("Width and height must be positive")
|
|
25
|
+
if self.fps <= 0:
|
|
26
|
+
raise ValueError("FPS must be positive")
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
from typing import Any, Dict
|
|
2
|
+
|
|
3
|
+
import cv2
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
from visualkit.config import VideoConfig
|
|
7
|
+
from visualkit.enums import AnimationType
|
|
8
|
+
from visualkit.media_element import MediaElement
|
|
9
|
+
from visualkit.text_element import SubtitleElement, TextRenderer
|
|
10
|
+
from visualkit.timeline import Timeline
|
|
11
|
+
from visualkit.transitions import TransitionElement
|
|
12
|
+
from visualkit.utils import logger
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SimpleVideoEditor:
|
|
16
|
+
def __init__(self, config: VideoConfig | None = None):
|
|
17
|
+
self.config = config or VideoConfig()
|
|
18
|
+
self.text_renderer = TextRenderer(self.config)
|
|
19
|
+
self.timeline = Timeline()
|
|
20
|
+
self.subtitle_elements = []
|
|
21
|
+
|
|
22
|
+
def load_from_json(self, json_data: Dict[str, Any]):
|
|
23
|
+
try:
|
|
24
|
+
config_data = json_data.get("config", {})
|
|
25
|
+
self.config.width = config_data.get("width", self.config.width)
|
|
26
|
+
self.config.height = config_data.get("height", self.config.height)
|
|
27
|
+
self.config.fps = config_data.get("fps", self.config.fps)
|
|
28
|
+
self.config.codec = config_data.get("codec", self.config.codec)
|
|
29
|
+
self.config.resize_method = config_data.get(
|
|
30
|
+
"resize_method", self.config.resize_method
|
|
31
|
+
)
|
|
32
|
+
self.config.__post_init__()
|
|
33
|
+
self.text_renderer = TextRenderer(self.config)
|
|
34
|
+
assets = json_data.get("assets", {})
|
|
35
|
+
main_layer = json_data.get("main_layer", [])
|
|
36
|
+
current_time = 0.0
|
|
37
|
+
for element_data in main_layer:
|
|
38
|
+
element_type = element_data.get("type")
|
|
39
|
+
if element_type == "media":
|
|
40
|
+
media_id = element_data.get("media")
|
|
41
|
+
duration = element_data.get("duration", 5.0)
|
|
42
|
+
effect = element_data.get("effect", "none")
|
|
43
|
+
if media_id in assets:
|
|
44
|
+
asset_path = assets[media_id]["path"]
|
|
45
|
+
try:
|
|
46
|
+
media_element = MediaElement(asset_path, duration, effect)
|
|
47
|
+
self.timeline.add_element(
|
|
48
|
+
media_element, current_time, current_time + duration
|
|
49
|
+
)
|
|
50
|
+
current_time += duration
|
|
51
|
+
except Exception as e:
|
|
52
|
+
logger.error(f"Failed to load media {asset_path}: {e}")
|
|
53
|
+
continue
|
|
54
|
+
elif element_type == "transition":
|
|
55
|
+
duration = element_data.get("duration", 1.0)
|
|
56
|
+
transition_type = element_data.get("transition_type", "crossfade")
|
|
57
|
+
try:
|
|
58
|
+
transition_element = TransitionElement(
|
|
59
|
+
duration, transition_type
|
|
60
|
+
)
|
|
61
|
+
self.timeline.add_element(
|
|
62
|
+
transition_element, current_time, current_time + duration
|
|
63
|
+
)
|
|
64
|
+
current_time += duration
|
|
65
|
+
except Exception as e:
|
|
66
|
+
logger.error(f"Failed to create transition: {e}")
|
|
67
|
+
continue
|
|
68
|
+
subtitle_layers = json_data.get("subtitle_layers", [])
|
|
69
|
+
for layer_data in subtitle_layers:
|
|
70
|
+
for subtitle_data in layer_data.get("elements", []):
|
|
71
|
+
try:
|
|
72
|
+
start_time = self._parse_time(
|
|
73
|
+
subtitle_data.get("start_time", 0)
|
|
74
|
+
)
|
|
75
|
+
end_time = self._parse_time(subtitle_data.get("end_time", 5))
|
|
76
|
+
text = subtitle_data.get("text", "")
|
|
77
|
+
animation_type = AnimationType(
|
|
78
|
+
subtitle_data.get("animation_type", "typewriter")
|
|
79
|
+
)
|
|
80
|
+
typewriter_speed = subtitle_data.get("typewriter_speed", 20.0)
|
|
81
|
+
subtitle = SubtitleElement(
|
|
82
|
+
start_time, end_time, text, animation_type, typewriter_speed
|
|
83
|
+
)
|
|
84
|
+
self.subtitle_elements.append(subtitle)
|
|
85
|
+
except Exception as e:
|
|
86
|
+
logger.error(f"Failed to create subtitle: {e}")
|
|
87
|
+
continue
|
|
88
|
+
except Exception as e:
|
|
89
|
+
logger.error(f"Error loading project: {e}")
|
|
90
|
+
raise
|
|
91
|
+
|
|
92
|
+
def _parse_time(self, time_str) -> float:
|
|
93
|
+
if isinstance(time_str, (int, float)):
|
|
94
|
+
return float(time_str)
|
|
95
|
+
if ":" in str(time_str):
|
|
96
|
+
try:
|
|
97
|
+
parts = str(time_str).split(":")
|
|
98
|
+
if len(parts) == 2:
|
|
99
|
+
minutes = int(parts[0])
|
|
100
|
+
seconds = int(parts[1])
|
|
101
|
+
return minutes * 60 + seconds
|
|
102
|
+
except ValueError:
|
|
103
|
+
pass
|
|
104
|
+
return float(time_str)
|
|
105
|
+
|
|
106
|
+
def get_duration(self) -> float:
|
|
107
|
+
return self.timeline.get_duration()
|
|
108
|
+
|
|
109
|
+
def render_frame(self, timestamp: float) -> np.ndarray:
|
|
110
|
+
frame = np.zeros((self.config.height, self.config.width, 3), dtype=np.uint8)
|
|
111
|
+
active_element_info = self.timeline.get_active_element(timestamp)
|
|
112
|
+
if active_element_info:
|
|
113
|
+
element = active_element_info["element"]
|
|
114
|
+
local_time = timestamp - active_element_info["start_time"]
|
|
115
|
+
if isinstance(element, MediaElement):
|
|
116
|
+
frame = element.get_frame(local_time, self.config)
|
|
117
|
+
elif isinstance(element, TransitionElement):
|
|
118
|
+
prev_info = self.timeline.get_previous_media_element(
|
|
119
|
+
active_element_info["start_time"]
|
|
120
|
+
)
|
|
121
|
+
next_info = self.timeline.get_next_media_element(
|
|
122
|
+
active_element_info["end_time"]
|
|
123
|
+
)
|
|
124
|
+
prev_frame = frame
|
|
125
|
+
next_frame = frame
|
|
126
|
+
if prev_info:
|
|
127
|
+
prev_frame = prev_info["element"].get_frame(
|
|
128
|
+
prev_info["element"].duration - 0.001, self.config
|
|
129
|
+
)
|
|
130
|
+
if next_info:
|
|
131
|
+
next_frame = next_info["element"].get_frame(0.001, self.config)
|
|
132
|
+
frame = element.apply(prev_frame, next_frame, local_time)
|
|
133
|
+
for subtitle in self.subtitle_elements:
|
|
134
|
+
frame = self.text_renderer.render_subtitle(frame, subtitle, timestamp)
|
|
135
|
+
return frame
|
|
136
|
+
|
|
137
|
+
def render_video(self, output_path: str, show_progress: bool = True) -> bool:
|
|
138
|
+
duration = self.get_duration()
|
|
139
|
+
if duration <= 0:
|
|
140
|
+
logger.error("Project has no duration")
|
|
141
|
+
return False
|
|
142
|
+
total_frames = int(duration * self.config.fps)
|
|
143
|
+
if total_frames <= 0:
|
|
144
|
+
logger.error("Invalid frame count")
|
|
145
|
+
return False
|
|
146
|
+
fourcc = cv2.VideoWriter_fourcc(*self.config.codec)
|
|
147
|
+
out = cv2.VideoWriter(
|
|
148
|
+
output_path,
|
|
149
|
+
fourcc,
|
|
150
|
+
self.config.fps,
|
|
151
|
+
(self.config.width, self.config.height),
|
|
152
|
+
)
|
|
153
|
+
if not out.isOpened():
|
|
154
|
+
logger.error(f"Could not open video writer for {output_path}")
|
|
155
|
+
return False
|
|
156
|
+
try:
|
|
157
|
+
for frame_idx in range(total_frames):
|
|
158
|
+
timestamp = frame_idx / self.config.fps
|
|
159
|
+
frame = self.render_frame(timestamp)
|
|
160
|
+
if frame.shape[:2] != (self.config.height, self.config.width):
|
|
161
|
+
frame = cv2.resize(
|
|
162
|
+
frame,
|
|
163
|
+
(self.config.width, self.config.height),
|
|
164
|
+
interpolation=cv2.INTER_AREA,
|
|
165
|
+
)
|
|
166
|
+
out.write(frame)
|
|
167
|
+
if show_progress and frame_idx % 30 == 0:
|
|
168
|
+
progress = (frame_idx + 1) / total_frames
|
|
169
|
+
print(f"\rRendering: {progress:.1%}", end="", flush=True)
|
|
170
|
+
if show_progress:
|
|
171
|
+
print("\nRendering complete!")
|
|
172
|
+
return True
|
|
173
|
+
except Exception as e:
|
|
174
|
+
logger.error(f"Error during rendering: {e}")
|
|
175
|
+
return False
|
|
176
|
+
finally:
|
|
177
|
+
out.release()
|
|
178
|
+
self.cleanup()
|
|
179
|
+
|
|
180
|
+
def cleanup(self):
|
|
181
|
+
for elem_info in self.timeline.elements:
|
|
182
|
+
if isinstance(elem_info["element"], MediaElement):
|
|
183
|
+
elem_info["element"].cleanup()
|