4

我正在使用 Vapory,它是 Povray 的包装 Python 库。它允许使用 Python 函数来操作典型的 Povray 操作。

我想在视频流的每一帧中叠加 3D 模型。在 Vapory 中执行此操作的方法如下:

from vapory import *
from moviepy.video.io.ffmpeg_writer import ffmpeg_write_image

light = LightSource([10, 15, -20], [1.3, 1.3, 1.3])
wall = Plane([0, 0, 1], 20, Texture(Pigment('color', [1, 1, 1])))
ground = Plane( [0, 1, 0], 0,
                Texture( Pigment( 'color', [1, 1, 1]),
                         Finish( 'phong', 0.1,
                                 'reflection',0.4,
                                 'metallic', 0.3)))
sphere1 = Sphere([-4, 2, 2], 2.0, Pigment('color', [0, 0, 1]),
                                           Finish('phong', 0.8,
                                                  'reflection', 0.5))
sphere2 =Sphere([4, 1, 0], 1.0, Texture('T_Ruby_Glass'),
                Interior('ior',2))

scene = Scene( Camera("location", [0, 5, -10], "look_at", [1, 3, 0]),
               objects = [ ground, wall, sphere1, sphere2, light],
               included=["glass.inc"] )


def embed_in_scene(image):

    ffmpeg_write_image("__temp__.png", image)
    image_ratio = 1.0*image.shape[1]/image.shape[0]
    screen = Box([0, 0, 0], [1, 1, 0], Texture(
                    Pigment( ImageMap('png', '"__temp__.png"', 'once')),
                    Finish('ambient', 1.2) ),
                 'scale', [10, 10/image_ratio,1],
                 'rotate', [0, 20, 0],
                 'translate', [-3, 1, 3])
    new_scene = scene.add_objects([screen])
    return new_scene.render(width=800, height=480, antialiasing=0.001)

clip = (VideoFileClip("bunny.mp4") # File containing the original video
        .subclip(23, 47) # cut between t=23 and 47 seconds
        .fl_image(embed_in_scene)  # <= The magic happens
        .fadein(1).fadeout(1)
        .audio_fadein(1).audio_fadeout(1))
clip.write_videofile("bunny2.mp4",bitrate='8000k')

视频流的结果如下:

在此处输入图像描述

然而,我想要的是电影盒是整个场景,并且球体保持在它们所在的位置。第一个想法是从代码中删除旋转功能,它确实有效,但是我仍然无法将电影帧拉伸到实际场景的末端角落。

有什么想法吗?

编辑:所以我能够移动相机,将物体移到中心。但是我仍然无法将电影全屏显示。这是因为相机对象被告知要看向坐标,我不知道相机应该指向什么坐标,以便全屏获取图片。看:

在此处输入图像描述

4

0 回答 0