summaryrefslogtreecommitdiff
path: root/cli/app/search
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-01-17 19:10:00 +0100
committerJules Laplace <julescarbon@gmail.com>2020-01-17 19:10:00 +0100
commit42d032decf2be236e1fc86abe53d6b02e435e938 (patch)
tree9a41b77fbc6baed144affda3d94e59445a95ed5a /cli/app/search
parente980b37539e3a90a36c6a71038c91a0073b115d8 (diff)
write and upload video
Diffstat (limited to 'cli/app/search')
-rw-r--r--cli/app/search/live.py43
1 files changed, 27 insertions, 16 deletions
diff --git a/cli/app/search/live.py b/cli/app/search/live.py
index 8038e72..6730c96 100644
--- a/cli/app/search/live.py
+++ b/cli/app/search/live.py
@@ -413,31 +413,45 @@ class Listener:
tag = "biggan_" + timestamp()
# path_out = os.path.join(app_cfg.DIR_RESULTS, tag)
# os.makedirs(path_out, exist_ok=True)
- gen_time_total = 0
- to_pil_time_total = 0
- save_time_total = 0
- resize_time_total = 0
- send_time_total = 0
- p = Popen([
+ fp_out = os.path.join(app_cfg.DIR_RENDERS, '{}.mp4'.format(tag))
+ pipe = Popen([
'ffmpeg',
'-y',
'-f', 'image2pipe',
'-vcodec', 'png',
'-r', '25',
'-i', '-',
-
'-c:v', 'libx264',
'-preset', 'slow',
'-crf', '19',
'-vf', 'fps=25',
'-pix_fmt', 'yuv420p',
'-s', '512x512',
-
- # '-vcodec', 'mpeg4',
- # '-qscale', '5',
- '-r', '25', '{}.mp4'.format(tag)
+ '-r', '25',
+ fp_out
], stdin=PIPE, stdout=PIPE)
+ # catch interrupts
+ try:
+ self.run(interpolator, pipe)
+ except e:
+ pass
+ self.rpc_client.send_status('processing', False)
+ self.sess.close()
+ print("Writing video...")
+ pipe.stdin.close()
+ pipe.wait()
+ print("Uploading video...")
+ data = upload_file_to_cortex(opt_folder_id, fp_out, datatype='video', activity='live')
+ print(json.dumps(data, indent=2))
+ print("Done")
+
+ def run(self, interpolator, pipe):
+ gen_time_total = 0
+ to_pil_time_total = 0
+ save_time_total = 0
+ resize_time_total = 0
+ send_time_total = 0
for i in range(99999):
if i == 0:
print("Loading network...")
@@ -463,7 +477,7 @@ class Listener:
if out_img is not None:
save_time = time.time()
# out_img.save(os.path.join(path_out, "frame_{:05d}.png".format(i)), format='png', compression_level=3)
- out_img.save(p.stdin, format='png', compression_level=3)
+ out_img.save(pipe.stdin, format='png', compression_level=3)
save_time_total += time.time() - save_time
resize_time = time.time()
@@ -481,7 +495,4 @@ class Listener:
send_time_total += time.time() - send_time
if (i % 100) == 0 or i == 1:
print("gen: {:2f}, pil: {:2f}, save: {:2f}, resize: {:2f}, send: {:2f}".format(gen_time_total / i, to_pil_time_total / i, save_time_total / i, resize_time_total / i, send_time_total / i))
- p.stdin.close()
- p.wait()
- self.rpc_client.send_status('processing', False)
- self.sess.close()
+