11__author__ = 'David Karchmer'
22
3- import os
4- import sys
5- import json
6- import logging
7- import argparse
8- from logging import StreamHandler , Formatter
3+ import moviepy .editor as mpy
94
10- import moviepy .editor as moviepy
11-
12- if __name__ == "__main__" :
13-
14- # Logger Format
15- FORMAT = '[%(asctime)-15s] %(levelname)-6s %(message)s'
16- DATE_FORMAT = '%d/%b/%Y %H:%M:%S'
17- formatter = Formatter (fmt = FORMAT , datefmt = DATE_FORMAT )
18- handler = StreamHandler ()
19- handler .setFormatter (formatter )
20- logger = logging .getLogger (__name__ )
21- logger .addHandler (handler )
22- logger .setLevel (logging .DEBUG )
23-
24- parser = argparse .ArgumentParser (description = __doc__ ,
25- formatter_class = argparse .RawDescriptionHelpFormatter )
26- parser .add_argument ('-o' , dest = 'output' , type = str , help = "Output File" , default = 'stack.mp4' )
27- __author__ = 'dkarchmer'
28-
29- import os
30- import sys
31- import json
32- import logging
33- import argparse
34- from logging import StreamHandler , Formatter
35-
36- #from moviepy.editor import *
37- import moviepy .editor as moviepy
38-
39-
40- if __name__ == "__main__" :
41-
42- # Logger Format
43- FORMAT = '[%(asctime)-15s] %(levelname)-6s %(message)s'
44- DATE_FORMAT = '%d/%b/%Y %H:%M:%S'
45- formatter = Formatter (fmt = FORMAT , datefmt = DATE_FORMAT )
46- handler = StreamHandler ()
47- handler .setFormatter (formatter )
48- logger = logging .getLogger (__name__ )
49- logger .addHandler (handler )
50- logger .setLevel (logging .DEBUG )
51-
52- parser = argparse .ArgumentParser (description = __doc__ ,
53- formatter_class = argparse .RawDescriptionHelpFormatter )
54-
55- parser .add_argument ('-o' , dest = 'output' , type = str , help = "Output File" , default = 'stack.mp4' )
56- parser .add_argument ('videos' , metavar = 'videos' , type = str , nargs = '+' , help = 'Videos to process' )
57-
58- args = parser .parse_args (sys .argv [1 :])
59-
60- logger .debug ('ARGS: ' + str (args ))
61-
62- if not args .jsonfile :
63- logger .error ('Missing required configuration json file' )
64- exit (1 )
65-
66- logger .info ('Processing data from Json file: {0}' .format (args .jsonfile ))
67- json_file = video_file = os .path .join (args .indir , args .jsonfile )
68- if not os .path .isfile (json_file ):
69- logger .error ('Json file not found: {0}' .format (json_file ))
70- exit (1 )
71-
72- json_data = open (json_file ).read ()
73- data = json .loads (json_data )
74- logger .info (data )
75-
76- print ('Generate Matrix' )
77-
78-
79- clips = []
80- for v in data ['videos' ]:
81- # If we need to resize: clip.fx( resize, width=240)
82- clips .append (moviepy .VideoFileClip (os .path .join (data ['input_dir' ], v ['file' ]))
83- .subclip (v ['ss' ],v ['ss' ]+ 60 * data ['duration' ]).without_audio ().margin (10 ))
84- # .set_start(v['ss']).set_duration(30).without_audio().margin(10))
85-
86- final_clip = moviepy .clips_array ([[clips [0 ], clips [1 ]], [clips [2 ], clips [3 ]]])
87-
88- final_clip .write_videofile (args .output )
89-
90- args = parser .parse_args (sys .argv [1 :])
91-
92- logger .debug ('ARGS: ' + str (args ))
93-
94- if not args .jsonfile :
95- logger .error ('Missing required configuration json file' )
96- exit (1 )
97-
98- logger .info ('Processing data from Json file: {0}' .format (args .jsonfile ))
99- json_file = video_file = os .path .join (args .indir , args .jsonfile )
100- if not os .path .isfile (json_file ):
101- logger .error ('Json file not found: {0}' .format (json_file ))
102- exit (1 )
103-
104- json_data = open (json_file ).read ()
105- data = json .loads (json_data )
106- logger .info (data )
107-
108- print ('Generate Matrix' )
109-
110-
111- clips = []
112- for v in data ['videos' ]:
113- # If we need to resize: clip.fx( resize, width=240)
114- clips .append (moviepy .VideoFileClip (os .path .join (data ['input_dir' ], v ['file' ]))
115- .subclip (v ['ss' ],v ['ss' ]+ 60 * data ['duration' ]).without_audio ().margin (10 ))
116- # .set_start(v['ss']).set_duration(30).without_audio().margin(10))
117-
118- final_clip = moviepy .clips_array ([[clips [0 ], clips [1 ]], [clips [2 ], clips [3 ]]])
119-
120- final_clip .write_videofile (args .output )
5+ hello_world = mpy .TextClip ('Hello, World!' , fontsize = 78 , color = 'white' , size = (1280 ,720 ))
6+ hello_world = hello_world .set_duration (10 )
7+ hello_world .write_videofile ('hello_world.mp4' , fps = 24 )
0 commit comments