mirror of
https://github.com/EDeev/circlechek.git
synced 2026-10-07 20:49:51 +03:00
Переводы строк приведены к LF
This commit is contained in:
parent
3ac2dfe5e1
commit
7f85340c86
2 changed files with 133 additions and 131 deletions
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
* text=auto eol=lf
|
||||||
|
*.mp4 binary
|
||||||
262
code/scripts.py
262
code/scripts.py
|
|
@ -1,131 +1,131 @@
|
||||||
from PIL import Image, ImageDraw, ImageFilter
|
from PIL import Image, ImageDraw, ImageFilter
|
||||||
from moviepy import *
|
from moviepy import *
|
||||||
import numpy, os
|
import numpy, os
|
||||||
|
|
||||||
from init import bug_report
|
from init import bug_report
|
||||||
|
|
||||||
|
|
||||||
class Movie:
|
class Movie:
|
||||||
def __init__(self, video_file, video_name, path):
|
def __init__(self, video_file, video_name, path):
|
||||||
self.video_file = video_file
|
self.video_file = video_file
|
||||||
self.video_name = video_name
|
self.video_name = video_name
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
self.path_frames = ""
|
self.path_frames = ""
|
||||||
|
|
||||||
def split_into_frames(self):
|
def split_into_frames(self):
|
||||||
video_clip = VideoFileClip(self.video_file)
|
video_clip = VideoFileClip(self.video_file)
|
||||||
video_clip.audio.write_audiofile(self.path + f"/{self.video_name}-audio.mp3", logger=None)
|
video_clip.audio.write_audiofile(self.path + f"/{self.video_name}-audio.mp3", logger=None)
|
||||||
|
|
||||||
self.path_frames = self.path + "/frames"
|
self.path_frames = self.path + "/frames"
|
||||||
step = 1 / 30.0 if video_clip.fps > 60.0 else 1 / video_clip.fps
|
step = 1 / 30.0 if video_clip.fps > 60.0 else 1 / video_clip.fps
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
for current_duration in numpy.arange(0, video_clip.duration, step):
|
for current_duration in numpy.arange(0, video_clip.duration, step):
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
str_c = str(count)
|
str_c = str(count)
|
||||||
num = "00000"[:(len(str_c) * -1)] + str_c
|
num = "00000"[:(len(str_c) * -1)] + str_c
|
||||||
|
|
||||||
frame_filename = os.path.join(self.path_frames, f"frame-{num}.jpeg")
|
frame_filename = os.path.join(self.path_frames, f"frame-{num}.jpeg")
|
||||||
try: video_clip.save_frame(frame_filename, current_duration)
|
try: video_clip.save_frame(frame_filename, current_duration)
|
||||||
except Exception: return False
|
except Exception: return False
|
||||||
|
|
||||||
video_clip.close()
|
video_clip.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@bug_report
|
@bug_report
|
||||||
def unity_into_video(self, frames):
|
def unity_into_video(self, frames):
|
||||||
video_clip = VideoFileClip(self.video_file)
|
video_clip = VideoFileClip(self.video_file)
|
||||||
fps = 30.0 if video_clip.fps > 60.0 else video_clip.fps
|
fps = 30.0 if video_clip.fps > 60.0 else video_clip.fps
|
||||||
video_clip.close()
|
video_clip.close()
|
||||||
os.remove(self.video_file)
|
os.remove(self.video_file)
|
||||||
|
|
||||||
clip = ImageSequenceClip(list(map(lambda x: self.path_frames + "/" + x, frames)), fps=fps)
|
clip = ImageSequenceClip(list(map(lambda x: self.path_frames + "/" + x, frames)), fps=fps)
|
||||||
clip.write_videofile(self.video_file, logger=None)
|
clip.write_videofile(self.video_file, logger=None)
|
||||||
clip.close()
|
clip.close()
|
||||||
|
|
||||||
video_clip = VideoFileClip(self.video_file)
|
video_clip = VideoFileClip(self.video_file)
|
||||||
audio_clip = AudioFileClip(self.path + f"/{self.video_name}-audio.mp3")
|
audio_clip = AudioFileClip(self.path + f"/{self.video_name}-audio.mp3")
|
||||||
|
|
||||||
video_clip_with_audio = video_clip.with_audio(audio_clip)
|
video_clip_with_audio = video_clip.with_audio(audio_clip)
|
||||||
video_clip_with_audio.write_videofile(self.path + "/acs-" + self.video_name + ".mp4", logger=None)
|
video_clip_with_audio.write_videofile(self.path + "/acs-" + self.video_name + ".mp4", logger=None)
|
||||||
|
|
||||||
video_clip.close()
|
video_clip.close()
|
||||||
audio_clip.close()
|
audio_clip.close()
|
||||||
|
|
||||||
|
|
||||||
class Frame:
|
class Frame:
|
||||||
def __init__(self, filename, background):
|
def __init__(self, filename, background):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.background = background
|
self.background = background
|
||||||
|
|
||||||
def size(self):
|
def size(self):
|
||||||
image = Image.open(self.filename)
|
image = Image.open(self.filename)
|
||||||
width, height = image.size
|
width, height = image.size
|
||||||
image.close()
|
image.close()
|
||||||
|
|
||||||
return width, height
|
return width, height
|
||||||
|
|
||||||
def medium_color(self):
|
def medium_color(self):
|
||||||
img = Image.open(self.filename)
|
img = Image.open(self.filename)
|
||||||
width, height = img.size
|
width, height = img.size
|
||||||
|
|
||||||
pixels = img.load()
|
pixels = img.load()
|
||||||
r, g, b = [], [], []
|
r, g, b = [], [], []
|
||||||
|
|
||||||
for y in range(width):
|
for y in range(width):
|
||||||
for x in range(height):
|
for x in range(height):
|
||||||
p = pixels[x, y]
|
p = pixels[x, y]
|
||||||
r.append(p[0])
|
r.append(p[0])
|
||||||
g.append(p[1])
|
g.append(p[1])
|
||||||
b.append(p[2])
|
b.append(p[2])
|
||||||
|
|
||||||
r = sum(r) // len(r)
|
r = sum(r) // len(r)
|
||||||
g = sum(g) // len(g)
|
g = sum(g) // len(g)
|
||||||
b = sum(b) // len(b)
|
b = sum(b) // len(b)
|
||||||
|
|
||||||
img.close()
|
img.close()
|
||||||
return r, g, b
|
return r, g, b
|
||||||
|
|
||||||
def gradient(self, width, height, start_list, stop_list, is_horizontal_list):
|
def gradient(self, width, height, start_list, stop_list, is_horizontal_list):
|
||||||
def get_gradient(start, stop, width, height, is_horizontal):
|
def get_gradient(start, stop, width, height, is_horizontal):
|
||||||
if is_horizontal:
|
if is_horizontal:
|
||||||
return numpy.tile(numpy.linspace(start, stop, width), (height, 1))
|
return numpy.tile(numpy.linspace(start, stop, width), (height, 1))
|
||||||
else:
|
else:
|
||||||
return numpy.tile(numpy.linspace(start, stop, height), (width, 1)).T
|
return numpy.tile(numpy.linspace(start, stop, height), (width, 1)).T
|
||||||
|
|
||||||
result = numpy.zeros((height, width, len(start_list)))
|
result = numpy.zeros((height, width, len(start_list)))
|
||||||
for i, (start, stop, is_horizontal) in enumerate(zip(start_list, stop_list, is_horizontal_list)):
|
for i, (start, stop, is_horizontal) in enumerate(zip(start_list, stop_list, is_horizontal_list)):
|
||||||
result[:, :, i] = get_gradient(start, stop, width, height, is_horizontal)
|
result[:, :, i] = get_gradient(start, stop, width, height, is_horizontal)
|
||||||
|
|
||||||
Image.fromarray(numpy.uint8(result)).save(self.background, quality=95)
|
Image.fromarray(numpy.uint8(result)).save(self.background, quality=95)
|
||||||
|
|
||||||
def blur(self, width, height):
|
def blur(self, width, height):
|
||||||
image = Image.open(self.filename)
|
image = Image.open(self.filename)
|
||||||
image = image.filter(ImageFilter.GaussianBlur(6))
|
image = image.filter(ImageFilter.GaussianBlur(6))
|
||||||
|
|
||||||
part_width = width // 64
|
part_width = width // 64
|
||||||
part_height = height // 64
|
part_height = height // 64
|
||||||
|
|
||||||
image = image.crop((part_width * 10, part_height * 10, part_width * 54, part_height * 54))
|
image = image.crop((part_width * 10, part_height * 10, part_width * 54, part_height * 54))
|
||||||
image = image.resize((width, height))
|
image = image.resize((width, height))
|
||||||
image.save(self.background, quality=95)
|
image.save(self.background, quality=95)
|
||||||
|
|
||||||
image.close()
|
image.close()
|
||||||
|
|
||||||
def unity_image(self):
|
def unity_image(self):
|
||||||
im1 = Image.open(self.background)
|
im1 = Image.open(self.background)
|
||||||
im2 = Image.open(self.filename)
|
im2 = Image.open(self.filename)
|
||||||
|
|
||||||
mask = Image.new("L", im2.size, 0)
|
mask = Image.new("L", im2.size, 0)
|
||||||
draw = ImageDraw.Draw(mask)
|
draw = ImageDraw.Draw(mask)
|
||||||
draw.ellipse(((1, 1), (im2.size[0] - 1, im2.size[1] - 1)), fill=255)
|
draw.ellipse(((1, 1), (im2.size[0] - 1, im2.size[1] - 1)), fill=255)
|
||||||
mask_blur = mask.filter(ImageFilter.GaussianBlur(1))
|
mask_blur = mask.filter(ImageFilter.GaussianBlur(1))
|
||||||
|
|
||||||
im1.paste(im2, (0, 0), mask_blur)
|
im1.paste(im2, (0, 0), mask_blur)
|
||||||
im1.save(self.filename)
|
im1.save(self.filename)
|
||||||
|
|
||||||
im1.close()
|
im1.close()
|
||||||
im2.close()
|
im2.close()
|
||||||
mask.close()
|
mask.close()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue