vapory icon indicating copy to clipboard operation
vapory copied to clipboard

How to get a scene with a movie?

Open eyildiz-ugoe opened this issue 7 years ago • 6 comments

Hi, I have the following (from the tutorial):

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

# set the light source, background and surface
light = LightSource([10, 15, -20], [1.3, 1.3, 1.3])

# synthetic objects to be displayed
sphere1 = Sphere([0, 0, 0], 2.0, Pigment('color', [0, 0, 1]),
                                           Finish('phong', 0.8))
sphere2 =Sphere([-3, 0, 0], 1.0, Texture('T_Ruby_Glass'),
                Interior('ior',2))

# scene description
scene = Scene( Camera("location", [0, 0, -10], "look_at", [0, 0, 0]),
               objects = [sphere1, sphere2, light],
               included=["glass.inc"] )

# render command
scene.render("objects.png", width=800, height=480 )


# we would like to embed a video stream as a background in our scene
def embed_in_scene(image):

    ffmpeg_write_image("__temp__.png", image)
    screen = Box([0, 0, 0], [1, 1, 0], Texture(
                    Pigment( ImageMap('png', '"__temp__.png"', 'once')),),
                 'scale', [10, 10, 10])
    new_scene = scene.add_objects([screen])
    return new_scene.render(width=800, height=480, antialiasing=0.001)


clip = (VideoFileClip("scenes/dis1.mp4") # File containing the original video
        .subclip(0, 1) # cut between t=23 and 47 seconds
        .fl_image(embed_in_scene))  # <= The magic happens

clip.write_videofile("scenes/dis1-edited.mp4",bitrate='8000k')

However I don't get the video fullscreen in the background. I want the whole scene to be the video, added the objects at the locations specified.

How to achieve this?

eyildiz-ugoe avatar Jul 02 '18 11:07 eyildiz-ugoe

Like this?


from vapory import *
from PIL import Image
from moviepy.editor import VideoClip

def scene(t):
   # set the light source, background and surface
    light = LightSource([10, 15, -20], [1.3, 1.3, 1.3])

    # synthetic objects to be displayed
    sphere1 = Sphere([0, 0, 0], 2.0, Pigment('color', [0, 0, 1]),
                                           Finish('phong', 0.8))
    sphere2 =Sphere([-3, 0, 0], 1.0, Texture('T_Ruby_Glass'),
                Interior('ior',2))
    return Scene( Camera("location", [0, 0, -10], "look_at", [0, 0, 0]),
               objects = [sphere1, sphere2, light],
               included=["glass.inc"] )

filename = 'myfile.mp4'

def make_frame(t):
    return scene(t).render(width = 400, height=600, antialiasing=0.001)

VideoClip(make_frame, duration=7).write_videofile(filename,fps=30)

NGeorgescu avatar Jul 04 '18 12:07 NGeorgescu

@NGeorgescu This does not show the movie in full screen. Even though I used your centralized view I got such a movie:

1

As you can see, the movie is still small in the background and not what I want. I'd like to have that movie running in the background being the whole screen.

eyildiz-ugoe avatar Jul 04 '18 13:07 eyildiz-ugoe

I don't understand what I'm looking at in your screenshot. You want a movie inside your movie?

NGeorgescu avatar Jul 04 '18 14:07 NGeorgescu

Yes, that's what the code I shared first all above is doing in the first place. There is a frame/box in which a movie is playing. I want that frame/box to be fullscreen. Very simple.

eyildiz-ugoe avatar Jul 04 '18 14:07 eyildiz-ugoe

I believe what you have here is more a geometry problem, you will have to orient the box right in front of the camera and at the right distance (or sight size) so it covers the whole camera field. It's all about trials and errors.

Zulko avatar Jul 04 '18 14:07 Zulko

@Zulko You're right, it boils down to that eventually. I mean, why does the box appear in weird location like that in the first place? The camera looks at the sphere how it supposed to, however the box not. That means the box is misplaced.

eyildiz-ugoe avatar Jul 04 '18 14:07 eyildiz-ugoe