简体   繁体   English

使用moviepy在半圆路径上显示gif VideoClips

[英]Displaying gif VideoClips on a half circle path with moviepy

I am trying to compose a collection of about 6 to 7 gif aniated clips on top of a base video.我正在尝试在基本视频的基础上制作大约 6 到 7 个 gif 动画剪辑的集合。 These animated icons are shown on along a half circle at the center of the video.这些动画图标显示在视频中心的半圆上。 I am figuring out the best way to write this logic, but stuck at this for a while.我正在寻找编写此逻辑的最佳方法,但在此停留了一段时间。 Any help is much appreciated.任何帮助深表感谢。

positions = [
            [(200,200)], 
            [(200,300)],
            [(200,400)],
            [(200,500)],
            [(200,600)],
            [(200,700)],
            [(200,800)],
            [(200,900)],
            [(200,1000)]
            
            ]
    
clip = (VideoFileClip(f"{DIRECTORY+wd}.gif")
                .set_start(0)
                .set_duration(video_clip.duration)
                .set_position(positions[l]))
clips.append(clip)

        
final_clip = concatenate_videoclips([clips[i] for i in range(len(clips))])

I don't know if I understand what you try to do but it should be rather我不知道我是否理解您尝试做的事情,但应该是

positions = [
    (200, 200), 
    (200, 300),
    (200, 400),
    (200, 500),
    (200, 600),
    (200, 700),
    (200, 800),
    (200, 900),
    (200, 1000)
]
    
clips = []

for pos in positions:
    clip = (VideoFileClip(f"{DIRECTORY+wd}.gif")
                .set_start(0)
                .set_duration(video_clip.duration)
                .set_position(pos))
    clips.append(clip)
        
final_clip = concatenate_videoclips(clips)

EDIT:编辑:

And if you want to draw on circle path then you may need to use sin() , cos() to calculate positions.如果你想在圆形路径上绘制,那么你可能需要使用sin()cos()来计算位置。

I used matplotlib to display positions.我使用matplotlib来显示位置。

It calculates 36 positions (every 10 degrees) for circle with radius 10, and center (50,50)它为半径为 10 的圆和中心 (50,50) 计算 36 个位置(每 10 度)

from math import sin, cos, radians

positions = []

r = 10
center_x = 50
center_y = 50

for angle in range(0, 360, 10):
    x = center_x + sin(radians(angle)) * r
    y = center_y + cos(radians(angle)) * r
    positions.append( (x, y) )

# ---

import matplotlib.pyplot as plt

data_x = [pos[0] for pos in positions]
data_y = [pos[1] for pos in positions]

plt.scatter(data_x, data_y)
plt.show()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM