ChinaFFmpeg

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 9753|回复: 1

[Linux] ffmpeg里如何实现cubic-bezier曲线的效果

[复制链接]
发表于 2018-10-13 16:51:10 | 显示全部楼层 |阅读模式
本帖最后由 radrupt 于 2018-10-14 22:31 编辑

效果如下
http://cubic-bezier.com/#1,.06,.66,1.04
回复

使用道具 举报

 楼主| 发表于 2018-10-14 22:32:45 | 显示全部楼层
这个问题目前已经搞定了
使用moviepy
[Python] 纯文本查看 复制代码
import numpy as np
import bezier
from moviepy.editor import *
from moviepy.video.tools.segmenting import findObjects

# WE CREATE THE TEXT THAT IS GOING TO MOVE, WE CENTER IT.

screensize = (960,544)
txtClip = TextClip('王迪',color='white', font="MicrosoftYaHei",
                   kerning = 5, fontsize=100)
cvc = CompositeVideoClip( [txtClip.set_pos('center')],
                        size=screensize)

# THE NEXT FOUR FUNCTIONS DEFINE FOUR WAYS OF MOVING THE LETTERS
print ( TextClip.list("font") )
nodes1 = np.asfortranarray([
  [0, 0.25, .25, 1],
  [0, 0.1, 1, 1],
])
# 三阶bezier curve
curve1 = bezier.Curve(nodes1, degree=3)

# for t in range(0,10):
#   print(t,curve1.evaluate(t/10))

# 字符当前在屏幕上的位置,第几个字符,字符总数
def moveUp(screenpos,i,nletters):
    v = np.array([0,1])
    s = 1
    d = lambda t : 1 if t <=s else 0
    return lambda t: screenpos +d(t)*v*(320*(1-curve1.evaluate(t/s)[1][0]))

# WE USE THE PLUGIN findObjects TO LOCATE AND SEPARATE EACH LETTER
letters = findObjects(cvc) # a list of ImageClips


# WE ANIMATE THE LETTERS

def moveLetters(letters, funcpos):
    return [ letter.set_pos(funcpos(letter.screenpos,i,len(letters)))
              for i,letter in enumerate(letters)]

# 遍历函数数组,将灭一个函数赋值给CompositeVideoClip, 
clip = CompositeVideoClip( moveLetters(letters,moveUp),
                              size = screensize).subclip(0,5)

# WE CONCATENATE EVERYTHING AND WRITE TO A FILE

clip.write_videofile('./new.mp4',fps=25,codec='mpeg4')
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|Archiver|ChinaFFmpeg

GMT+8, 2024-12-27 12:53 , Processed in 0.049945 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表