def video():
    clip1 = ImageClip("./simplesignage/manager/static/content/c1/Lake-Chelan.jpeg")
    clip1.set_fps(15) # framerate
    clip1 = clip1.set_end(15) # duration: 0 to n=15 seconds
    #clip1.resize(height=1080) # height of the clip
    clip2 = ImageClip("./simplesignage/manager/static/content/c2/Mount-Rainier.jpg")
    clip2 = clip2.set_end(10)
    #clip2.resize(height=1080)
    clip2.set_fps(15)
    clip3 = ImageClip("./simplesignage/manager/static/content/c3/mt-stuart.jpg")
    clip3 = clip3.set_end(10)
    #clip3.resize(height=1080)
    clip3.set_fps(15)
    clip4 = VideoFileClip("./simplesignage/manager/static/content/c9/ENBjQKJ_-_Imgur.mp4")

    final = concatenate_videoclips(clips=[clip1, clip4, clip2, clip3], method="compose")
    final.resize(height=1080)
    final.write_videofile(filename="./video.mp4", fps=15, audio=False)#, progress_bar=True)
Exemple #2
0
def compile_video(show_items,
                  output_path='./manager/static/shows/',
                  frame_rate=30):
    # items: {item 1, item 2, ...}
    print("Compiling Video...")

    name = "Show_%d.mp4" % (int(time.time()))
    print(name)

    if output_path.rindex('/') == len(output_path) - 1:
        showPath = "%s%s" % (output_path, name)
    else:
        showPath = "%s/%s" % (output_path, name)

    video_clips = [
    ]  # clip array, will use a SHIT LOAD of memory, you're editing a video...

    for item in show_items:
        if os.path.isfile(item.file):
            # debug params
            #print("file: ", item.file, "Exists")
            #print(os.listdir(item.file[0:item.file.rindex('/')+1]))

            if ".mp4" in item.file.lower():
                # Use VideoFileClip class
                vclip = VideoFileClip(item.file)
                # resize the height to 1080p
                vclip = vclip.resize(height=1080)
                # then see if it is too wide
                (w, h) = vclip.size
                if w > 1920:
                    vclip = vclip.resize(width=1920)
                    print("resize width")
                video_clips.append(vclip)

            elif ".gif" in item.file.lower():
                # Use VideoFileClip class
                vclip = VideoFileClip(item.file)
                # resize the height to 1080p
                vclip = vclip.resize(height=1080)
                # then see if it is too wide
                (w, h) = vclip.size
                if w > 1920:
                    vclip = vclip.resize(width=1920)
                    print("resize width")
                #vclip.set_fps(frame_rate)
                for gi in range(0, item.gifIteration):
                    video_clips.append(vclip)

            elif ".png" or ".jpg" in item.file.lower():
                # Use ImageClip class
                img = ImageClip(item.file)
                # resize the height to 1080p
                img = img.resize(height=1080)
                # then if it is too wide, resize to 1920 wide
                (w, h) = img.size
                if w > 1920:
                    img = img.resize(width=1920)
                    print("resize width")
                #img.resize(height=1080)
                img = img.set_end(int(item.displayTime))
                #img.set_fps(frame_rate)
                video_clips.append(img)

            else:
                print("unsupported file type: ",
                      item.file.lower()[item.file.rindex('.'):len(item.file)])
        else:
            print("File: ", item.file, "Does Not Exist")

        #elif ".pdf" in item.file.lower(): # pdf are taken care of at upload
        #    print("PDF: ", item.file)
        # pause last frame and fade out/in?

    final_clip = concatenate_videoclips(video_clips, method="compose")
    final_clip.resize(height=1080)
    final_clip.write_videofile(filename=showPath,
                               fps=frame_rate,
                               audio=False,
                               threads=4)
    return showPath, name