visualkit 0.0.1__tar.gz → 0.1.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.
Files changed (23) hide show
  1. {visualkit-0.0.1/src/visualkit.egg-info → visualkit-0.1.1}/PKG-INFO +1 -1
  2. {visualkit-0.0.1 → visualkit-0.1.1}/pyproject.toml +4 -11
  3. visualkit-0.1.1/src/visualkit/project_creator.py +144 -0
  4. {visualkit-0.0.1 → visualkit-0.1.1/src/visualkit.egg-info}/PKG-INFO +1 -1
  5. visualkit-0.0.1/src/visualkit/project_creator.py +0 -130
  6. {visualkit-0.0.1 → visualkit-0.1.1}/AUTHORS.rst +0 -0
  7. {visualkit-0.0.1 → visualkit-0.1.1}/LICENSE +0 -0
  8. {visualkit-0.0.1 → visualkit-0.1.1}/README.md +0 -0
  9. {visualkit-0.0.1 → visualkit-0.1.1}/setup.cfg +0 -0
  10. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit/__init__.py +0 -0
  11. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit/__main__.py +0 -0
  12. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit/config.py +0 -0
  13. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit/editor.py +0 -0
  14. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit/enums.py +0 -0
  15. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit/media_element.py +0 -0
  16. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit/text_element.py +0 -0
  17. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit/timeline.py +0 -0
  18. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit/transitions.py +0 -0
  19. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit/utils.py +0 -0
  20. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit.egg-info/SOURCES.txt +0 -0
  21. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit.egg-info/dependency_links.txt +0 -0
  22. {visualkit-0.0.1 → visualkit-0.1.1}/src/visualkit.egg-info/requires.txt +0 -0
  23. {visualkit-0.0.1 → visualkit-0.1.1}/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.0.1
3
+ Version: 0.1.1
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
@@ -4,22 +4,16 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "visualkit"
7
- version = "0.0.1"
7
+ version = "0.1.1"
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
- authors = [
11
- { name = "Suraj Airi", email = "surajairi.ml@gmail.com" }
12
- ]
10
+ authors = [{ name = "Suraj Airi", email = "surajairi.ml@gmail.com" }]
13
11
  license = { text = "MIT license" }
14
12
  requires-python = ">=3.9"
15
- dependencies = [
16
- "opencv-python>=4.12.0.88",
17
- ]
13
+ dependencies = ["opencv-python>=4.12.0.88"]
18
14
 
19
15
  [dependency-groups]
20
- dev = [
21
- "ruff>=0.12.1",
22
- ]
16
+ dev = ["ruff>=0.12.1"]
23
17
 
24
18
 
25
19
  [tool.setuptools.packages.find]
@@ -27,4 +21,3 @@ where = ["src"]
27
21
 
28
22
  [tool.setuptools.package-dir]
29
23
  "" = "src"
