question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Slide In Effect with Images

See original GitHub issue
        clips = []
        for _, name in urls:
            img = name.replace("webp", "jpg")
            Image.open(name).convert("RGB").save(img)
            clips.append(ImageClip(img).set_duration(3))

        video = CompositeVideoClip([
            clip.fx(transfx.slide_out, duration=0.4, side="left")
            for clip in clips
        ])
        video.write_videofile(file_name,
            codec="libx264", audio_codec="aac",
            preset="ultrafast", fps=24, logger=None,
            ffmpeg_params=[
                "-vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2",
                "-pix_fmt", "yuv420p"
            ]
        )

this is my code. im trying to make a slideshow from these images, but the issue is that the result is not what it should be. every clip is on top of each other and trasnition is not working, it just do the effect to a black screen: here’s the result i get:

https://user-images.githubusercontent.com/69367859/175075544-e9b56cb8-5af6-40ed-b2a4-97714941ef65.mp4

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:49 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
MohamedAbdultawabcommented, Jul 1, 2022

I believe the problem is with your ordering of the operations you are performing on each clip Check the following snippet and the following output

PS. I’ve also added a set_position call to fix the positioning of the unfit images

# Create image clips and resize them to same size so no black borders gets added

EFFECT_DURATION = 0.3
CLIP_DURATION = 3.3

clip1 = ImageClip("../experiments/1.jpeg").set_duration(CLIP_DURATION)
clip2 = ImageClip("../experiments/2.jpeg").set_duration(CLIP_DURATION)
clip3 = ImageClip("../experiments/3.jpeg").set_duration(CLIP_DURATION)
clips = [clip1, clip2, clip3]

# For the first clip we will need it to start from the beginning and only add
# slide out effect to the end of it
first_clip = CompositeVideoClip(
    [
        clips[0]
        .set_pos("center")
        .fx(transfx.slide_out, duration=EFFECT_DURATION, side="left")
    ]
).set_start((CLIP_DURATION - EFFECT_DURATION) * 0)

# For the last video we only need it to start entring the screen from the left going right
# but not slide out at the end so the end clip exits on a full image not a partial image or black screen
last_clip = (
    CompositeVideoClip(
        [
            clips[-1]
            .set_pos("center")
            .fx(transfx.slide_in, duration=EFFECT_DURATION, side="right")
        ]
        # -1 because we start with index 0 so we go all the way up to array length - 1
    )
    .set_start((CLIP_DURATION - EFFECT_DURATION) * (len(clips) - 1))
    .fx(transfx.slide_out, duration=EFFECT_DURATION, side="left")
)

videos = (
    [first_clip]
    # For all other clips in the middle, we need them to slide in to the previous clip and out for the next one
    + [
        (
            CompositeVideoClip(
                [
                    clip.set_pos("center").fx(
                        transfx.slide_in, duration=EFFECT_DURATION, side="right"
                    )
                ]
            )
            .set_start((CLIP_DURATION - EFFECT_DURATION) * idx)
            .fx(transfx.slide_out, duration=EFFECT_DURATION, side="left")
        )
        # set start to 1 since we start from second clip in the original array
        for idx, clip in enumerate(clips[1:-1], start=1)
    ]
    + [last_clip]
)

video = CompositeVideoClip(videos)
video.write_videofile(
    "2_final_clip.mp4",
    codec="libx264",
    audio_codec="aac",
    preset="ultrafast",
    fps=24,
    threads=24,
    ffmpeg_params=["-vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2", "-pix_fmt", "yuv420p"],
)

https://user-images.githubusercontent.com/19710525/176975569-40f0d587-e8e0-4928-bb35-82e65e517d95.mp4

1reaction
stefanodvxcommented, Jun 29, 2022

it works like this, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Animate a picture on your slide
In this example, we'll animate two pictures: Select the first picture. On the Animations tab, select an animation effect. For example, select Fly...
Read more >
How To Create Image Hover Overlay Slide Effects
Learn how to create image overlay hover slide effects. Image Overlay Slide. Learn how to create a sliding overlay effect to an image,...
Read more >
21 Cool Slider Animation Effects
21 Cool Slider Animation Effects ... Image sliders are a common feature for websites. They are an incredibly versatile design tool that allow...
Read more >
46 Image Slider - Content Carousels Design Inspiration
Handpicked collection of image slider design inspiration. ✓ GIF preview ✓ HTML CSS copy paste code. ... Bay Window Style Image Slider With...
Read more >
CSS Slide-In Image
This page uses CSS animations to create slide-in images. CSS animations are a standards-compliant way of creating marquees and other animated effects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found