Я работаю над проектом обработки видео, и мне нужно добавить 3D-эффект, похожий на перелистывание страниц в книге, используя python с несколькими фотографиями. Я использую moviepy и прошел Поворот изображения вокруг своей оси X . Однако я не могу сшить несколько (скажем, 2) фотографий, используя вышеуказанное решение. вращается только одна фотография, а другая - как слайд. Кроме того, его обработка занимает слишком много времени на моей маме c. Есть ли другое решение проблемы или какие-либо предложения в моем коде, чтобы исправить это?
from moviepy.editor import concatenate, ImageClip, VideoClip
from vapory import *
img_path1 = 'IMG_4936.JPG'
img_path2 = 'IMG_4935.JPG'
list = [img_path2,img_path1]
img_clip = ImageClip(img_path1)
W, H = img_clip.w, img_clip.h
AR = 1.0*W/H
screensize = (W,H)
# Set rotation rate by defining the period (in seconds) for 360 deg. revolution
t_rev = 2.0
total_duration = 9.0
t_half = 1.0 # The time required for a half revolution
t_still = 1.0 # How long (in seconds) to hold the half rotated image still
# Static POV-Ray objects
cam = Camera('location', [ 0, 0, -1],
'look_at', [ 0, 0, 0])
light = LightSource([0, 0, -1]) # Light at camera location
bg = Background('color', [0, 0, 0]) # Black background
slides =[]
f_slides=[]
count=-1
for i in list:
count += 1
print("path",i)
start_time = time.time()
print("before scene: ", count)
def scene(t):
print("inside scene: ",count)
""" Returns the scene at time 't' (in seconds) """
s = Scene(camera = cam, objects = [light, bg])
# Add POV-Ray box with image textured on it
s = s.add_objects([
Box([0, 0, 0],
[W, H, 0],
Texture(Pigment(ImageMap('"{}"'.format(i), 'once')),
Finish('ambient', 1.0)),
'translate', [-0.5, -0.5, 0],
'scale', [AR, 1, 0],
'rotate', [0, (360/t_rev)*t, 0])]) # Can change axis of rotation here
print("format path: ", i)
return s
def make_frame(t):
return scene(t).render(width=W, height=H, antialiasing=0.1)
still_1 = VideoClip(make_frame).to_ImageClip(t=count*2*t_rev).set_duration(t_still)
half_1 = VideoClip(make_frame).subclip(count*2*t_rev, count*2*t_rev+t_half)
still_2 = VideoClip(make_frame).to_ImageClip(t=count*2*t_rev+t_half).set_duration(t_still)
half_2 = VideoClip(make_frame).subclip(count*2*t_rev+t_half, count*2*t_rev+t_rev)
final_clip = concatenate([still_1, half_1, still_2, half_2 ])
f_slides.append(final_clip)
final_clip_f = concatenate_videoclips([j for j in f_slides],method="compose").set_duration(total_duration)
final_clip_f.write_videofile("pic_rot.mp4", fps=12, ffmpeg_params=['-movflags', '+faststart'])
end_time = time.time()
print("Total time for creating video = {}".format(end_time - start_time))
Кроме того, функция make_frame и функция сцены вызывается многократно. Я не понимаю это повторение.