簡體   English   中英

使用moviepy在半圓路徑上顯示gif VideoClips

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

我正在嘗試在基本視頻的基礎上制作大約 6 到 7 個 gif 動畫剪輯的集合。 這些動畫圖標顯示在視頻中心的半圓上。 我正在尋找編寫此邏輯的最佳方法,但在此停留了一段時間。 任何幫助深表感謝。

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))])

我不知道我是否理解您嘗試做的事情,但應該是

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)

編輯:

如果你想在圓形路徑上繪制,那么你可能需要使用sin()cos()來計算位置。

我使用matplotlib來顯示位置。

它為半徑為 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