Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
personal:portfolio:vcat-script [2019/01/02 14:09]
antonello created
personal:portfolio:vcat-script [2019/01/02 14:52] (current)
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://zulko.github.io/moviepy/|moviepy]] (that in turn wraps `ffmpeg`) to allow mixing and merging segments from other videos in a final video.+A Python script that wraps [[https://zulko.github.io/moviepy/|moviepy]] (that in turn wraps ''ffmpeg'') to allow mixing and merging segments from other videos in a final video. 
 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,inputfile2[start-end],... -o <outputfile>`+Use it with ''vcat -i inputfile1,inputfile2[start-end],... -o <outputfile>'' 
 + 
 +<code python> 
 +#!/usr/bin/python3 
 + 
 +import sys, getopt, re 
 + 
 +def printerror(errormsg): 
 +  print("*** vcat - concatenate video segments using moviepy ***\n"
 +  print("ERROR:", errormsg,"\n"
 +  print("Usage: vcat -i inputfile1,inputfile2[start-end],... -o <outputfile>"
 +  print("Optional start and end points should be given in seconds. If files have spaces, they should be quoted (e.g. \"input file.mp4[5-30]\")."
 + 
 +try: 
 + from moviepy.editor import VideoFileClip, concatenate_videoclips 
 +except ImportError: 
 + printerror("You don't seem to have moviepy installed. Install it with `pip install moviepy`."
 + exit(1) 
 + 
 +def main(argv): 
 +    inputfiles_arg = '' 
 +    outputfile = '' 
 +    try: 
 +        opts, args = getopt.getopt(argv,"hi:o:",["input=","output="]) 
 +    except getopt.GetoptError as err: 
 +        printerror(str(err)) 
 +        sys.exit(2) 
 +    for opt, arg in opts: 
 +        if opt == '-h': 
 +            printerror(""
 +            sys.exit() 
 +        elif opt in ("-i", "--input"): 
 +            inputfiles_arg = arg 
 +        elif opt in ("-o", "--output"): 
 +            outputfile = arg 
 +    if outputfile =='': 
 +        printerror("Output file not specified"
 +     
 +    iFiles = inputfiles_arg.split(','
 + 
 +    clips=[] 
 +    for iFile in iFiles: 
 +        subclip = re.search(r"\[([0-9\-\.]+)\]", iFile) 
 +        if subclip is None: 
 +            clips.append(VideoFileClip(iFile)) 
 +        else: 
 +            dims = subclip.group(1).split('-'
 +            if len(dims) != 2: 
 +                printerror("If a specific segment of a file is specified, this should be given as [startseconds-endseconds]"
 +            iFile = iFile.replace("["+subclip.group(1)+"]",''
 +            clips.append(VideoFileClip(iFile).subclip(float(dims[0]),float(dims[1]))) 
 + 
 +    f = concatenate_videoclips(clips) 
 +    f.write_videofile(outputfile) 
 + 
 + 
 +if __name__ == "__main__": 
 +   main(sys.argv[1:])
  
-  #!/usr/bin/python3 +</code
-   +
-  import sys, getopt, re +
-   +
-  def printerror(errormsg): +
-    print("*** vcat - concatenate video segments using moviepy ***\n"+
-    print("ERROR:", errormsg,"\n"+
-    print("Usage: vcat -i inputfile1,inputfile2[start-end],... -o <outputfile>") +
-    print("Optional start and end points should be given in seconds. If files have spaces, they should be quoted (e.g. \"input file.mp4[5-30]\")."+
-   +
-  try: +
-   from moviepy.editor import VideoFileClip, concatenate_videoclips +
-  except ImportError: +
-   printerror("You don't seem to have moviepy installed. Install it with `pip install moviepy`."+
-   exit(1) +
-   +
-  def main(argv): +
-      inputfiles_arg = '' +
-      outputfile = '' +
-      try: +
-          opts, args = getopt.getopt(argv,"hi:o:",["input=","output="]) +
-      except getopt.GetoptError as err: +
-          printerror(str(err)) +
-          sys.exit(2) +
-      for opt, arg in opts: +
-          if opt == '-h': +
-              printerror(""+
-              sys.exit() +
-          elif opt in ("-i", "--input"): +
-              inputfiles_arg = arg +
-          elif opt in ("-o", "--output"): +
-              outputfile = arg +
-      if outputfile =='': +
-          printerror("Output file not specified"+
-       +
-      iFiles = inputfiles_arg.split(','+
-   +
-      clips=[] +
-      for iFile in iFiles: +
-          subclip = re.search(r"\[([0-9\-]+)\]", iFile) +
-          if subclip is None: +
-              clips.append(VideoFileClip(iFile)) +
-          else: +
-              dims = subclip.group(1).split('-'+
-              if len(dims) != 2: +
-                  printerror("If a specific segment of a file is specified, this should be given as [startseconds-endseconds]"+
-              iFile = iFile.replace("["+subclip.group(1)+"]",''+
-              clips.append(VideoFileClip(iFile).subclip(int(dims[0]),int(dims[1]))) +
-   +
-      f = concatenate_videoclips(clips) +
-      f.write_videofile(outputfile) +
-       +
- +
personal/portfolio/vcat-script.1546434553.txt.gz · Last modified: 2019/01/02 14:09 by antonello
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0