ZTWHHH commited on
Commit
9062d81
·
verified ·
1 Parent(s): d4c6bac

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. videollama2/lib/python3.10/site-packages/moviepy/video/__pycache__/VideoClip.cpython-310.pyc +0 -0
  3. videollama2/lib/python3.10/site-packages/moviepy/video/__pycache__/__init__.cpython-310.pyc +0 -0
  4. videollama2/lib/python3.10/site-packages/moviepy/video/compositing/__pycache__/__init__.cpython-310.pyc +0 -0
  5. videollama2/lib/python3.10/site-packages/moviepy/video/compositing/__pycache__/on_color.cpython-310.pyc +0 -0
  6. videollama2/lib/python3.10/site-packages/moviepy/video/compositing/__pycache__/positioning.cpython-310.pyc +0 -0
  7. videollama2/lib/python3.10/site-packages/moviepy/video/compositing/__pycache__/transitions.cpython-310.pyc +0 -0
  8. videollama2/lib/python3.10/site-packages/moviepy/video/compositing/on_color.py +27 -0
  9. videollama2/lib/python3.10/site-packages/moviepy/video/compositing/positioning.py +5 -0
  10. videollama2/lib/python3.10/site-packages/moviepy/video/fx/__init__.py +4 -0
  11. videollama2/lib/python3.10/site-packages/moviepy/video/fx/__pycache__/freeze.cpython-310.pyc +0 -0
  12. videollama2/lib/python3.10/site-packages/moviepy/video/fx/__pycache__/headblur.cpython-310.pyc +0 -0
  13. videollama2/lib/python3.10/site-packages/moviepy/video/fx/__pycache__/painting.cpython-310.pyc +0 -0
  14. videollama2/lib/python3.10/site-packages/moviepy/video/fx/__pycache__/scroll.cpython-310.pyc +0 -0
  15. videollama2/lib/python3.10/site-packages/moviepy/video/fx/accel_decel.py +44 -0
  16. videollama2/lib/python3.10/site-packages/moviepy/video/fx/blackwhite.py +22 -0
  17. videollama2/lib/python3.10/site-packages/moviepy/video/fx/blink.py +15 -0
  18. videollama2/lib/python3.10/site-packages/moviepy/video/fx/colorx.py +10 -0
  19. videollama2/lib/python3.10/site-packages/moviepy/video/fx/crop.py +53 -0
  20. videollama2/lib/python3.10/site-packages/moviepy/video/fx/even_size.py +22 -0
  21. videollama2/lib/python3.10/site-packages/moviepy/video/fx/fadein.py +25 -0
  22. videollama2/lib/python3.10/site-packages/moviepy/video/fx/fadeout.py +28 -0
  23. videollama2/lib/python3.10/site-packages/moviepy/video/fx/gamma_corr.py +8 -0
  24. videollama2/lib/python3.10/site-packages/moviepy/video/fx/headblur.py +58 -0
  25. videollama2/lib/python3.10/site-packages/moviepy/video/fx/invert_colors.py +8 -0
  26. videollama2/lib/python3.10/site-packages/moviepy/video/fx/loop.py +26 -0
  27. videollama2/lib/python3.10/site-packages/moviepy/video/fx/lum_contrast.py +11 -0
  28. videollama2/lib/python3.10/site-packages/moviepy/video/fx/make_loopable.py +14 -0
  29. videollama2/lib/python3.10/site-packages/moviepy/video/fx/margin.py +58 -0
  30. videollama2/lib/python3.10/site-packages/moviepy/video/fx/mask_and.py +20 -0
  31. videollama2/lib/python3.10/site-packages/moviepy/video/fx/mask_or.py +20 -0
  32. videollama2/lib/python3.10/site-packages/moviepy/video/fx/mirror_x.py +4 -0
  33. videollama2/lib/python3.10/site-packages/moviepy/video/fx/mirror_y.py +3 -0
  34. videollama2/lib/python3.10/site-packages/moviepy/video/fx/painting.py +43 -0
  35. videollama2/lib/python3.10/site-packages/moviepy/video/fx/rotate.py +73 -0
  36. videollama2/lib/python3.10/site-packages/moviepy/video/fx/scroll.py +16 -0
  37. videollama2/lib/python3.10/site-packages/moviepy/video/fx/speedx.py +21 -0
  38. videollama2/lib/python3.10/site-packages/moviepy/video/fx/supersample.py +13 -0
  39. videollama2/lib/python3.10/site-packages/moviepy/video/fx/time_symmetrize.py +17 -0
  40. videollama2/lib/python3.10/site-packages/moviepy/video/io/VideoFileClip.py +134 -0
  41. videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/ImageSequenceClip.cpython-310.pyc +0 -0
  42. videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/__init__.cpython-310.pyc +0 -0
  43. videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/bindings.cpython-310.pyc +0 -0
  44. videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/ffmpeg_reader.cpython-310.pyc +0 -0
  45. videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/gif_writers.cpython-310.pyc +0 -0
  46. videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/html_tools.cpython-310.pyc +0 -0
  47. videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/preview.cpython-310.pyc +0 -0
  48. videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/sliders.cpython-310.pyc +0 -0
  49. videollama2/lib/python3.10/site-packages/moviepy/video/io/bindings.py +32 -0
  50. videollama2/lib/python3.10/site-packages/moviepy/video/io/ffmpeg_reader.py +393 -0
.gitattributes CHANGED
@@ -1825,3 +1825,4 @@ parrot/lib/python3.10/site-packages/opencv_python.libs/libavutil-a0a0531e.so.57.
1825
  parrot/lib/python3.10/site-packages/scipy/ndimage/_nd_image.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1826
  parrot/lib/python3.10/site-packages/scipy/interpolate/_ppoly.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1827
  parrot/lib/python3.10/site-packages/scipy/optimize/_trlib/_trlib.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
1825
  parrot/lib/python3.10/site-packages/scipy/ndimage/_nd_image.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1826
  parrot/lib/python3.10/site-packages/scipy/interpolate/_ppoly.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1827
  parrot/lib/python3.10/site-packages/scipy/optimize/_trlib/_trlib.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1828
