videopython 0.1.41__py3-none-any.whl → 0.2.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.

Potentially problematic release.


This version of videopython might be problematic. Click here for more details.

@@ -53,22 +53,22 @@ class TransformationPipeline:
53
53
 
54
54
 
55
55
  class CutFrames(Transformation):
56
- def __init__(self, start_frame: int, end_frame: int):
57
- self.start_frame = start_frame
58
- self.end_frame = end_frame
56
+ def __init__(self, start: int, end: int):
57
+ self.start = start
58
+ self.end = end
59
59
 
60
60
  def apply(self, video: Video) -> Video:
61
- video = video[self.start_frame : self.end_frame]
61
+ video = video[self.start : self.end]
62
62
  return video
63
63
 
64
64
 
65
65
  class CutSeconds(Transformation):
66
- def __init__(self, start_second: float | int, end_second: float | int):
67
- self.start_second = start_second
68
- self.end_second = end_second
66
+ def __init__(self, start: float | int, end: float | int):
67
+ self.start = start
68
+ self.end = end
69
69
 
70
70
  def apply(self, video: Video) -> Video:
71
- video = video[round(self.start_second * video.fps) : round(self.end_second * video.fps)]
71
+ video = video[round(self.start * video.fps) : round(self.end * video.fps)]
72
72
  return video
73
73
 
74
74
 
@@ -112,18 +112,18 @@ class Resize(Transformation):
112
112
 
113
113
 
114
114
  class ResampleFPS(Transformation):
115
- def __init__(self, new_fps: int | float):
116
- self.new_fps = float(new_fps)
115
+ def __init__(self, fps: int | float):
116
+ self.fps = float(fps)
117
117
 
118
118
  def _downsample(self, video: Video) -> Video:
119
- target_frame_count = int(len(video.frames) * (self.new_fps / video.fps))
119
+ target_frame_count = int(len(video.frames) * (self.fps / video.fps))
120
120
  new_frame_indices = np.round(np.linspace(0, len(video.frames) - 1, target_frame_count)).astype(int)
121
121
  video.frames = video.frames[new_frame_indices]
122
- video.fps = self.new_fps
122
+ video.fps = self.fps
123
123
  return video
124
124
 
125
125
  def _upsample(self, video: Video) -> Video:
126
- target_frame_count = int(len(video.frames) * (self.new_fps / video.fps))
126
+ target_frame_count = int(len(video.frames) * (self.fps / video.fps))
127
127
  new_frame_indices = np.linspace(0, len(video.frames) - 1, target_frame_count)
128
128
  new_frames = []
129
129
  for i in tqdm(range(len(new_frame_indices) - 1)):
@@ -134,17 +134,17 @@ class ResampleFPS(Transformation):
134
134
  ]
135
135
  new_frames.append(new_frame.astype(np.uint8))
136
136
  video.frames = np.array(new_frames, dtype=np.uint8)
137
- video.fps = self.new_fps
137
+ video.fps = self.fps
138
138
  return video
139
139
 
140
140
  def apply(self, video: Video) -> Video:
141
- if video.fps == self.new_fps:
141
+ if video.fps == self.fps:
142
142
  return video
143
- elif video.fps > self.new_fps:
144
- print(f"Downsampling video from {video.fps} to {self.new_fps} FPS.")
143
+ elif video.fps > self.fps:
144
+ print(f"Downsampling video from {video.fps} to {self.fps} FPS.")
145
145
  video = self._downsample(video)
146
146
  else:
147
- print(f"Upsampling video from {video.fps} to {self.new_fps} FPS.")
147
+ print(f"Upsampling video from {video.fps} to {self.fps} FPS.")
148
148
  video = self._upsample(video)
149
149
  return video
150
150
 
