代码拉取完成,页面将自动刷新
同步操作将从 席理加/time-lapse 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import os, sys
import yaml
from moviepy.editor import *
dirname, filename = os.path.split(os.path.abspath(sys.argv[0]))
class ControlDefine:
def __init__(self,
capturesdir = "D:\\time-lapse\\output",
targetdir = "D:\\time-lapse\\output",
targetfile = "timelapse.gif",
mergestep = 1):
self.capturesdir = capturesdir # 延时图像存储位置
self.targetdir = targetdir # gif输出位置
self.targetfile = targetfile # gif输出文件名
self.mergestep = mergestep # 延时输出速度,默认为1,即输出gif的延时间隔与抓取间隔一致,2为抓取间隔的1倍
def loadConfig(configfile, withprint = False):
if os.path.exists(configfile):
configdata = yaml.load(open(configfile, 'r'))
capturesdir = configdata['capturesdir']
targetdir = configdata['targetdir']
targetfile = configdata['targetfile']
mergestep = configdata['mergestep']
configobject = ControlDefine(capturesdir, targetdir, targetfile, mergestep)
else:
configobject = ControlDefine()
if withprint:
print(configobject.capturesdir, configobject.targetdir, configobject.targetfile, configobject.mergestep)
return configobject
print("Starting make movies to gif")
control = loadConfig("make-gif.yml", True)
def mergeCapture(targetdir, targetvideo, srcdir, speed):
# output目录不存在则创建
if not(os.path.exists(targetdir)):
os.mkdir(targetdir)
filepath = targetdir + "/" + targetvideo
lsdir = os.listdir(srcdir)
files = [i for i in lsdir if os.path.isfile(os.path.join(srcdir,i))]
files.sort(reverse=False)
if files:
for item in files:
if item.endswith('.mp4'):
print(item)
gifitem = item[:-4] + ".gif"
item = os.path.join(srcdir, item)
# 512 * 384 标清 1920, 1080 960-+256=714,1216, 540-+192=348,732
source = VideoFileClip(item)
duration = source.duration
print(duration)
print(source.get_frame(0).shape)
x = 1920 / 2 - 1
y = 1080 / 2 - 1
# 向右平移256像素
x += 128
y -= 0 # 192, 0
x1 = int(x - 512 / 2)
x2 = int(x + 512 / 2)
y1 = int(y - 384 / 2)
y2 = int(y + 384 / 2)
print(x1, x2, y1, y2)
target = VideoClip(lambda t: source.get_frame(t)[y1:y2][:,x1:x2], duration=duration).set_fps(source.fps)
targetpath = os.path.join(targetdir, gifitem)
target.write_gif(targetpath,fps=(source.fps * 0.125))
target.close()
mergeCapture(control.targetdir, control.targetfile, control.capturesdir, control.mergestep)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。