+ videollama2/lib/python3.10/site-packages/pip/_vendor/idna/__pycache__/idnadata.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
videollama2/lib/python3.10/site-packages/moviepy/video/__pycache__/VideoClip.cpython-310.pyc ADDED
Binary file (36 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (170 Bytes). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/compositing/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (182 Bytes). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/compositing/__pycache__/on_color.cpython-310.pyc ADDED
Binary file (1.16 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/compositing/__pycache__/positioning.cpython-310.pyc ADDED
Binary file (254 Bytes). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/compositing/__pycache__/transitions.cpython-310.pyc ADDED
Binary file (4.62 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/compositing/on_color.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
2
+ from moviepy.video.VideoClip import ColorClip
3
+
4
+
5
+ def on_color(clip, size=None, color=(0, 0, 0), pos=None, col_opacity=None):
6
+ """
7
+ Returns a clip made of the current clip overlaid on a color
8
+ clip of a possibly bigger size. Can serve to flatten transparent
9
+ clips (ideal for previewing clips with masks).
10
+
11
+ :param size: size of the final clip. By default it will be the
12
+ size of the current clip.
13
+ :param bg_color: the background color of the final clip
14
+ :param pos: the position of the clip in the final clip.
15
+ :param col_opacity: should the added zones be transparent ?
16
+ """
17
+
18
+ if size is None:
19
+ size = clip.size
20
+ if pos is None:
21
+ pos = 'center'
22
+ colorclip = ColorClip(size, color=color)
23
+ if col_opacity:
24
+ colorclip = colorclip.with_mask().set_opacity(col_opacity)
25
+
26
+ return CompositeVideoClip([colorclip, clip.set_position(pos)],
27
+ transparent=(col_opacity is not None))
videollama2/lib/python3.10/site-packages/moviepy/video/compositing/positioning.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ """
2
+ This module provides classes that make positioning easy
3
+ """
4
+
5
+ # class ClipPosition:
videollama2/lib/python3.10/site-packages/moviepy/video/fx/__init__.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ """
2
+ This module contains transformation functions (clip->clip)
3
+ One file for one fx. The file's name is the fx's name
4
+ """
videollama2/lib/python3.10/site-packages/moviepy/video/fx/__pycache__/freeze.cpython-310.pyc ADDED
Binary file (1.21 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/fx/__pycache__/headblur.cpython-310.pyc ADDED
Binary file (1.7 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/fx/__pycache__/painting.cpython-310.pyc ADDED
Binary file (1.46 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/fx/__pycache__/scroll.cpython-310.pyc ADDED
Binary file (845 Bytes). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/fx/accel_decel.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def f_accel_decel(t, old_d, new_d, abruptness=1, soonness=1.0):
2
+ """
3
+ abruptness
4
+ negative abruptness (>-1): speed up down up
5
+ zero abruptness : no effect
6
+ positive abruptness: speed down up down
7
+
8
+ soonness
9
+ for positive abruptness, determines how soon the
10
+ speedup occurs (0<soonness < inf)
11
+ """
12
+
13
+ a = 1.0+abruptness
14
+ def _f(t):
15
+ f1 = lambda t: (0.5)**(1-a)*(t**a)
16
+ f2 = lambda t: (1-f1(1-t))
17
+ return (t<.5)*f1(t) + (t>=.5)*f2(t)
18
+
19
+ return old_d*_f((t/new_d)**soonness)
20
+
21
+
22
+ def accel_decel(clip, new_duration=None, abruptness=1.0, soonness=1.0):
23
+ """
24
+
25
+ new_duration
26
+ If None, will be that of the current clip.
27
+
28
+ abruptness
29
+ negative abruptness (>-1): speed up down up
30
+ zero abruptness : no effect
31
+ positive abruptness: speed down up down
32
+
33
+ soonness
34
+ for positive abruptness, determines how soon the
35
+ speedup occurs (0<soonness < inf)
36
+ """
37
+
38
+ if new_duration is None:
39
+ new_duration = clip.duration
40
+
41
+ fl = lambda t : f_accel_decel(t, clip.duration, new_duration,
42
+ abruptness, soonness)
43
+
44
+ return clip.fl_time(fl).set_duration(new_duration)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/blackwhite.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+
4
+ def blackwhite(clip, RGB = None, preserve_luminosity=True):
5
+ """ Desaturates the picture, makes it black and white.
6
+ Parameter RGB allows to set weights for the different color
7
+ channels.
8
+ If RBG is 'CRT_phosphor' a special set of values is used.
9
+ preserve_luminosity maintains the sum of RGB to 1."""
10
+ if RGB is None:
11
+ RGB = [1,1,1]
12
+
13
+ if RGB == 'CRT_phosphor':
14
+ RGB = [0.2125, 0.7154, 0.0721]
15
+
16
+ R,G,B = 1.0*np.array(RGB)/ (sum(RGB) if preserve_luminosity else 1)
17
+
18
+ def fl(im):
19
+ im = (R*im[:,:,0] + G*im[:,:,1] + B*im[:,:,2])
20
+ return np.dstack(3*[im]).astype('uint8')
21
+
22
+ return clip.fl_image(fl)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/blink.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import copy
2
+
3
+
4
+ def blink(clip, d_on, d_off):
5
+ """
6
+ Makes the clip blink. At each blink it will be displayed ``d_on``
7
+ seconds and disappear ``d_off`` seconds. Will only work in
8
+ composite clips.
9
+ """
10
+ newclip = copy.copy(clip)
11
+ if newclip.mask is None:
12
+ newclip = newclip.with_mask()
13
+ D = d_on + d_off
14
+ newclip.mask = newclip.mask.fl( lambda gf,t: gf(t)*((t % D) < d_on))
15
+ return newclip
videollama2/lib/python3.10/site-packages/moviepy/video/fx/colorx.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+
4
+ def colorx(clip, factor):
5
+ """ multiplies the clip's colors by the given factor, can be used
6
+ to decrease or increase the clip's brightness (is that the
7
+ reight word ?)
8
+ """
9
+ return clip.fl_image( lambda pic: np.minimum(255,(factor*pic)).
10
+ astype('uint8'))
videollama2/lib/python3.10/site-packages/moviepy/video/fx/crop.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def crop(clip, x1=None, y1=None, x2=None, y2=None, width=None, height=None, x_center=None, y_center=None):
2
+ """
3
+ Returns a new clip in which just a rectangular subregion of the
4
+ original clip is conserved. x1,y1 indicates the top left corner and
5
+ x2,y2 is the lower right corner of the croped region.
6
+ All coordinates are in pixels. Float numbers are accepted.
7
+
8
+ To crop an arbitrary rectangle:
9
+
10
+ >>> crop(clip, x1=50, y1=60, x2=460, y2=275)
11
+
12
+ Only remove the part above y=30:
13
+
14
+ >>> crop(clip, y1=30)
15
+
16
+ Crop a rectangle that starts 10 pixels left and is 200px wide
17
+
18
+ >>> crop(clip, x1=10, width=200)
19
+
20
+ Crop a rectangle centered in x,y=(300,400), width=50, height=150 :
21
+
22
+ >>> crop(clip, x_center=300 , y_center=400,
23
+ width=50, height=150)
24
+
25
+ Any combination of the above should work, like for this rectangle
26
+ centered in x=300, with explicit y-boundaries:
27
+
28
+ >>> crop(x_center=300, width=400, y1=100, y2=600)
29
+
30
+ """
31
+
32
+ if width and x1 is not None:
33
+ x2 = x1 + width
34
+ elif width and x2 is not None:
35
+ x1 = x2 - width
36
+
37
+ if height and y1 is not None:
38
+ y2 = y1 + height
39
+ elif height and y2 is not None:
40
+ y1 = y2 - height
41
+
42
+ if x_center:
43
+ x1, x2 = x_center - width / 2, x_center + width / 2
44
+
45
+ if y_center:
46
+ y1, y2 = y_center - height / 2, y_center + height / 2
47
+
48
+ x1 = x1 or 0
49
+ y1 = y1 or 0
50
+ x2 = x2 or clip.size[0]
51
+ y2 = y2 or clip.size[1]
52
+
53
+ return clip.fl_image(lambda pic: pic[int(y1) : int(y2), int(x1) : int(x2)], apply_to=["mask"])
videollama2/lib/python3.10/site-packages/moviepy/video/fx/even_size.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from moviepy.decorators import apply_to_mask
2
+
3
+
4
+ @apply_to_mask
5
+ def even_size(clip):
6
+ """
7
+ Crops the clip to make dimensions even.
8
+ """
9
+ w, h = clip.size
10
+ w_even = w % 2 == 0
11
+ h_even = h % 2 == 0
12
+ if w_even and h_even:
13
+ return clip
14
+
15
+ if not w_even and not h_even:
16
+ fl_image = lambda a : a[:-1,:-1,:]
17
+ elif w_even:
18
+ fl_image = lambda a : a[:,:-1,:]
19
+ else:
20
+ fl_image = lambda a : a[:-1,:,:]
21
+
22
+ return clip.fl_image(fl_image)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/fadein.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+
4
+ def fadein(clip, duration, initial_color=None):
5
+ """
6
+ Makes the clip progressively appear from some color (black by default),
7
+ over ``duration`` seconds at the beginning of the clip. Can be used for
8
+ masks too, where the initial color must be a number between 0 and 1.
9
+ For cross-fading (progressive appearance or disappearance of a clip
10
+ over another clip, see ``composition.crossfade``
11
+ """
12
+
13
+ if initial_color is None:
14
+ initial_color = 0 if clip.ismask else [0,0,0]
15
+
16
+ initial_color = np.array(initial_color)
17
+
18
+ def fl(gf, t):
19
+ if t>=duration:
20
+ return gf(t)
21
+ else:
22
+ fading = (1.0*t/duration)
23
+ return fading*gf(t) + (1-fading)*initial_color
24
+
25
+ return clip.fl(fl)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/fadeout.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from moviepy.decorators import requires_duration
4
+
5
+
6
+ @requires_duration
7
+ def fadeout(clip, duration, final_color=None):
8
+ """
9
+ Makes the clip progressively fade to some color (black by default),
10
+ over ``duration`` seconds at the end of the clip. Can be used for
11
+ masks too, where the final color must be a number between 0 and 1.
12
+ For cross-fading (progressive appearance or disappearance of a clip
13
+ over another clip, see ``composition.crossfade``
14
+ """
15
+
16
+ if final_color is None:
17
+ final_color = 0 if clip.ismask else [0,0,0]
18
+
19
+ final_color = np.array(final_color)
20
+
21
+ def fl(gf, t):
22
+ if (clip.duration-t)>=duration:
23
+ return gf(t)
24
+ else:
25
+ fading = 1.0 * (clip.duration - t) / duration
26
+ return fading*gf(t) + (1-fading)*final_color
27
+
28
+ return clip.fl(fl)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/gamma_corr.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+
2
+ def gamma_corr(clip, gamma):
3
+ """ Gamma-correction of a video clip """
4
+ def fl(im):
5
+ corrected = (255*(1.0*im/255)**gamma)
6
+ return corrected.astype('uint8')
7
+
8
+ return clip.fl_image(fl)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/headblur.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ #------- CHECKING DEPENDENCIES -----------------------------------------
4
+ try:
5
+ import cv2
6
+ headblur_possible = True
7
+ if cv2.__version__ >= '3.0.0':
8
+ cv2.CV_AA=cv2.LINE_AA
9
+ except:
10
+ headblur_possible = False
11
+ #-----------------------------------------------------------------------
12
+
13
+
14
+ def headblur(clip,fx,fy,r_zone,r_blur=None):
15
+ """
16
+ Returns a filter that will blurr a moving part (a head ?) of
17
+ the frames. The position of the blur at time t is
18
+ defined by (fx(t), fy(t)), the radius of the blurring
19
+ by ``r_zone`` and the intensity of the blurring by ``r_blur``.
20
+ Requires OpenCV for the circling and the blurring.
21
+ Automatically deals with the case where part of the image goes
22
+ offscreen.
23
+ """
24
+
25
+ if r_blur is None: r_blur = 2*r_zone/3
26
+
27
+ def fl(gf,t):
28
+
29
+ im = gf(t)
30
+ h,w,d = im.shape
31
+ x,y = int(fx(t)),int(fy(t))
32
+ x1,x2 = max(0,x-r_zone),min(x+r_zone,w)
33
+ y1,y2 = max(0,y-r_zone),min(y+r_zone,h)
34
+ region_size = y2-y1,x2-x1
35
+
36
+ mask = np.zeros(region_size).astype('uint8')
37
+ cv2.circle(mask, (r_zone,r_zone), r_zone, 255, -1,
38
+ lineType=cv2.CV_AA)
39
+
40
+ mask = np.dstack(3*[(1.0/255)*mask])
41
+
42
+ orig = im[y1:y2, x1:x2]
43
+ blurred = cv2.blur(orig,(r_blur, r_blur))
44
+ im[y1:y2, x1:x2] = mask*blurred + (1-mask)*orig
45
+ return im
46
+
47
+ return clip.fl(fl)
48
+
49
+
50
+
51
+ #------- OVERWRITE IF REQUIREMENTS NOT MET -----------------------------
52
+ if not headblur_possible:
53
+ doc = headblur.__doc__
54
+ def headblur(clip,fx,fy,r_zone,r_blur=None):
55
+ raise IOError("fx painting needs opencv")
56
+
57
+ headblur.__doc__ = doc
58
+ #-----------------------------------------------------------------------
videollama2/lib/python3.10/site-packages/moviepy/video/fx/invert_colors.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ def invert_colors(clip):
2
+ """ Returns the color-inversed clip.
3
+
4
+ The values of all pixels are replaced with (255-v) or (1-v) for masks
5
+ Black becomes white, green becomes purple, etc.
6
+ """
7
+ maxi = (1.0 if clip.ismask else 255)
8
+ return clip.fl_image(lambda f : maxi - f)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/loop.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from moviepy.decorators import apply_to_audio, apply_to_mask, requires_duration
2
+
3
+
4
+ @requires_duration
5
+ @apply_to_mask
6
+ @apply_to_audio
7
+ def loop(self, n=None, duration=None):
8
+ """
9
+ Returns a clip that plays the current clip in an infinite loop.
10
+ Ideal for clips coming from gifs.
11
+
12
+ Parameters
13
+ ------------
14
+ n
15
+ Number of times the clip should be played. If `None` the
16
+ the clip will loop indefinitely (i.e. with no set duration).
17
+
18
+ duration
19
+ Total duration of the clip. Can be specified instead of n.
20
+ """
21
+ result = self.fl_time(lambda t: t % self.duration)
22
+ if n:
23
+ duration = n*self.duration
24
+ if duration:
25
+ result = result.set_duration(duration)
26
+ return result
videollama2/lib/python3.10/site-packages/moviepy/video/fx/lum_contrast.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def lum_contrast(clip, lum = 0, contrast=0, contrast_thr=127):
2
+ """ luminosity-contrast correction of a clip """
3
+
4
+ def fl_image(im):
5
+ im = 1.0*im # float conversion
6
+ corrected = im + lum + contrast*(im-float(contrast_thr))
7
+ corrected[corrected < 0] = 0
8
+ corrected[corrected > 255] = 255
9
+ return corrected.astype('uint8')
10
+
11
+ return clip.fl_image(fl_image)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/make_loopable.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import moviepy.video.compositing.transitions as transfx
2
+ from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
3
+
4
+
5
+ def make_loopable(clip, cross):
6
+ """
7
+ Makes the clip fade in progressively at its own end, this way
8
+ it can be looped indefinitely. ``cross`` is the duration in seconds
9
+ of the fade-in. """
10
+ d = clip.duration
11
+ clip2 = clip.fx(transfx.crossfadein, cross).\
12
+ set_start(d - cross)
13
+ return CompositeVideoClip([ clip, clip2 ]).\
14
+ subclip(cross,d)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/margin.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from moviepy.decorators import apply_to_mask
4
+ from moviepy.video.VideoClip import ImageClip
5
+
6
+
7
+ @apply_to_mask
8
+ def margin(clip, mar=None, left=0, right=0, top=0,
9
+ bottom=0, color=(0, 0, 0), opacity = 1.0):
10
+ """
11
+ Draws an external margin all around the frame.
12
+
13
+ :param mar: if not ``None``, then the new clip has a margin of
14
+ size ``mar`` in pixels on the left, right, top, and bottom.
15
+
16
+ :param left, right, top, bottom: width of the margin in pixel
17
+ in these directions.
18
+
19
+ :param color: color of the margin.
20
+
21
+ :param mask_margin: value of the mask on the margin. Setting
22
+ this value to 0 yields transparent margins.
23
+
24
+ """
25
+
26
+ if (opacity != 1.0) and (clip.mask is None) and not (clip.ismask):
27
+ clip = clip.add_mask()
28
+
29
+ if mar is not None:
30
+ left = right = top = bottom = mar
31
+
32
+ def make_bg(w,h):
33
+ new_w, new_h = w + left + right, h + top + bottom
34
+ if clip.ismask:
35
+ shape = (new_h, new_w)
36
+ bg = ( np.tile(opacity, (new_h, new_w))
37
+ .astype(float)
38
+ .reshape(shape))
39
+ else:
40
+ shape = (new_h, new_w, 3)
41
+ bg = np.tile(color, (new_h, new_w)).reshape(shape)
42
+ return bg
43
+
44
+ if isinstance(clip, ImageClip):
45
+
46
+ im = make_bg(clip.w,clip.h)
47
+ im[top:top + clip.h, left:left + clip.w] = clip.img
48
+ return clip.fl_image(lambda pic:im)
49
+
50
+ else:
51
+
52
+ def fl(gf, t):
53
+ pic = gf(t)
54
+ h,w = pic.shape[:2]
55
+ im = make_bg(w,h)
56
+ im[top:top + h, left:left + w] = pic
57
+ return im
58
+ return clip.fl(fl)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/mask_and.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from ..VideoClip import ImageClip
4
+
5
+
6
+ def mask_and(clip, other_clip):
7
+ """ Returns the logical 'and' (min) between two masks.
8
+ other_clip can be a mask clip or a picture (np.array).
9
+ The result has the duration of 'clip' (if it has any)
10
+ """
11
+
12
+ # To ensure that 'or' of two ImageClips will be an ImageClip.
13
+ if isinstance(other_clip, ImageClip):
14
+ other_clip = other_clip.img
15
+
16
+ if isinstance(other_clip, np.ndarray):
17
+ return clip.fl_image(lambda f : np.minimum(f, other_clip))
18
+ else:
19
+ return clip.fl(lambda gf, t : np.minimum(gf(t),
20
+ other_clip.get_frame(t)))
videollama2/lib/python3.10/site-packages/moviepy/video/fx/mask_or.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from ..VideoClip import ImageClip
4
+
5
+
6
+ def mask_or(clip, other_clip):
7
+ """ Returns the logical 'or' (max) between two masks.
8
+ other_clip can be a mask clip or a picture (np.array).
9
+ The result has the duration of 'clip' (if it has any)
10
+ """
11
+
12
+ # To ensure that 'or' of two ImageClips will be an ImageClip.
13
+ if isinstance(other_clip, ImageClip):
14
+ other_clip = other_clip.img
15
+
16
+ if isinstance(other_clip, np.ndarray):
17
+ return clip.fl_image(lambda f : np.maximum(f, other_clip))
18
+ else:
19
+ return clip.fl(lambda gf, t : np.maximum(gf(t),
20
+ other_clip.get_frame(t)))
videollama2/lib/python3.10/site-packages/moviepy/video/fx/mirror_x.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ def mirror_x(clip, apply_to= "mask"):
3
+ """ flips the clip horizontally (and its mask too, by default) """
4
+ return clip.fl_image(lambda f: f[:,::-1], apply_to = apply_to)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/mirror_y.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ def mirror_y(clip, apply_to= "mask"):
2
+ """ flips the clip vertically (and its mask too, by default) """
3
+ return clip.fl_image(lambda f : f[::-1], apply_to = apply_to)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/painting.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #------- CHECKING DEPENDENCIES -----------------------------------------
2
+ painting_possible = True
3
+ try:
4
+ from skimage.filter import sobel
5
+ except:
6
+ try:
7
+ from scipy.ndimage.filters import sobel
8
+ except:
9
+ painting_possible = False
10
+ #-----------------------------------------------------------------------
11
+
12
+
13
+
14
+ import numpy as np
15
+
16
+
17
+ def to_painting(image,saturation = 1.4,black = 0.006):
18
+ """ transforms any photo into some kind of painting """
19
+ edges = sobel(image.mean(axis=2))
20
+ darkening = black*(255*np.dstack(3*[edges]))
21
+ painting = saturation*image-darkening
22
+ return np.maximum(0,np.minimum(255,painting)).astype('uint8')
23
+
24
+ def painting(clip, saturation = 1.4,black = 0.006):
25
+ """
26
+ Transforms any photo into some kind of painting. Saturation
27
+ tells at which point the colors of the result should be
28
+ flashy. ``black`` gives the anount of black lines wanted.
29
+ Requires Scikit-image or Scipy installed.
30
+ """
31
+ return clip.fl_image(lambda im : to_painting(im,saturation,black))
32
+
33
+
34
+
35
+ #------- OVERWRITE IF REQUIREMENTS NOT MET -----------------------------
36
+
37
+ if not painting_possible:
38
+ doc = painting.__doc__
39
+ def painting(clip, newsize=None, height=None, width=None):
40
+ raise IOError("fx painting needs scikit-image or scipy")
41
+
42
+ painting.__doc__ = doc
43
+ #-----------------------------------------------------------------------
videollama2/lib/python3.10/site-packages/moviepy/video/fx/rotate.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from moviepy.decorators import apply_to_mask
4
+
5
+ try:
6
+ from PIL import Image
7
+ PIL_FOUND = True
8
+ def pil_rotater(pic, angle, resample, expand):
9
+ return np.array( Image.fromarray(pic).rotate(angle, expand=expand,
10
+ resample=resample))
11
+ except ImportError:
12
+ PIL_FOUND = False
13
+
14
+ def rotate(clip, angle, unit='deg', resample="bicubic", expand=True):
15
+ """
16
+ Change unit to 'rad' to define angles as radians.
17
+ If the angle is not one of 90, 180, -90, -180 (degrees) there will be
18
+ black borders. You can make them transparent with
19
+
20
+ >>> newclip = clip.add_mask().rotate(72)
21
+
22
+ Parameters
23
+ ===========
24
+
25
+ clip
26
+ A video clip
27
+
28
+ angle
29
+ Either a value or a function angle(t) representing the angle of rotation
30
+
31
+ unit
32
+ Unit of parameter `angle` (either `deg` for degrees or `rad` for radians)
33
+
34
+ resample
35
+ One of "nearest", "bilinear", or "bicubic".
36
+
37
+ expand
38
+ Only applIf False, the clip will maintain the same True, the clip will be resized so that the whole
39
+ """
40
+
41
+ resample = {"bilinear": Image.BILINEAR,
42
+ "nearest": Image.NEAREST,
43
+ "bicubic": Image.BICUBIC}[resample]
44
+
45
+ if not hasattr(angle, '__call__'):
46
+ # if angle is a constant, convert to a constant function
47
+ a = +angle
48
+ angle = lambda t: a
49
+
50
+ transpo = [1,0] if clip.ismask else [1,0,2]
51
+
52
+ def fl(gf, t):
53
+
54
+ a = angle(t)
55
+ im = gf(t)
56
+
57
+ if unit == 'rad':
58
+ a = 360.0*a/(2*np.pi)
59
+
60
+ if (a==90) and expand:
61
+ return np.transpose(im, axes=transpo)[::-1]
62
+ elif (a==-90) and expand:
63
+ return np.transpose(im, axes=transpo)[:,::-1]
64
+ elif (a in [180, -180]) and expand:
65
+ return im[::-1,::-1]
66
+ elif not PIL_FOUND:
67
+ raise ValueError('Without "Pillow" installed, only angles 90, -90,'
68
+ '180 are supported, please install "Pillow" with'
69
+ "pip install pillow")
70
+ else:
71
+ return pil_rotater(im, a, resample=resample, expand=expand)
72
+
73
+ return clip.fl(fl, apply_to=["mask"])
videollama2/lib/python3.10/site-packages/moviepy/video/fx/scroll.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def scroll(clip, h=None, w=None, x_speed=0, y_speed=0,
2
+ x_start=0, y_start=0, apply_to="mask"):
3
+ """ Scrolls horizontally or vertically a clip, e.g. to make end
4
+ credits """
5
+ if h is None: h = clip.h
6
+ if w is None: w = clip.w
7
+
8
+ xmax = clip.w-w-1
9
+ ymax = clip.h-h-1
10
+
11
+ def f(gf,t):
12
+ x = int(max(0, min(xmax, x_start+ round(x_speed*t))))
13
+ y = int(max(0, min(ymax, y_start+ round(y_speed*t))))
14
+ return gf(t)[y:y+h, x:x+w]
15
+
16
+ return clip.fl(f, apply_to = apply_to)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/speedx.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from moviepy.decorators import apply_to_audio, apply_to_mask
2
+
3
+
4
+ def speedx(clip, factor = None, final_duration=None):
5
+ """
6
+ Returns a clip playing the current clip but at a speed multiplied
7
+ by ``factor``. Instead of factor one can indicate the desired
8
+ ``final_duration`` of the clip, and the factor will be automatically
9
+ computed.
10
+ The same effect is applied to the clip's audio and mask if any.
11
+ """
12
+
13
+ if final_duration:
14
+ factor = 1.0* clip.duration / final_duration
15
+
16
+ newclip = clip.fl_time(lambda t: factor * t, apply_to=['mask', 'audio'])
17
+
18
+ if clip.duration is not None:
19
+ newclip = newclip.set_duration(1.0 * clip.duration / factor)
20
+
21
+ return newclip
videollama2/lib/python3.10/site-packages/moviepy/video/fx/supersample.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+
4
+ def supersample(clip, d, nframes):
5
+ """ Replaces each frame at time t by the mean of `nframes` equally spaced frames
6
+ taken in the interval [t-d, t+d]. This results in motion blur."""
7
+
8
+ def fl(gf, t):
9
+ tt = np.linspace(t-d, t+d, nframes)
10
+ avg = np.mean(1.0*np.array([gf(t_) for t_ in tt], dtype='uint16'), axis=0)
11
+ return avg.astype("uint8")
12
+
13
+ return clip.fl(fl)
videollama2/lib/python3.10/site-packages/moviepy/video/fx/time_symmetrize.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from moviepy.decorators import apply_to_audio, apply_to_mask, requires_duration
2
+ from moviepy.video.compositing.concatenate import concatenate_videoclips
3
+
4
+ from .time_mirror import time_mirror
5
+
6
+
7
+ @requires_duration
8
+ @apply_to_mask
9
+ def time_symmetrize(clip):
10
+ """
11
+ Returns a clip that plays the current clip once forwards and
12
+ then once backwards. This is very practival to make video that
13
+ loop well, e.g. to create animated GIFs.
14
+ This effect is automatically applied to the clip's mask and audio
15
+ if they exist.
16
+ """
17
+ return concatenate_videoclips([clip, clip.fx( time_mirror )])
videollama2/lib/python3.10/site-packages/moviepy/video/io/VideoFileClip.py ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ from moviepy.audio.io.AudioFileClip import AudioFileClip
4
+ from moviepy.Clip import Clip
5
+ from moviepy.video.io.ffmpeg_reader import FFMPEG_VideoReader
6
+ from moviepy.video.VideoClip import VideoClip
7
+
8
+
9
+ class VideoFileClip(VideoClip):
10
+
11
+ """
12
+
13
+ A video clip originating from a movie file. For instance: ::
14
+
15
+ >>> clip = VideoFileClip("myHolidays.mp4")
16
+ >>> clip.close()
17
+ >>> with VideoFileClip("myMaskVideo.avi") as clip2:
18
+ >>> pass # Implicit close called by context manager.
19
+
20
+
21
+ Parameters
22
+ ------------
23
+
24
+ filename:
25
+ The name of the video file. It can have any extension supported
26
+ by ffmpeg: .ogv, .mp4, .mpeg, .avi, .mov etc.
27
+
28
+ has_mask:
29
+ Set this to 'True' if there is a mask included in the videofile.
30
+ Video files rarely contain masks, but some video codecs enable
31
+ that. For istance if you have a MoviePy VideoClip with a mask you
32
+ can save it to a videofile with a mask. (see also
33
+ ``VideoClip.write_videofile`` for more details).
34
+
35
+ audio:
36
+ Set to `False` if the clip doesn't have any audio or if you do not
37
+ wish to read the audio.
38
+
39
+ target_resolution:
40
+ Set to (desired_height, desired_width) to have ffmpeg resize the frames
41
+ before returning them. This is much faster than streaming in high-res
42
+ and then resizing. If either dimension is None, the frames are resized
43
+ by keeping the existing aspect ratio.
44
+
45
+ resize_algorithm:
46
+ The algorithm used for resizing. Default: "bicubic", other popular
47
+ options include "bilinear" and "fast_bilinear". For more information, see
48
+ https://ffmpeg.org/ffmpeg-scaler.html
49
+
50
+ fps_source:
51
+ The fps value to collect from the metadata. Set by default to 'tbr', but
52
+ can be set to 'fps', which may be helpful if importing slow-motion videos
53
+ that get messed up otherwise.
54
+
55
+
56
+ Attributes
57
+ -----------
58
+
59
+ filename:
60
+ Name of the original video file.
61
+
62
+ fps:
63
+ Frames per second in the original file.
64
+
65
+
66
+ Read docs for Clip() and VideoClip() for other, more generic, attributes.
67
+
68
+ Lifetime
69
+ --------
70
+
71
+ Note that this creates subprocesses and locks files. If you construct one of these instances, you must call
72
+ close() afterwards, or the subresources will not be cleaned up until the process ends.
73
+
74
+ If copies are made, and close() is called on one, it may cause methods on the other copies to fail.
75
+
76
+ """
77
+
78
+ def __init__(self, filename, has_mask=False,
79
+ audio=True, audio_buffersize=200000,
80
+ target_resolution=None, resize_algorithm='bicubic',
81
+ audio_fps=44100, audio_nbytes=2, verbose=False,
82
+ fps_source='tbr'):
83
+
84
+ VideoClip.__init__(self)
85
+
86
+ # Make a reader
87
+ pix_fmt = "rgba" if has_mask else "rgb24"
88
+ self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt,
89
+ target_resolution=target_resolution,
90
+ resize_algo=resize_algorithm,
91
+ fps_source=fps_source)
92
+
93
+ # Make some of the reader's attributes accessible from the clip
94
+ self.duration = self.reader.duration
95
+ self.end = self.reader.duration
96
+
97
+ self.fps = self.reader.fps
98
+ self.size = self.reader.size
99
+ self.rotation = self.reader.rotation
100
+
101
+ self.filename = self.reader.filename
102
+
103
+ if has_mask:
104
+
105
+ self.make_frame = lambda t: self.reader.get_frame(t)[:,:,:3]
106
+ mask_mf = lambda t: self.reader.get_frame(t)[:,:,3]/255.0
107
+ self.mask = (VideoClip(ismask=True, make_frame=mask_mf)
108
+ .set_duration(self.duration))
109
+ self.mask.fps = self.fps
110
+
111
+ else:
112
+
113
+ self.make_frame = lambda t: self.reader.get_frame(t)
114
+
115
+ # Make a reader for the audio, if any.
116
+ if audio and self.reader.infos['audio_found']:
117
+
118
+ self.audio = AudioFileClip(filename,
119
+ buffersize=audio_buffersize,
120
+ fps=audio_fps,
121
+ nbytes=audio_nbytes)
122
+
123
+ def close(self):
124
+ """ Close the internal reader. """
125
+ if self.reader:
126
+ self.reader.close()
127
+ self.reader = None
128
+
129
+ try:
130
+ if self.audio:
131
+ self.audio.close()
132
+ self.audio = None
133
+ except AttributeError:
134
+ pass
videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/ImageSequenceClip.cpython-310.pyc ADDED
Binary file (4.49 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (255 Bytes). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/bindings.cpython-310.pyc ADDED
Binary file (1.06 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/ffmpeg_reader.cpython-310.pyc ADDED
Binary file (9.4 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/gif_writers.cpython-310.pyc ADDED
Binary file (6.63 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/html_tools.cpython-310.pyc ADDED
Binary file (6.48 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/preview.cpython-310.pyc ADDED
Binary file (3.79 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/io/__pycache__/sliders.cpython-310.pyc ADDED
Binary file (2.23 kB). View file
 
videollama2/lib/python3.10/site-packages/moviepy/video/io/bindings.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ This module implements all the functions to communicate with other Python
3
+ modules (PIL, matplotlib, mayavi, etc.)
4
+ """
5
+
6
+ import numpy as np
7
+
8
+
9
+ def PIL_to_npimage(im):
10
+ """ Transforms a PIL/Pillow image into a numpy RGB(A) image.
11
+ Actually all this do is returning numpy.array(im)."""
12
+ return np.array(im)
13
+ #w,h = im.size
14
+ #d = (4 if im.mode=="RGBA" else 3)
15
+ #return +np.frombuffer(im.tobytes(), dtype='uint8').reshape((h,w,d))
16
+
17
+
18
+ def mplfig_to_npimage(fig):
19
+ """ Converts a matplotlib figure to a RGB frame after updating the canvas"""
20
+ # only the Agg backend now supports the tostring_rgb function
21
+ from matplotlib.backends.backend_agg import FigureCanvasAgg
22
+ canvas = FigureCanvasAgg(fig)
23
+ canvas.draw() # update/draw the elements
24
+
25
+ # get the width and the height to resize the matrix
26
+ l,b,w,h = canvas.figure.bbox.bounds
27
+ w, h = int(w), int(h)
28
+
29
+ # exports the canvas to a string buffer and then to a numpy nd.array
30
+ buf = canvas.tostring_rgb()
31
+ image= np.frombuffer(buf, dtype=np.uint8)
32
+ return image.reshape(h,w,3)
videollama2/lib/python3.10/site-packages/moviepy/video/io/ffmpeg_reader.py ADDED
@@ -0,0 +1,393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ This module implements all the functions to read a video or a picture
3
+ using ffmpeg. It is quite ugly, as there are many pitfalls to avoid
4
+ """
5
+
6
+ from __future__ import division
7
+
8
+ import logging
9
+ import os
10
+ import re
11
+ import subprocess as sp
12
+ import warnings
13
+
14
+ import numpy as np
15
+
16
+ from moviepy.compat import DEVNULL, PY3
17
+ from moviepy.config import get_setting # ffmpeg, ffmpeg.exe, etc...
18
+ from moviepy.tools import cvsecs
19
+
20
+ logging.captureWarnings(True)
21
+
22
+
23
+
24
+
25
+
26
+ class FFMPEG_VideoReader:
27
+
28
+ def __init__(self, filename, print_infos=False, bufsize = None,
29
+ pix_fmt="rgb24", check_duration=True,
30
+ target_resolution=None, resize_algo='bicubic',
31
+ fps_source='tbr'):
32
+
33
+ self.filename = filename
34
+ self.proc = None
35
+ infos = ffmpeg_parse_infos(filename, print_infos, check_duration,
36
+ fps_source)
37
+ self.fps = infos['video_fps']
38
+ self.size = infos['video_size']
39
+ self.rotation = infos['video_rotation']
40
+
41
+ if target_resolution:
42
+ # revert the order, as ffmpeg used (width, height)
43
+ target_resolution = target_resolution[1], target_resolution[0]
44
+
45
+ if None in target_resolution:
46
+ ratio = 1
47
+ for idx, target in enumerate(target_resolution):
48
+ if target:
49
+ ratio = target / self.size[idx]
50
+ self.size = (int(self.size[0] * ratio), int(self.size[1] * ratio))
51
+ else:
52
+ self.size = target_resolution
53
+ self.resize_algo = resize_algo
54
+
55
+ self.duration = infos['video_duration']
56
+ self.ffmpeg_duration = infos['duration']
57
+ self.nframes = infos['video_nframes']
58
+
59
+ self.infos = infos
60
+
61
+ self.pix_fmt = pix_fmt
62
+ self.depth = 4 if pix_fmt == 'rgba' else 3
63
+
64
+ if bufsize is None:
65
+ w, h = self.size
66
+ bufsize = self.depth * w * h + 100
67
+
68
+ self.bufsize= bufsize
69
+ self.initialize()
70
+
71
+
72
+ self.pos = 1
73
+ self.lastread = self.read_frame()
74
+
75
+
76
+ def initialize(self, starttime=0):
77
+ """Opens the file, creates the pipe. """
78
+
79
+ self.close() # if any
80
+
81
+ if starttime != 0 :
82
+ offset = min(1, starttime)
83
+ i_arg = ['-ss', "%.06f" % (starttime - offset),
84
+ '-i', self.filename,
85
+ '-ss', "%.06f" % offset]
86
+ else:
87
+ i_arg = [ '-i', self.filename]
88
+
89
+ cmd = ([get_setting("FFMPEG_BINARY")] + i_arg +
90
+ ['-loglevel', 'error',
91
+ '-f', 'image2pipe',
92
+ '-vf', 'scale=%d:%d' % tuple(self.size),
93
+ '-sws_flags', self.resize_algo,
94
+ "-pix_fmt", self.pix_fmt,
95
+ '-vcodec', 'rawvideo', '-'])
96
+ popen_params = {"bufsize": self.bufsize,
97
+ "stdout": sp.PIPE,
98
+ "stderr": sp.PIPE,
99
+ "stdin": DEVNULL}
100
+
101
+ if os.name == "nt":
102
+ popen_params["creationflags"] = 0x08000000
103
+
104
+ self.proc = sp.Popen(cmd, **popen_params)
105
+
106
+
107
+ def skip_frames(self, n=1):
108
+ """Reads and throws away n frames """
109
+ w, h = self.size
110
+ for i in range(n):
111
+ self.proc.stdout.read(self.depth*w*h)
112
+ #self.proc.stdout.flush()
113
+ self.pos += n
114
+
115
+
116
+ def read_frame(self):
117
+ w, h = self.size
118
+ nbytes= self.depth*w*h
119
+
120
+ s = self.proc.stdout.read(nbytes)
121
+ if len(s) != nbytes:
122
+
123
+ warnings.warn("Warning: in file %s, "%(self.filename)+
124
+ "%d bytes wanted but %d bytes read,"%(nbytes, len(s))+
125
+ "at frame %d/%d, at time %.02f/%.02f sec. "%(
126
+ self.pos,self.nframes,
127
+ 1.0*self.pos/self.fps,
128
+ self.duration)+
129
+ "Using the last valid frame instead.",
130
+ UserWarning)
131
+
132
+ if not hasattr(self, 'lastread'):
133
+ raise IOError(("MoviePy error: failed to read the first frame of "
134
+ "video file %s. That might mean that the file is "
135
+ "corrupted. That may also mean that you are using "
136
+ "a deprecated version of FFMPEG. On Ubuntu/Debian "
137
+ "for instance the version in the repos is deprecated. "
138
+ "Please update to a recent version from the website.")%(
139
+ self.filename))
140
+
141
+ result = self.lastread
142
+
143
+ else:
144
+ if hasattr(np, 'frombuffer'):
145
+ result = np.frombuffer(s, dtype='uint8')
146
+ else:
147
+ result = np.fromstring(s, dtype='uint8')
148
+ result.shape =(h, w, len(s)//(w*h)) # reshape((h, w, len(s)//(w*h)))
149
+ self.lastread = result
150
+
151
+ return result
152
+
153
+ def get_frame(self, t):
154
+ """ Read a file video frame at time t.
155
+
156
+ Note for coders: getting an arbitrary frame in the video with
157
+ ffmpeg can be painfully slow if some decoding has to be done.
158
+ This function tries to avoid fetching arbitrary frames
159
+ whenever possible, by moving between adjacent frames.
160
+ """
161
+
162
+ # these definitely need to be rechecked sometime. Seems to work.
163
+
164
+ # I use that horrible '+0.00001' hack because sometimes due to numerical
165
+ # imprecisions a 3.0 can become a 2.99999999... which makes the int()
166
+ # go to the previous integer. This makes the fetching more robust in the
167
+ # case where you get the nth frame by writing get_frame(n/fps).
168
+
169
+ pos = int(self.fps*t + 0.00001)+1
170
+
171
+ # Initialize proc if it is not open
172
+ if not self.proc:
173
+ self.initialize(t)
174
+ self.pos = pos
175
+ self.lastread = self.read_frame()
176
+
177
+ if pos == self.pos:
178
+ return self.lastread
179
+ elif (pos < self.pos) or (pos > self.pos + 100):
180
+ self.initialize(t)
181
+ self.pos = pos
182
+ else:
183
+ self.skip_frames(pos-self.pos-1)
184
+ result = self.read_frame()
185
+ self.pos = pos
186
+ return result
187
+
188
+ def close(self):
189
+ if self.proc:
190
+ self.proc.terminate()
191
+ self.proc.stdout.close()
192
+ self.proc.stderr.close()
193
+ self.proc.wait()
194
+ self.proc = None
195
+ if hasattr(self, 'lastread'):
196
+ del self.lastread
197
+
198
+ def __del__(self):
199
+ self.close()
200
+
201
+
202
+ def ffmpeg_read_image(filename, with_mask=True):
203
+ """ Read an image file (PNG, BMP, JPEG...).
204
+
205
+ Wraps FFMPEG_Videoreader to read just one image.
206
+ Returns an ImageClip.
207
+
208
+ This function is not meant to be used directly in MoviePy,
209
+ use ImageClip instead to make clips out of image files.
210
+
211
+ Parameters
212
+ -----------
213
+
214
+ filename
215
+ Name of the image file. Can be of any format supported by ffmpeg.
216
+
217
+ with_mask
218
+ If the image has a transparency layer, ``with_mask=true`` will save
219
+ this layer as the mask of the returned ImageClip
220
+
221
+ """
222
+ pix_fmt = 'rgba' if with_mask else "rgb24"
223
+ reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt, check_duration=False)
224
+ im = reader.lastread
225
+ del reader
226
+ return im
227
+
228
+
229
+ def ffmpeg_parse_infos(filename, print_infos=False, check_duration=True,
230
+ fps_source='tbr'):
231
+ """Get file infos using ffmpeg.
232
+
233
+ Returns a dictionnary with the fields:
234
+ "video_found", "video_fps", "duration", "video_nframes",
235
+ "video_duration", "audio_found", "audio_fps"
236
+
237
+ "video_duration" is slightly smaller than "duration" to avoid
238
+ fetching the uncomplete frames at the end, which raises an error.
239
+
240
+ """
241
+
242
+
243
+ # open the file in a pipe, provoke an error, read output
244
+ is_GIF = filename.endswith('.gif')
245
+ cmd = [get_setting("FFMPEG_BINARY"), "-i", filename]
246
+ if is_GIF:
247
+ cmd += ["-f", "null", "/dev/null"]
248
+
249
+ popen_params = {"bufsize": 10**5,
250
+ "stdout": sp.PIPE,
251
+ "stderr": sp.PIPE,
252
+ "stdin": DEVNULL}
253
+
254
+ if os.name == "nt":
255
+ popen_params["creationflags"] = 0x08000000
256
+
257
+ proc = sp.Popen(cmd, **popen_params)
258
+ (output, error) = proc.communicate()
259
+ infos = error.decode('utf8')
260
+
261
+ del proc
262
+
263
+ if print_infos:
264
+ # print the whole info text returned by FFMPEG
265
+ print(infos)
266
+
267
+
268
+ lines = infos.splitlines()
269
+ if "No such file or directory" in lines[-1]:
270
+ raise IOError(("MoviePy error: the file %s could not be found!\n"
271
+ "Please check that you entered the correct "
272
+ "path.")%filename)
273
+
274
+ result = dict()
275
+
276
+
277
+ # get duration (in seconds)
278
+ result['duration'] = None
279
+
280
+ if check_duration:
281
+ try:
282
+ keyword = ('frame=' if is_GIF else 'Duration: ')
283
+ # for large GIFS the "full" duration is presented as the last element in the list.
284
+ index = -1 if is_GIF else 0
285
+ line = [l for l in lines if keyword in l][index]
286
+ match = re.findall("([0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9])", line)[0]
287
+ result['duration'] = cvsecs(match)
288
+ except:
289
+ raise IOError(("MoviePy error: failed to read the duration of file %s.\n"
290
+ "Here are the file infos returned by ffmpeg:\n\n%s")%(
291
+ filename, infos))
292
+
293
+ # get the output line that speaks about video
294
+ lines_video = [l for l in lines if ' Video: ' in l and re.search('\d+x\d+', l)]
295
+
296
+ result['video_found'] = ( lines_video != [] )
297
+
298
+ if result['video_found']:
299
+ try:
300
+ line = lines_video[0]
301
+
302
+ # get the size, of the form 460x320 (w x h)
303
+ match = re.search(" [0-9]*x[0-9]*(,| )", line)
304
+ s = list(map(int, line[match.start():match.end()-1].split('x')))
305
+ result['video_size'] = s
306
+ except:
307
+ raise IOError(("MoviePy error: failed to read video dimensions in file %s.\n"
308
+ "Here are the file infos returned by ffmpeg:\n\n%s")%(
309
+ filename, infos))
310
+
311
+ # Get the frame rate. Sometimes it's 'tbr', sometimes 'fps', sometimes
312
+ # tbc, and sometimes tbc/2...
313
+ # Current policy: Trust tbr first, then fps unless fps_source is
314
+ # specified as 'fps' in which case try fps then tbr
315
+
316
+ # If result is near from x*1000/1001 where x is 23,24,25,50,
317
+ # replace by x*1000/1001 (very common case for the fps).
318
+
319
+ def get_tbr():
320
+ match = re.search("( [0-9]*.| )[0-9]* tbr", line)
321
+
322
+ # Sometimes comes as e.g. 12k. We need to replace that with 12000.
323
+ s_tbr = line[match.start():match.end()].split(' ')[1]
324
+ if "k" in s_tbr:
325
+ tbr = float(s_tbr.replace("k", "")) * 1000
326
+ else:
327
+ tbr = float(s_tbr)
328
+ return tbr
329
+
330
+ def get_fps():
331
+ match = re.search("( [0-9]*.| )[0-9]* fps", line)
332
+ fps = float(line[match.start():match.end()].split(' ')[1])
333
+ return fps
334
+
335
+ if fps_source == 'tbr':
336
+ try:
337
+ result['video_fps'] = get_tbr()
338
+ except:
339
+ result['video_fps'] = get_fps()
340
+
341
+ elif fps_source == 'fps':
342
+ try:
343
+ result['video_fps'] = get_fps()
344
+ except:
345
+ result['video_fps'] = get_tbr()
346
+
347
+ # It is known that a fps of 24 is often written as 24000/1001
348
+ # but then ffmpeg nicely rounds it to 23.98, which we hate.
349
+ coef = 1000.0/1001.0
350
+ fps = result['video_fps']
351
+ for x in [23,24,25,30,50]:
352
+ if (fps!=x) and abs(fps - x*coef) < .01:
353
+ result['video_fps'] = x*coef
354
+
355
+ if check_duration:
356
+ result['video_nframes'] = int(result['duration']*result['video_fps'])+1
357
+ result['video_duration'] = result['duration']
358
+ else:
359
+ result['video_nframes'] = 1
360
+ result['video_duration'] = None
361
+ # We could have also recomputed the duration from the number
362
+ # of frames, as follows:
363
+ # >>> result['video_duration'] = result['video_nframes'] / result['video_fps']
364
+
365
+ # get the video rotation info.
366
+ try:
367
+ rotation_lines = [l for l in lines if 'rotate :' in l and re.search('\d+$', l)]
368
+ if len(rotation_lines):
369
+ rotation_line = rotation_lines[0]
370
+ match = re.search('\d+$', rotation_line)
371
+ result['video_rotation'] = int(rotation_line[match.start() : match.end()])
372
+ else:
373
+ result['video_rotation'] = 0
374
+ except:
375
+ raise IOError(("MoviePy error: failed to read video rotation in file %s.\n"
376
+ "Here are the file infos returned by ffmpeg:\n\n%s")%(
377
+ filename, infos))
378
+
379
+
380
+ lines_audio = [l for l in lines if ' Audio: ' in l]
381
+
382
+ result['audio_found'] = lines_audio != []
383
+
384
+ if result['audio_found']:
385
+ line = lines_audio[0]
386
+ try:
387
+ match = re.search(" [0-9]* Hz", line)
388
+ hz_string = line[match.start()+1:match.end()-3] # Removes the 'hz' from the end
389
+ result['audio_fps'] = int(hz_string)
390
+ except:
391
+ result['audio_fps'] = 'unknown'
392
+
393
+ return result