makevideo.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import os
  2. import sys
  3. from moviepy.editor import ImageSequenceClip
  4. imageList = []
  5. def makeVideo(fileid, videopath):
  6. global imageList
  7. clip = ImageSequenceClip(imageList, fps = 25)
  8. clip.write_videofile("%s\\%s.mp4" % (videopath, fileid), codec="libx264", bitrate="200000")
  9. def dealAllPng(rootdir):
  10. for root,dirs,files in os.walk(rootdir):
  11. # for dir in dirs:
  12. # print(os.path.join(root,dir))
  13. for file in files:
  14. picpath = os.path.join(root,file)
  15. print("dealAllPng: " + picpath)
  16. imageList.append(picpath)
  17. if __name__ == '__main__':
  18. paramNum = len(sys.argv)
  19. if paramNum != 2:
  20. print("param err! please input fileid.")
  21. exit()
  22. # sys.argv[0] 表示脚本名
  23. fileid = int(sys.argv[1]) #csv文件编号 详见 fileinfo.js
  24. filepath = r"pic\\%d" % fileid
  25. videopath = r"video"
  26. print("dealAllPng start !")
  27. dealAllPng(filepath)
  28. print("============ makeVideo ============")
  29. makeVideo(fileid, videopath)