@@ -0,0 +1,32 @@
1
+ import cv2
2
+ import numpy as np
3
+ from PIL import Image
4
+
5
+ from videopython.base.transforms import Resize
6
+ from videopython.generation import ImageToVideo, TextToImage
7
+
8
+ N_ITERATIONS = 11
9
+ PRMOPT = "Sunset at the sea, cimenatic view"
10
+
11
+
12
+ def main():
13
+ text_to_image = TextToImage()
14
+ image_to_video = ImageToVideo()
15
+
16
+ target_height = 576
17
+ target_width = 1024
18
+
19
+ base_image = text_to_image.generate_image(PRMOPT)
20
+ image = cv2.resize(np.asarray(base_image), (target_width, target_height))
21
+
22
+ video = image_to_video.generate_video(image)
23
+
24
+ for i in range(N_ITERATIONS - 1):
25
+ print(f"Generating {i+2}/{N_ITERATIONS}...")
26
+ video += image_to_video.generate_video(Image.fromarray(video.frames[-1]))
27
+
28
+ video.save()
29
+
30
+
31
+ if __name__ == "__main__":
32
+ main()
@@ -6,7 +6,7 @@ from PIL.Image import Image
6
6
  from videopython.base.video import Video
7
7
 
8
8
  TEXT_TO_VIDEO_MODEL = "cerspense/zeroscope_v2_576w"
9
- IMAGE_TO_VIDEO_MODEL = "stabilityai/stable-video-diffusion-img2vid-xt"
9
+ IMAGE_TO_VIDEO_MODEL = "stabilityai/stable-video-diffusion-img2vid-xt-1-1"
10
10
 
11
11
 
12
12
  class TextToVideo:
@@ -247,7 +247,7 @@ class SlideOverImage:
247
247
  self.fps = fps
248
248
  self.length_seconds = length_seconds
249
249
 
250
- def slide(self, image: np.ndarray) -> Video:
250
+ def apply(self, image: np.ndarray) -> Video:
251
251
  image = self._resize(image)
252
252
  max_offset = image.shape[1] - self.video_width
253
253
  frame_count = round(self.fps * self.length_seconds)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: videopython
3
- Version: 0.1.41
3
+ Version: 0.2.0
4
4
  Summary: Minimal video generation and processing library.
5
5
  Author-email: Bartosz Wójtowicz <bartoszwojtowicz@outlook.com>, Bartosz Rudnikowicz <bartoszrudnikowicz840@gmail.com>, Piotr Pukisz <piotr.pukisz@gmail.com>
6
6
  License: Apache License
@@ -250,8 +250,41 @@ pip install videopython[generation]
250
250
  > The funcionalities found in `videopython.generation` won't work.
251
251
 
252
252
  ## Basic Usage
253
- > Using Nvidia A40 or better is recommended for the `videopython.generation` module.
254
253
 
