加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
video.py 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
jjj1112 提交于 2020-02-14 17:07 . upload
from moviepy.editor import ImageSequenceClip
import argparse
import os
IMAGE_EXT = ['jpeg', 'gif', 'png', 'jpg']
def main():
parser = argparse.ArgumentParser(description='Create driving video.')
parser.add_argument(
'image_folder',
type=str,
default='',
help='Path to image folder. The video will be created from these images.'
)
parser.add_argument(
'--fps',
type=int,
default=60,
help='FPS (Frames per second) setting for the video.')
args = parser.parse_args()
#convert file folder into list firltered for image file types
image_list = sorted([os.path.join(args.image_folder, image_file)
for image_file in os.listdir(args.image_folder)])
image_list = [image_file for image_file in image_list if os.path.splitext(image_file)[1][1:].lower() in IMAGE_EXT]
#two methods of naming output video to handle varying environemnts
video_file_1 = args.image_folder + '.mp4'
video_file_2 = args.image_folder + 'output_video.mp4'
print("Creating video {}, FPS={}".format(args.image_folder, args.fps))
clip = ImageSequenceClip(image_list, fps=args.fps)
try:
clip.write_videofile(video_file_1)
except:
clip.write_videofile(video_file_2)
if __name__ == '__main__':
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化