-
Notifications
You must be signed in to change notification settings - Fork 1
/
video.py
executable file
·37 lines (29 loc) · 1.01 KB
/
video.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# Combines a folder of frames into a video using moviepy
#
# usage: $ python video.py 60 webcamImages {webcamTimelapse}
# fps directory name
# If the name is omitted, the video will have the same name as the folder
# the images came from.
from __future__ import print_function
from moviepy.editor import *
import sys
import os
frames = int(sys.argv[1])
directory = sys.argv[2]
try:
# Append '.mp4' to the filename if it doesn't already end like that
if sys.argv[3].endswith('.mp4'):
outputName = sys.argv[3]
else:
outputName = sys.argv[3] + '.mp4'
except IndexError:
outputName = directory.strip('/') + '.mp4'
# Pythonism ensues
names = [directory + '/' + name for name in os.listdir(directory) if name.endswith(".jpg") or name.endswith(".jpeg")]
if len(names) == 0:
print('No files found', file=sys.stderr)
sys.exit(1)
names.sort()
clip = ImageSequenceClip(names, fps=frames)
clip.write_videofile(outputName, fps=frames, codec='libx264')