254
+ ### Video handling
255
+
256
+ ```python
257
+ from videopython.base.video import Video
258
+
259
+ # Load videos and print metadata
260
+ video1 = Video.from_path("tests/test_data/fast_benchmark.mp4")
261
+ print(video1)
262
+
263
+ video2 = Video.from_path("tests/test_data/slow_benchmark.mp4")
264
+ print(video2)
265
+
266
+ # Define the transformations
267
+ from videopython.base.transforms import CutSeconds, ResampleFPS, Resize, TransformationPipeline
268
+
269
+ pipeline = TransformationPipeline(
270
+ [CutSeconds(start=1.5, end=6.5), ResampleFPS(fps=30), Resize(width=1000, height=1000)]
271
+ )
272
+ video1 = pipeline.run(video1)
273
+ video2 = pipeline.run(video2)
274
+
275
+ # Combine videos, add audio and save
276
+ from videopython.base.transitions import FadeTransition
277
+
278
+ fade = FadeTransition(effect_time_seconds=3.0)
279
+ video = fade.apply(videos=(video1, video2))
280
+ video.add_audio_from_file("tests/test_data/test_audio.mp3")
281
+
282
+ savepath = video.save()
283
+ ```
284
+
285
+ ### Video Generation
286
+
287
+ > Using Nvidia A40 or better is recommended for the `videopython.generation` module.
255
288
  ```python
256
289
  # Generate image and animate it
257
290
  from videopython.generation import ImageToVideo
@@ -2,18 +2,19 @@ videopython/base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
2
2
  videopython/base/compose.py,sha256=pti12VY3Yg7TZZiENPF6veM8POWssfsK8ePDdGlhAhA,1968
3
3
  videopython/base/effects.py,sha256=ZFUWrgVWTn4uWpxPfTQSQQKEZN5ns4btMofOZNHCeQc,7540
4
4
  videopython/base/exceptions.py,sha256=68_16lUPOR9_zhWdeBGS8_NFI32VbrcoDbN5KHHg0_w,44
5
- videopython/base/transforms.py,sha256=yDtM1uZOacB0OLPQnSGHl5upoNNeN0dPWXe0hJPeV-I,6004
5
+ videopython/base/transforms.py,sha256=VP8SGArokfXN-IE7tk-3i0oMM3HV5zpJa-GLj7BoeRo,5856
6
6
  videopython/base/transitions.py,sha256=zYsxIgiVfN9P-CoGWUWRYFBr_0inX1sAJ02gyIEQ678,3694
7
7
  videopython/base/video.py,sha256=kG-juKN-da5NzV89YxZl5JkyMTJFkgPceh4yuAUnsQs,11099
8
8
  videopython/generation/__init__.py,sha256=Qse024UgiS9OxXzbbInyZ-9cpfI4enR2Dcds4lLDpNA,201
9
9
  videopython/generation/audio.py,sha256=BTc-3vJ5e6D0lt2OPo2hfOcUqhNXIcvRLNoo2oQ470M,777
10
10
  videopython/generation/image.py,sha256=i8zJm0WXn_Pykby9Urw1kzDcla6ArYhRgG-ueRdoAJ0,675
11
- videopython/generation/video.py,sha256=WMFKKUSfIkQmxL6xhUb-MeAiHU6uOF_oFpmf69H8V8g,1827
11
+ videopython/generation/pipeline.py,sha256=v8GHkGNLErnQBjzNA8oem7fRv7YOx_NdduEC47kQkf0,773
12
+ videopython/generation/video.py,sha256=206YON_XjPTYyjIJ3j5uBgd_yHmCDg7SqbkIU9GzEgw,1831
12
13
  videopython/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
14
  videopython/utils/common.py,sha256=F-30YoKUwWDI7HiJUWw0gRFUguhShSVaxT0aFfvpifg,936
14
- videopython/utils/image.py,sha256=8m1uzyfrj5Kdbw7IZyqwj-6NXK4KH-szJxtN_EQva4s,12084
15
- videopython-0.1.41.dist-info/LICENSE,sha256=nJL9jVOt2MSW7swNDq4Y6oD_n9bLI0B0afr8ougtZ6s,10832
16
- videopython-0.1.41.dist-info/METADATA,sha256=Hu511G-WnKEwOn9gG_53ywH1NDAH2pA5d_LzFUuYmfM,15659
17
- videopython-0.1.41.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
18
- videopython-0.1.41.dist-info/top_level.txt,sha256=OikTGG8Swfw_syz--1atAn5KQ4GH9Pye17eATGred-Q,12
19
- videopython-0.1.41.dist-info/RECORD,,
15
+ videopython/utils/image.py,sha256=gng1by8ieYRVs1DlxHPMqYIPxKc1WWwBm8W5oASBKfY,12084
16
+ videopython-0.2.0.dist-info/LICENSE,sha256=nJL9jVOt2MSW7swNDq4Y6oD_n9bLI0B0afr8ougtZ6s,10832
17
+ videopython-0.2.0.dist-info/METADATA,sha256=W8FecvXP3eT7BSeUNjDKiykVPIrcwXsademTs9gl3MU,16531
18
+ videopython-0.2.0.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
19
+ videopython-0.2.0.dist-info/top_level.txt,sha256=OikTGG8Swfw_syz--1atAn5KQ4GH9Pye17eATGred-Q,12
20
+ videopython-0.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (70.1.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5