30
-
@@ -0,0 +1,144 @@
1
+ import random
2
+ from pathlib import Path
3
+
4
+ from .media_element import MediaElement
5
+ from .transitions import TransitionElement
6
+
7
+
8
+ class ProjectCreator:
9
+ @staticmethod
10
+ def create_project_from_media_and_transcript(
11
+ media: dict,
12
+ transcript: dict,
13
+ media_dir: str = "",
14
+ file_extension: str = "jpg",
15
+ resolution: tuple[int, int] = (720, 1280),
16
+ fps: int = 30,
17
+ codec: str = "mp4v", # Options: avc1, hevc, vp9, mp4v (recommended)
18
+ transition_duration: float = 1.0,
19
+ resize_method: str = "fill", # Options: smart, adaptive, gradual, aspect_ratio
20
+ ):
21
+ """
22
+ Creates a project configuration from media and transcript data.
23
+ Args:
24
+ media (dict): Media assets to include in the project. `media['media']` list of dicts with keys:
25
+ - file_path (str): Path to the media file.
26
+ - start_time (float): Start time of the media in seconds.
27
+ - end_time (float): End time of the media in seconds.
28
+ - type (str): Type of media, e.g., "image" or "video". [optional, default is "image"]
29
+
30
+ transcript (dict): Transcript data for subtitles. `transcript['segments']` list of dicts with keys:
31
+ - start (float): Start time of the subtitle in seconds.
32
+ - end (float): End time of the subtitle in seconds.
33
+ - text (str): Text of the subtitle.
34
+
35
+ media_dir (str): Directory containing media files.
36
+ file_extension (str): File extension for media files. [default: "jpg"]
37
+ resolution (tuple): Video resolution as (width, height).
38
+ fps (int): Frames per second for the video.
39
+ codec (str): Codec to use for video encoding.
40
+ transition_duration (float): Duration of transitions between media elements.
41
+ resize_method (str): Method to use for resizing images. [adaptive (default)] Options: smart, adaptive, gradual, aspect_ratio.
42
+ Returns:
43
+ dict: Project configuration dictionary.
44
+ """ # noqa: E501
45
+
46
+ project = {
47
+ "config": {
48
+ "width": resolution[0],
49
+ "height": resolution[1],
50
+ "fps": fps,
51
+ "codec": codec,
52
+ "resize_method": resize_method,
53
+ },
54
+ "assets": {},
55
+ "main_layer": [],
56
+ "subtitle_layers": [],
57
+ }
58
+ try:
59
+ total_media = len(media["media"])
60
+ # load media assets
61
+ for i, entry in enumerate(media["media"]):
62
+ media_id = f"media_{i + 1:02d}"
63
+ file_path = (
64
+ entry.get("file_path", None) or f"image_{i}.{file_extension}"
65
+ )
66
+ media_path: str = (
67
+ file_path
68
+ if (media_dir is None or media_dir == "")
69
+ else f"{media_dir}/{file_path}"
70
+ )
71
+ media_type = entry.get("type", "image")
72
+ project["assets"][media_id] = {
73
+ "path": str(media_path),
74
+ "type": media_type,
75
+ }
76
+ # if not first index, add a transition
77
+ duration = float(entry["end_time"]) - float(entry["start_time"])
78
+ taken = False
79
+
80
+ if i > 0 and duration > 1:
81
+ project["main_layer"].append(
82
+ {
83
+ "type": "transition",
84
+ "duration": transition_duration,
85
+ "transition_type": random.choice(
86
+ TransitionElement.get_available_transitions()
87
+ ),
88
+ }
89
+ )
90
+ taken = True
91
+
92
+ # calculate transition overlapping duration for media element
93
+ sub_duration = 0
94
+ if not taken or total_media == 1: # Only one media element
95
+ sub_duration = 0
96
+ elif i == 0 or i == total_media - 1: # first or last media
97
+ sub_duration = transition_duration / 2
98
+ else: # middle media
99
+ sub_duration = transition_duration
100
+
101
+ if media_type == "image":
102
+ project["main_layer"].append(
103
+ {
104
+ "type": "media",
105
+ "media": media_id,
106
+ "duration": round(duration - sub_duration, 3),
107
+ "effect": entry.get(
108
+ "effect",
109
+ random.choice(MediaElement.get_moving_effects()),
110
+ ),
111
+ }
112
+ )
113
+ elif media_type == "video":
114
+ # todo: handle video asset properly
115
+ project["main_layer"].append(
116
+ {
117
+ "type": "media",
118
+ "media": media_id,
119
+ "duration": entry.get("duration", 5.0),
120
+ }
121
+ )
122
+
123
+ # transcript elements for subtitle layers
124
+ subtitle_layer = {
125
+ "name": "main_subtitles",
126
+ "elements": [],
127
+ }
128
+
129
+ for seg in transcript["sentences"]:
130
+ subtitle_layer["elements"].append(
131
+ {
132
+ "start_time": seg["start"],
133
+ "end_time": seg["end"],
134
+ "text": seg["text"],
135
+ "animation_type": "typewriter",
136
+ }
137
+ )
138
+
139
+ project["subtitle_layers"].append(subtitle_layer)
140
+
141
+ return project
142
+ except Exception as e:
143
+ print(f"Error creating project: {e}")
144
+ raise ValueError("Failed to create project") from e
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: visualkit
3
- Version: 0.0.1
3
+ Version: 0.1.1
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
@@ -1,130 +0,0 @@
1
- import random
2
- from pathlib import Path
3
-
4
- from visualkit.media_element import MediaElement
5
- from visualkit.transitions import TransitionElement
6
-
7
-
8
- class ProjectCreator:
9
- @staticmethod
10
- def create_project_from_media_and_transcript(
11
- media: dict,
12
- transcript: dict,
13
- media_dir: str = "",
14
- resolution: tuple[int, int] = (720, 1280),
15
- fps: int = 30,
16
- codec: str = "mp4v",
17
- transition_duration: float = 1.0,
18
- resize_method: str = "adaptive", # Options: smart, adaptive, gradual, aspect_ratio
19
- ):
20
- """
21
- Creates a project configuration from media and transcript data.
22
- Args:
23
- media (dict): Media assets to include in the project. `media['media']` list of dicts with keys:
24
- - file_path (str): Path to the media file.
25
- - start_time (float): Start time of the media in seconds.
26
- - end_time (float): End time of the media in seconds.
27
- - type (str): Type of media, e.g., "image" or "video". [optional, default is "image"]
28
-
29
- transcript (dict): Transcript data for subtitles. `transcript['segments']` list of dicts with keys:
30
- - start (float): Start time of the subtitle in seconds.
31
- - end (float): End time of the subtitle in seconds.
32
- - text (str): Text of the subtitle.
33
-
34
- media_dir (str): Directory containing media files.
35
- resolution (tuple): Video resolution as (width, height).
36
- fps (int): Frames per second for the video.
37
- codec (str): Codec to use for video encoding.
38
- transition_duration (float): Duration of transitions between media elements.
39
- resize_method (str): Method to use for resizing images. [adaptive (default)] Options: smart, adaptive, gradual, aspect_ratio.
40
- Returns:
41
- dict: Project configuration dictionary.
42
- """ # noqa: E501
43
-
44
- project = {
45
- "config": {
46
- "width": resolution[0],
47
- "height": resolution[1],
48
- "fps": fps,
49
- "codec": codec,
50
- "resize_method": resize_method,
51
- },
52
- "assets": {},
53
- "main_layer": [],
54
- "subtitle_layers": [],
55
- }
56
- total_media = len(media["media"])
57
- # load media assets
58
- for i, entry in enumerate(media["media"]):
59
- media_id = f"media_{i + 1:02d}"
60
- media_path: Path = Path(media_dir) / entry["file_path"]
61
- media_type = entry.get("type", "image")
62
- project["assets"][media_id] = {
63
- "path": str(media_path),
64
- "type": media_type,
65
- }
66
- # if not first index, add a transition
67
- duration = float(entry["end_time"]) - float(entry["start_time"])
68
- taken = False
69
-
70
- if i > 0 and duration > 1:
71
- project["main_layer"].append(
72
- {
73
- "type": "transition",
74
- "duration": transition_duration,
75
- "transition_type": random.choice(
76
- TransitionElement.get_available_transitions()
77
- ),
78
- }
79
- )
80
- taken = True
81
-
82
- # calculate transition overlapping duration for media element
83
- sub_duration = 0
84
- if not taken or total_media == 1: # Only one media element
85
- sub_duration = 0
86
- elif i == 0 or i == total_media - 1: # first or last media
87
- sub_duration = transition_duration / 2
88
- else: # middle media
89
- sub_duration = transition_duration
90
-
91
- if media_type == "image":
92
- project["main_layer"].append(
93
- {
94
- "type": "media",
95
- "media": media_id,
96
- "duration": round(duration - sub_duration, 3),
97
- "effect": entry.get(
98
- "effect", random.choice(MediaElement.get_moving_effects())
99
- ),
100
- }
101
- )
102
- elif media_type == "video":
103
- # todo: handle video asset properly
104
- project["main_layer"].append(
105
- {
106
- "type": "media",
107
- "media": media_id,
108
- "duration": entry.get("duration", 5.0),
109
- }
110
- )
111
-
112
- # transcript elements for subtitle layers
113
- subtitle_layer = {
114
- "name": "main_subtitles",
115
- "elements": [],
116
- }
117
-
118
- for seg in transcript["segments"]:
119
- subtitle_layer["elements"].append(
120
- {
121
- "start_time": seg["start"],
122
- "end_time": seg["end"],
123
- "text": seg["text"],
124
- "animation_type": "typewriter",
125
- }
126
- )
127
-
128
- project["subtitle_layers"].append(subtitle_layer)
129
-
130
- return project
File without changes
File without changes
File without changes
File without changes