import os
import sys
from moviepy.editor import ImageSequenceClip

imageList = []

def makeVideo(fileid, videopath):
    global imageList
    clip = ImageSequenceClip(imageList, fps = 25)
    clip.write_videofile("%s\\%s.mp4" % (videopath, fileid), codec="libx264", bitrate="200000")

def dealAllPng(rootdir):
    for root,dirs,files in os.walk(rootdir):
        # for dir in dirs:
        #     print(os.path.join(root,dir))
        for file in files:
            picpath = os.path.join(root,file)
            print("dealAllPng: " + picpath)
            imageList.append(picpath)


if __name__ == '__main__':
    paramNum = len(sys.argv)
    if paramNum != 2:
        print("param err! please input fileid.")
        exit()

    # sys.argv[0] 表示脚本名
    fileid = int(sys.argv[1])      #csv文件编号  详见 fileinfo.js
    filepath =  r"pic\\%d" % fileid
    videopath =  r"video"

    print("dealAllPng start !")
    dealAllPng(filepath)

    print("============ makeVideo ============")
    makeVideo(fileid, videopath)
