20 | 20 |
|
21 | 21 |
from kinoje.utils import LoggingExecutor
|
22 | 22 |
from kinoje.renderer import Renderer
|
|
23 |
from kinoje.compiler import GifCompiler, MpegCompiler
|
23 | 24 |
|
24 | 25 |
|
25 | 26 |
SUPPORTED_OUTPUT_FORMATS = ('.m4v', '.mp4', '.gif')
|
|
131 | 132 |
|
132 | 133 |
tempdir = mkdtemp()
|
133 | 134 |
|
134 | |
framerate = options.fps
|
135 | |
|
136 | 135 |
duration = options.duration
|
137 | 136 |
if duration is None:
|
138 | 137 |
duration = config['duration']
|
|
140 | 139 |
start_time = options.start * duration
|
141 | 140 |
stop_time = options.stop * duration
|
142 | 141 |
requested_duration = stop_time - start_time
|
143 | |
num_frames = int(requested_duration * framerate)
|
144 | |
t_step = 1.0 / (duration * framerate)
|
|
142 |
num_frames = int(requested_duration * options.fps)
|
|
143 |
t_step = 1.0 / (duration * options.fps)
|
145 | 144 |
|
146 | 145 |
print "Start time: t=%s, %s seconds" % (options.start, start_time)
|
147 | 146 |
print "Stop time: t=%s, %s seconds" % (options.stop, stop_time)
|
148 | 147 |
print "Requested duration: %s seconds" % requested_duration
|
149 | |
print "Frame rate: %s fps" % framerate
|
150 | |
print "Number of frames: %s (rounded to %s)" % (requested_duration * framerate, num_frames)
|
|
148 |
print "Frame rate: %s fps" % options.fps
|
|
149 |
print "Number of frames: %s (rounded to %s)" % (requested_duration * options.fps, num_frames)
|
151 | 150 |
print "t-Step: %s" % t_step
|
152 | 151 |
|
153 | 152 |
exe = LoggingExecutor(os.path.join(tempdir, 'movie.log'))
|
|
175 | 174 |
exe.do_it("eog %s" % fn)
|
176 | 175 |
sys.exit(0)
|
177 | 176 |
|
178 | |
if outext == '.gif':
|
179 | |
# TODO: show some warning if this is not an integer delay
|
180 | |
delay = int(100.0 / framerate)
|
|
177 |
compiler = {
|
|
178 |
'.gif': GifCompiler,
|
|
179 |
'.mp4': MpegCompiler,
|
|
180 |
'.m4v': MpegCompiler,
|
|
181 |
}[outext](tempdir, outfilename, options, exe)
|
181 | 182 |
|
182 | |
filenames = [os.path.join(tempdir, options.frame_fmt % f) for f in xrange(0, num_frames)]
|
183 | |
if options.twitter:
|
184 | |
filespec = ' '.join(filenames[:-1] + ['-delay', str(delay / 2), filenames[-1]])
|
185 | |
else:
|
186 | |
filespec = ' '.join(filenames)
|
|
183 |
compiler.compile(num_frames)
|
|
184 |
finished_at = datetime.now()
|
187 | 185 |
|
188 | |
# -strip is there to force convert to process all input files. (if no transformation is given,
|
189 | |
# it can sometimes stop reading input files. leading to skippy animations. who knows why.)
|
190 | |
exe.do_it("convert -delay %s -loop 0 %s -strip %s" % (
|
191 | |
delay, filespec, outfilename
|
192 | |
))
|
193 | |
finished_at = datetime.now()
|
194 | |
if options.view:
|
195 | |
exe.do_it("eog %s" % outfilename)
|
196 | |
elif outext in ('.mp4', '.m4v'):
|
197 | |
ifmt = os.path.join(tempdir, options.frame_fmt)
|
198 | |
# fun fact: even if you say -r 30, it still picks 25 fps
|
199 | |
cmd = "ffmpeg -i %s -c:v libx264 -profile:v baseline -pix_fmt yuv420p -r %s -y %s" % (
|
200 | |
ifmt, int(framerate), outfilename
|
201 | |
)
|
202 | |
exe.do_it(cmd)
|
203 | |
finished_at = datetime.now()
|
204 | |
if options.view:
|
205 | |
exe.do_it("vlc %s" % outfilename)
|
206 | |
else:
|
207 | |
raise NotImplementedError
|
|
186 |
if options.view:
|
|
187 |
compiler.view()
|
208 | 188 |
|
209 | 189 |
exe.close()
|
210 | 190 |
|