Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
personal:portfolio:vcat-script [2019/01/02 14:09] antonello created |
personal:portfolio:vcat-script [2019/01/02 14:52] antonello Allowed decimal of seconds |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Vcat script: cut & merge video segments ====== | ====== Vcat script: cut & merge video segments ====== | ||
- | A Python script that wraps [[https:// | + | A Python script that wraps [[https:// |
Tested with mp4 (h.264/mp3) videos all with the same resolution. | Tested with mp4 (h.264/mp3) videos all with the same resolution. | ||
- | Use it with `vcat -i inputfile1, | + | Use it with '' |
+ | |||
+ | <code python> | ||
+ | # | ||
+ | |||
+ | import sys, getopt, re | ||
+ | |||
+ | def printerror(errormsg): | ||
+ | print(" | ||
+ | print(" | ||
+ | print(" | ||
+ | print(" | ||
+ | |||
+ | try: | ||
+ | from moviepy.editor import VideoFileClip, | ||
+ | except ImportError: | ||
+ | | ||
+ | | ||
+ | |||
+ | def main(argv): | ||
+ | inputfiles_arg = '' | ||
+ | outputfile = '' | ||
+ | try: | ||
+ | opts, args = getopt.getopt(argv," | ||
+ | except getopt.GetoptError as err: | ||
+ | printerror(str(err)) | ||
+ | sys.exit(2) | ||
+ | for opt, arg in opts: | ||
+ | if opt == ' | ||
+ | printerror("" | ||
+ | sys.exit() | ||
+ | elif opt in (" | ||
+ | inputfiles_arg = arg | ||
+ | elif opt in (" | ||
+ | outputfile = arg | ||
+ | if outputfile =='': | ||
+ | printerror(" | ||
+ | |||
+ | iFiles = inputfiles_arg.split(',' | ||
+ | |||
+ | clips=[] | ||
+ | for iFile in iFiles: | ||
+ | subclip = re.search(r" | ||
+ | if subclip is None: | ||
+ | clips.append(VideoFileClip(iFile)) | ||
+ | else: | ||
+ | dims = subclip.group(1).split(' | ||
+ | if len(dims) != 2: | ||
+ | printerror(" | ||
+ | iFile = iFile.replace(" | ||
+ | clips.append(VideoFileClip(iFile).subclip(float(dims[0]), | ||
+ | |||
+ | f = concatenate_videoclips(clips) | ||
+ | f.write_videofile(outputfile) | ||
+ | |||
+ | |||
+ | if __name__ == " | ||
+ | | ||
- | #!/usr/ | + | </code> |
- | + | ||
- | import sys, getopt, re | + | |
- | + | ||
- | def printerror(errormsg): | + | |
- | print(" | + | |
- | print(" | + | |
- | print(" | + | |
- | print(" | + | |
- | + | ||
- | try: | + | |
- | from moviepy.editor import VideoFileClip, | + | |
- | except ImportError: | + | |
- | | + | |
- | | + | |
- | + | ||
- | def main(argv): | + | |
- | inputfiles_arg = '' | + | |
- | outputfile = '' | + | |
- | try: | + | |
- | opts, args = getopt.getopt(argv," | + | |
- | except getopt.GetoptError as err: | + | |
- | printerror(str(err)) | + | |
- | sys.exit(2) | + | |
- | for opt, arg in opts: | + | |
- | if opt == ' | + | |
- | printerror("" | + | |
- | sys.exit() | + | |
- | elif opt in (" | + | |
- | inputfiles_arg = arg | + | |
- | elif opt in (" | + | |
- | outputfile = arg | + | |
- | if outputfile =='': | + | |
- | printerror(" | + | |
- | + | ||
- | iFiles = inputfiles_arg.split(',' | + | |
- | + | ||
- | clips=[] | + | |
- | for iFile in iFiles: | + | |
- | subclip = re.search(r" | + | |
- | if subclip is None: | + | |
- | clips.append(VideoFileClip(iFile)) | + | |
- | else: | + | |
- | dims = subclip.group(1).split(' | + | |
- | if len(dims) != 2: | + | |
- | printerror(" | + | |
- | iFile = iFile.replace(" | + | |
- | clips.append(VideoFileClip(iFile).subclip(int(dims[0]), | + | |
- | + | ||
- | f = concatenate_videoclips(clips) | + | |
- | f.write_videofile(outputfile) | + | |
- | + | ||
- | + |