visualkit 0.1.1__tar.gz → 0.1.4__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.1.1/src/visualkit.egg-info → visualkit-0.1.4}/PKG-INFO +2 -1
- {visualkit-0.1.1 → visualkit-0.1.4}/pyproject.toml +2 -2
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit/__init__.py +1 -1
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit/editor.py +25 -5
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit/media_element.py +101 -0
- {visualkit-0.1.1 → visualkit-0.1.4/src/visualkit.egg-info}/PKG-INFO +2 -1
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit.egg-info/requires.txt +1 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/AUTHORS.rst +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/LICENSE +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/README.md +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/setup.cfg +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit/__main__.py +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit/config.py +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit/enums.py +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit/project_creator.py +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit/text_element.py +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit/timeline.py +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit/transitions.py +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit/utils.py +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit.egg-info/SOURCES.txt +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit.egg-info/dependency_links.txt +0 -0
- {visualkit-0.1.1 → visualkit-0.1.4}/src/visualkit.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: visualkit
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
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
5
|
Author-email: Suraj Airi <surajairi.ml@gmail.com>
|
|
6
6
|
License: MIT license
|
|
@@ -8,6 +8,7 @@ Requires-Python: >=3.9
|
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
License-File: LICENSE
|
|
10
10
|
License-File: AUTHORS.rst
|
|
11
|
+
Requires-Dist: numpy>=2.0.2
|
|
11
12
|
Requires-Dist: opencv-python>=4.12.0.88
|
|
12
13
|
Dynamic: license-file
|
|
13
14
|
|
|
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "visualkit"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.4"
|
|
8
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
9
|
readme = "README.md"
|
|
10
10
|
authors = [{ name = "Suraj Airi", email = "surajairi.ml@gmail.com" }]
|
|
11
11
|
license = { text = "MIT license" }
|
|
12
12
|
requires-python = ">=3.9"
|
|
13
|
-
dependencies = ["opencv-python>=4.12.0.88"]
|
|
13
|
+
dependencies = ["numpy>=2.0.2", "opencv-python>=4.12.0.88"]
|
|
14
14
|
|
|
15
15
|
[dependency-groups]
|
|
16
16
|
dev = ["ruff>=0.12.1"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from .config import VideoConfig
|
|
2
2
|
from .editor import SimpleVideoEditor
|
|
3
3
|
from .enums import AnimationType
|
|
4
|
-
from .media_element import MediaElement
|
|
4
|
+
from .media_element import MediaElement, VideoMediaElement
|
|
5
5
|
from .text_element import SubtitleElement, TextRenderer
|
|
6
6
|
from .transitions import TransitionElement
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
from typing import Any, Dict
|
|
1
|
+
from typing import Any, Dict, Union
|
|
2
2
|
|
|
3
3
|
import cv2
|
|
4
4
|
import numpy as np
|
|
5
5
|
|
|
6
6
|
from visualkit.config import VideoConfig
|
|
7
7
|
from visualkit.enums import AnimationType
|
|
8
|
-
from visualkit.media_element import MediaElement
|
|
8
|
+
from visualkit.media_element import MediaElement, VideoMediaElement
|
|
9
9
|
from visualkit.text_element import SubtitleElement, TextRenderer
|
|
10
10
|
from visualkit.timeline import Timeline
|
|
11
11
|
from visualkit.transitions import TransitionElement
|
|
@@ -13,7 +13,7 @@ from visualkit.utils import logger
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class SimpleVideoEditor:
|
|
16
|
-
def __init__(self, config: VideoConfig
|
|
16
|
+
def __init__(self, config: Union[VideoConfig, None] = None):
|
|
17
17
|
self.config = config or VideoConfig()
|
|
18
18
|
self.text_renderer = TextRenderer(self.config)
|
|
19
19
|
self.timeline = Timeline()
|
|
@@ -41,9 +41,29 @@ class SimpleVideoEditor:
|
|
|
41
41
|
duration = element_data.get("duration", 5.0)
|
|
42
42
|
effect = element_data.get("effect", "none")
|
|
43
43
|
if media_id in assets:
|
|
44
|
-
|
|
44
|
+
asset_info = assets[media_id]
|
|
45
|
+
asset_path = asset_info.get("path")
|
|
46
|
+
asset_kind = asset_info.get("type", "image")
|
|
45
47
|
try:
|
|
46
|
-
|
|
48
|
+
if asset_kind == "video":
|
|
49
|
+
# If duration not explicitly given, derive from clip
|
|
50
|
+
if "duration" not in element_data:
|
|
51
|
+
cap = cv2.VideoCapture(asset_path)
|
|
52
|
+
if cap.isOpened():
|
|
53
|
+
fps_v = cap.get(cv2.CAP_PROP_FPS) or 30.0
|
|
54
|
+
frame_count = (
|
|
55
|
+
cap.get(cv2.CAP_PROP_FRAME_COUNT) or 0
|
|
56
|
+
)
|
|
57
|
+
if fps_v > 0 and frame_count > 0:
|
|
58
|
+
duration = frame_count / fps_v
|
|
59
|
+
cap.release()
|
|
60
|
+
media_element = VideoMediaElement(
|
|
61
|
+
asset_path, duration, effect
|
|
62
|
+
)
|
|
63
|
+
else:
|
|
64
|
+
media_element = MediaElement(
|
|
65
|
+
asset_path, duration, effect
|
|
66
|
+
)
|
|
47
67
|
self.timeline.add_element(
|
|
48
68
|
media_element, current_time, current_time + duration
|
|
49
69
|
)
|
|
@@ -1354,3 +1354,104 @@ class MediaElement:
|
|
|
1354
1354
|
if self._cap is not None:
|
|
1355
1355
|
self._cap.release()
|
|
1356
1356
|
self._cap = None
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
class VideoMediaElement(MediaElement):
|
|
1360
|
+
"""Media element for video clips (separate from still images).
|
|
1361
|
+
|
|
1362
|
+
This subclass decodes video frames on demand according to the local
|
|
1363
|
+
timestamp inside the element's duration. Effects are reused from the
|
|
1364
|
+
parent class.
|
|
1365
|
+
"""
|
|
1366
|
+
|
|
1367
|
+
def __init__(self, asset_path: str, duration: float, effect_type: str = "none"):
|
|
1368
|
+
super().__init__(asset_path, duration, effect_type)
|
|
1369
|
+
self._cap = cv2.VideoCapture(self.asset_path)
|
|
1370
|
+
if not self._cap.isOpened(): # degrade gracefully
|
|
1371
|
+
logger.error(f"Could not open video file: {self.asset_path}")
|
|
1372
|
+
self._video_fps = 0.0
|
|
1373
|
+
self._video_frame_count = 0
|
|
1374
|
+
else:
|
|
1375
|
+
self._video_fps = self._cap.get(cv2.CAP_PROP_FPS) or 30.0
|
|
1376
|
+
self._video_frame_count = int(self._cap.get(cv2.CAP_PROP_FRAME_COUNT) or 0)
|
|
1377
|
+
self._last_video_frame_index = -1
|
|
1378
|
+
|
|
1379
|
+
def get_frame(self, timestamp: float, config: VideoConfig) -> np.ndarray: # type: ignore[override]
|
|
1380
|
+
try:
|
|
1381
|
+
if self._video_fps <= 0 or self._video_frame_count <= 0:
|
|
1382
|
+
# Fallback to black frame
|
|
1383
|
+
return np.zeros((config.height, config.width, 3), dtype=np.uint8)
|
|
1384
|
+
|
|
1385
|
+
# Map local element timestamp to underlying video timeline
|
|
1386
|
+
video_duration = self._video_frame_count / self._video_fps
|
|
1387
|
+
# Use proportional mapping so element duration can trim/extend
|
|
1388
|
+
underlying_time = min(
|
|
1389
|
+
video_duration - 1e-4,
|
|
1390
|
+
(timestamp / self.duration) * video_duration,
|
|
1391
|
+
)
|
|
1392
|
+
target_index = int(underlying_time * self._video_fps)
|
|
1393
|
+
|
|
1394
|
+
if target_index != self._last_video_frame_index + 1:
|
|
1395
|
+
# Seek if not sequential
|
|
1396
|
+
self._cap.set(cv2.CAP_PROP_POS_FRAMES, target_index)
|
|
1397
|
+
|
|
1398
|
+
ret, frame = self._cap.read()
|
|
1399
|
+
if not ret or frame is None:
|
|
1400
|
+
# One retry
|
|
1401
|
+
self._cap.set(cv2.CAP_PROP_POS_FRAMES, target_index)
|
|
1402
|
+
ret, frame = self._cap.read()
|
|
1403
|
+
if not ret or frame is None:
|
|
1404
|
+
return np.zeros((config.height, config.width, 3), dtype=np.uint8)
|
|
1405
|
+
|
|
1406
|
+
self._last_video_frame_index = target_index
|
|
1407
|
+
|
|
1408
|
+
enlarged = self._enlarge_frame(frame, config)
|
|
1409
|
+
|
|
1410
|
+
if (
|
|
1411
|
+
self._last_effect_frame is None
|
|
1412
|
+
or abs(timestamp - self._last_timestamp) > 0.01
|
|
1413
|
+
):
|
|
1414
|
+
effected = self._apply_effect(enlarged.copy(), timestamp, config)
|
|
1415
|
+
self._last_effect_frame = effected
|
|
1416
|
+
self._last_timestamp = timestamp
|
|
1417
|
+
return self._last_effect_frame.copy()
|
|
1418
|
+
except Exception as e: # pragma: no cover - safety net
|
|
1419
|
+
logger.error(f"Video frame error {self.asset_path}: {e}")
|
|
1420
|
+
return np.zeros((config.height, config.width, 3), dtype=np.uint8)
|
|
1421
|
+
|
|
1422
|
+
def _enlarge_frame(self, frame: np.ndarray, config: VideoConfig) -> np.ndarray:
|
|
1423
|
+
"""Create enlarged frame (2.5x target) keeping aspect ratio similar to
|
|
1424
|
+
image implementation.
|
|
1425
|
+
"""
|
|
1426
|
+
target_w, target_h = config.width, config.height
|
|
1427
|
+
enlarged_w = int(target_w * 2.5)
|
|
1428
|
+
enlarged_h = int(target_h * 2.5)
|
|
1429
|
+
try:
|
|
1430
|
+
h, w = frame.shape[:2]
|
|
1431
|
+
aspect_src = w / h
|
|
1432
|
+
aspect_dst = enlarged_w / enlarged_h
|
|
1433
|
+
if aspect_src > aspect_dst:
|
|
1434
|
+
new_h = enlarged_h
|
|
1435
|
+
new_w = int(enlarged_h * aspect_src)
|
|
1436
|
+
else:
|
|
1437
|
+
new_w = enlarged_w
|
|
1438
|
+
new_h = int(enlarged_w / aspect_src)
|
|
1439
|
+
resized = cv2.resize(frame, (new_w, new_h), interpolation=cv2.INTER_AREA)
|
|
1440
|
+
y_off = max(0, (new_h - enlarged_h) // 2)
|
|
1441
|
+
x_off = max(0, (new_w - enlarged_w) // 2)
|
|
1442
|
+
cropped = resized[y_off : y_off + enlarged_h, x_off : x_off + enlarged_w]
|
|
1443
|
+
if cropped.shape[:2] != (enlarged_h, enlarged_w):
|
|
1444
|
+
pad = np.zeros((enlarged_h, enlarged_w, 3), dtype=np.uint8)
|
|
1445
|
+
y_s = (enlarged_h - cropped.shape[0]) // 2
|
|
1446
|
+
x_s = (enlarged_w - cropped.shape[1]) // 2
|
|
1447
|
+
pad[y_s : y_s + cropped.shape[0], x_s : x_s + cropped.shape[1]] = (
|
|
1448
|
+
cropped
|
|
1449
|
+
)
|
|
1450
|
+
return pad
|
|
1451
|
+
return cropped
|
|
1452
|
+
except Exception:
|
|
1453
|
+
return np.zeros((enlarged_h, enlarged_w, 3), dtype=np.uint8)
|
|
1454
|
+
|
|
1455
|
+
def cleanup(self): # type: ignore[override]
|
|
1456
|
+
super().cleanup()
|
|
1457
|
+
# Additional video specific cleanup handled by parent releasing cap
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: visualkit
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
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
5
|
Author-email: Suraj Airi <surajairi.ml@gmail.com>
|
|
6
6
|
License: MIT license
|
|
@@ -8,6 +8,7 @@ Requires-Python: >=3.9
|
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
License-File: LICENSE
|
|
10
10
|
License-File: AUTHORS.rst
|
|
11
|
+
Requires-Dist: numpy>=2.0.2
|
|
11
12
|
Requires-Dist: opencv-python>=4.12.0.88
|
|
12
13
|
Dynamic: license-file
|
|
13
14
|
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|