cdur = step["clip_dur"] if (cstart + cdur) > vdur: print("%s not long enough: %s > %s" % (step["filename"], (cstart + cdur), vdur)) sys.exit() # make a clip if we are not taking the whole thing # print("%s, %s" % (step["clip_start"], step["clip_dur"])) if cstart > 0 or cdur < vdur: clip = clip.subclip(step["clip_start"], step["clip_start"] + step["clip_dur"]) clip = clip.set_position((0, 0)) clip = clip.set_start(step["start"]) nextStep = False if i >= steps - 1 else instructions[i + 1] # cross fade in if step["crossfade"] > 0 and step["fade_in"] > 0: clip = clip.crossfadein(step["fade_in"]) elif step["fade_in"] > 0: clip = clip.fadein(step["fade_in"]) # cross fade out if next clip is cross fading in if nextStep and nextStep["crossfade"] > 0 and nextStep["fade_in"] > 0: clip = clip.crossfadeout(nextStep["fade_in"]) elif step["fade_out"] > 0: clip = clip.fadeout(step["fade_out"]) # fade in/out audio if step["fade_in"] > 0: clip = clip.audio_fadein(step["fade_in"]) if step["fade_out"] > 0: clip = clip.audio_fadeout(step["fade_out"])
def main(argv): codecs = { 'libx264': 'mp4', 'mpeg4': 'mp4', 'rawvideo': 'avi', 'png': 'avi', 'libvorbis': 'ogv', 'libvpx': 'webm', } inputFolder = None outputFile = None codec = None take = None method = "compose" print_short_licence() try: opts, args = getopt.getopt( argv, "hf:o:c:t:r", ["help", "folder=", "output="] ) except getopt.GetoptError: print_help() sys.exit(2) for opt, arg in opts: if opt == '-h': print_help() sys.exit() if opt == '--licence': print_licence() sys.exit() elif opt in ("-f", "--folder"): inputFolder = arg elif opt in ("-o", "--output"): outputFile = arg elif opt in ("-c"): codec = arg elif opt in ("-t"): take = max(1, int(arg)) elif opt in ("-r"): method = "chain" if codec is not None and not codecs.has_key(codec): print('Unknown codec, use -h or --help to show help message.') sys.exit(2) if not outputFile: print('Output folder is not found, use -h or --help to show help message.') sys.exit(2) fileList = [] try: fileList = os.listdir(inputFolder) shuffle(fileList) if (take is not None): fileList = fileList[:take] print(fileList) except: print('Input folder not found, use -h or --help to show help message.') sys.exit(2) if (len(fileList) <= 0): print('No input video found, use -h or --help to show help message.') sys.exit(2) videos = [] wWidth = None hHeight = None clipList = [] for f in fileList: clip = VideoFileClip(os.path.join(inputFolder, f)) clipList.append(clip) cwWidth, chHeight = clip.size wWidth = max(wWidth, cwWidth) hHeight = max(hHeight, chHeight) for clip in clipList: # clip.set_fps(24) if method == "chain": clip = clip.resize(width=wWidth, height=hHeight) clip = clip.crossfadein(0.5) videos.append(clip) result = concatenate_videoclips(videos, method=method, padding=0.5) result.write_videofile(outputFile, codec=codec)