Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get a scene with a movie? #45

Open
eyildiz-ugoe opened this issue Jul 2, 2018 · 6 comments
Open

How to get a scene with a movie? #45

eyildiz-ugoe opened this issue Jul 2, 2018 · 6 comments

Comments

@eyildiz-ugoe
Copy link

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?

@NGeorgescu
Copy link
Contributor

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)

@eyildiz-ugoe
Copy link
Author

eyildiz-ugoe commented Jul 4, 2018

@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.

@NGeorgescu
Copy link
Contributor

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

@eyildiz-ugoe
Copy link
Author

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.

@Zulko
Copy link
Owner

Zulko commented Jul 4, 2018

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.

@eyildiz-ugoe
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants