Spaces:
Runtime error
Runtime error
Rename rytp.py to app.py
Browse files- rytp.py → app.py +104 -103
rytp.py → app.py
RENAMED
@@ -1,103 +1,104 @@
|
|
1 |
-
|
2 |
-
from
|
3 |
-
import
|
4 |
-
import
|
5 |
-
import
|
6 |
-
import
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
| |
|
25 |
-
|_|
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
if c == "
|
80 |
-
if c == "
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
print(
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
rytp.
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from moviepy.editor import *
|
3 |
+
from pathlib import Path
|
4 |
+
import random
|
5 |
+
import os
|
6 |
+
import moviepy
|
7 |
+
import inspect
|
8 |
+
|
9 |
+
module_path = inspect.getfile(moviepy)
|
10 |
+
path_file_needed = os.path.dirname(module_path)+r"\video\fx\resize.py"
|
11 |
+
|
12 |
+
with open(path_file_needed, 'r') as f:
|
13 |
+
file_to_update = f.read()
|
14 |
+
if file_to_update.find("ANTIALIAS")!=-1:
|
15 |
+
with open(path_file_needed, 'w') as f:
|
16 |
+
f.write(file_to_update.replace('ANTIALIAS', 'LANCZOS'))
|
17 |
+
f.close()
|
18 |
+
|
19 |
+
intro = VideoFileClip("intro.mp4")
|
20 |
+
print("""
|
21 |
+
_ _
|
22 |
+
| | | |
|
23 |
+
_ __ _ _| |_ _ __ __ _ ___ _ __ ___ _ __ __ _| |_ ___ _ __
|
24 |
+
| '__| | | | __| '_ \ / _` |/ _ \ '_ \ / _ \ '__/ _` | __/ _ \| '__|
|
25 |
+
| | | |_| | |_| |_) | | (_| | __/ | | | __/ | | (_| | || (_) | |
|
26 |
+
|_| \__, |\__| .__/ \__, |\___|_| |_|\___|_| \__,_|\__\___/|_|
|
27 |
+
__/ | | | __/ |
|
28 |
+
|___/ |_| |___/
|
29 |
+
""")
|
30 |
+
clips_range = int(input("Количество вставок в пупе (25 вставок = +-одна минута): "))
|
31 |
+
minimum = float(input("Минимальная продолжительность одной вставки в пупе: "))
|
32 |
+
maximum = float(input("Максимальная продолжительность одной вставки в пупе: "))
|
33 |
+
random_shit = [i/10 for i in range(5, 25, 1)]
|
34 |
+
effects = ['.fx(vfx.speedx, random.choice(random_shit))', '.fx(vfx.mirror_x)', '.fx(vfx.time_mirror)', '.set_audio(second_clip.audio)', '.fx(vfx.invert_colors)']
|
35 |
+
percentage_array = ["САС"] * 35 + ["РАНДОМ"] * 35 + ["ПИТЧ"] * 20 + ["НИЧЕГО"] * 10
|
36 |
+
|
37 |
+
# САС эффект
|
38 |
+
def sas(clip):
|
39 |
+
reverse = clip.fx(vfx.time_mirror)
|
40 |
+
saas_clip = concatenate_videoclips([clip, reverse])
|
41 |
+
return saas_clip
|
42 |
+
|
43 |
+
# Питч эффект - с каждой итерацией (5 раз) клип становится всё быстрей и быстрей
|
44 |
+
def pitchclip(clip):
|
45 |
+
random_timestamp = random.uniform(0, clip.duration-(clip.duration/5))
|
46 |
+
clip_n = clip.subclip(random_timestamp, random_timestamp+(clip.duration/5))
|
47 |
+
|
48 |
+
return concatenate_videoclips([clip_n.fx(vfx.speedx, 1+i/2) for i in range(5)])
|
49 |
+
|
50 |
+
# Суп рандом - случайная скорость с каждой итерацией (10 раз)
|
51 |
+
def soup_random(clip):
|
52 |
+
random_timestamp = random.uniform(0, clip.duration-(clip.duration/5))
|
53 |
+
clip_n = clip.subclip(random_timestamp, random_timestamp+(clip.duration/5))
|
54 |
+
|
55 |
+
return concatenate_videoclips([clip_n.fx(vfx.speedx, random.uniform(1, 10)) for i in range(10)])
|
56 |
+
|
57 |
+
|
58 |
+
support_suffixes = [".mp4",".avi",".3gp",".mov"]
|
59 |
+
sources = list(filter(lambda x: Path(f"/media/{x}").suffix in support_suffixes, os.listdir(path="media")))
|
60 |
+
|
61 |
+
print("\nСурсы, использующий генератор:",sources,"\n")
|
62 |
+
|
63 |
+
print("Идёт генерирование пупа... Это может занять более 10 минут")
|
64 |
+
all_clips = [intro]
|
65 |
+
for x in range(clips_range):
|
66 |
+
random_effects = [random.choice(effects) for i in range(random.randint(1,3))]
|
67 |
+
|
68 |
+
if '.set_audio(second_clip.audio)' in random_effects:
|
69 |
+
second_clip = VideoFileClip(f"media/{random.choice(sources)}")
|
70 |
+
crop = random.uniform(0, second_clip.duration-maximum)
|
71 |
+
second_clip = second_clip.subclip(crop, crop + random.uniform(minimum, maximum))
|
72 |
+
|
73 |
+
first_clip = VideoFileClip(f"media/{random.choice(sources)}")
|
74 |
+
crop = random.uniform(0, first_clip.duration-maximum)
|
75 |
+
clip_rytp = eval(f"first_clip.subclip(crop, crop + random.uniform(minimum, maximum)){''.join(random_effects)}")
|
76 |
+
print(clip_rytp.duration)
|
77 |
+
c = random.choice(percentage_array)
|
78 |
+
try:
|
79 |
+
if c == "РАНДОМ": clip_rytp = soup_random(clip_rytp)
|
80 |
+
if c == "ПИТЧ": clip_rytp = pitchclip(clip_rytp)
|
81 |
+
if c == "САС": clip_rytp = sas(clip_rytp)
|
82 |
+
except:
|
83 |
+
pass
|
84 |
+
|
85 |
+
all_clips.append(clip_rytp)
|
86 |
+
clip_rytp.close()
|
87 |
+
|
88 |
+
percentage_rytp = int((len(all_clips)/(clips_range+1))*100)
|
89 |
+
print(f"Выполнено {len(all_clips)}/{clips_range+1} - {percentage_rytp}%")
|
90 |
+
|
91 |
+
print("Видео готово, остался рендер")
|
92 |
+
rytp_final = concatenate_videoclips(all_clips)
|
93 |
+
resolutions = [(320, 240), (640, 360), (1280, 720), (1024, 768)]
|
94 |
+
resolutions_img = ["320x240 - 240p", "640x360 - 360p", "1280x720 - 720p", "1024x768 - 4:3 разрешение"]
|
95 |
+
|
96 |
+
print("Выберите разрешение, в котором вы будете рендерить видео")
|
97 |
+
print('\n'.join([f'{i}. {resolutions_img[i]}' for i in range(len(resolutions_img))]))
|
98 |
+
|
99 |
+
res = int(input("-> "))
|
100 |
+
rytp = rytp_final.resize(resolutions[res])
|
101 |
+
input_fps = int(input("Введите кол-во фпс, в котором вы будете рендерить видео: "))
|
102 |
+
print("Идёт рендер пупа...")
|
103 |
+
rytp.write_videofile('new_rytp.mp4', fps=input_fps)
|
104 |
+
rytp.close()
|