def assemble(self, fnames):
"""
Stitches together movies from an ordered list of filenames.
Downloads new files from GCS then feeds files to ffmpeg.
Returns list of files sucessfully stitched into movie & calls stats func
"""
# Get files from GCS
pool = Pool(min(len(fnames), constants.MOVIE_DAEMON_MAX_PROCESSES))
results = pool.map(get_file_from_gcs, fnames)
pool.terminate()
# Start ffmpeg subprocess
ffmpeg_cmd = ["ffmpeg","-y", # Overwrite exsisting movie file
"-f", "image2pipe",
"-framerate", constants.MOVIE_FRAMERATE,
"-vcodec","mjpeg",
"-i", "-", # Input pipe from stdin
"-vf", "scale=1024:-1",
"-loglevel", "panic",
"-vcodec", "libx264",
constants.MOVIE_FPATH]
ffmpeg_ps = subprocess.Popen(ffmpeg_cmd, stdin=subprocess.PIPE)
fnames = list(compress(fnames, results))
files_read = self._pipe_to_ffmpeg(ffmpeg_ps, fnames)
if files_read > constants.MOVIE_MIN_FRAMES:
ffmpeg_ps.stdin.close()
ffmpeg_ps.wait()
else:
ffmpeg_ps.kill()
return fnames
评论列表
文章目录