-
Notifications
You must be signed in to change notification settings - Fork 0
/
movie.py
68 lines (61 loc) · 1.98 KB
/
movie.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
import sys, os, subprocess
from subprocess import call
import rbc_npy2Perseus as n2p
"""
Make a movie from PNG files. Assumed that this script resides in the
folder containing a sequence of frames (PNG files).
"""
slash = "/"
def sort_files( dlist ):
""" Sort files in dlist according to the order
of creation. """
return sorted(dlist, key=order)
def order( line ):
"""split line and return the index of the partial cover"""
return int( line.rstrip().split('.')[-2] )
def prefix_files( dlist, prefix ):
"""Return only files beginning with <prefix>"""
plist = [x for x in dlist if x.startswith( prefix )]
return plist
def suffix_files( dlist, suffix ):
"""Return only files ending with <suffix>"""
slist = [x for x in dlist if x.endswith( suffix )]
return slist
def patch_cover( dlist, prefix, suffix='png'):
"""Return image (of type <suffix>) that begin with <prefix>"""
a = prefix_files( dlist, prefix )
return suffix_files( a, suffix )
def run(dir, output, prgm='mencoder'):
if not output.endswith('.mp4'):
output+='.mp4'
if not dir.endswith('/'):
dir+='/'
if os.path.isdir (dir):
dlist = os.listdir(dir)
frames = []
for f in dlist:
if f.endswith('npy') and not os.path.isdir(dir+f):
frames.append(dir+f)
else:
print 'Error - input is not a directory'
return
#print frames
frames.sort(key=n2p.natural_key)
print '..creating movie..'
if prgm.startswith('m'):
call(['mencoder',
frames,
'-mf',
'type=png:h=800:w=400:fps=34',
'-ovc',
'lavc',
'-lavcopts',
'vcodec=avi',
'-oac',
'copy',
'-o',
output])
else:
call(['ffmpeg', '-qscale 5', '-r 34', '-b 9600', 'data/jberwald/wyss/data/Cells_Jesse/New/frames/new_110125/new_110125-concatenated-ASCII_%.npy', output ])
print '..finished..'