From 366e4bb6fe99e455cc3c0f78c320e4d1427248da Mon Sep 17 00:00:00 2001 From: pux Date: Wed, 12 Feb 2020 22:42:59 +0100 Subject: escaping works with spaces, commas still make it fail --- nstvid.py | 79 ++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/nstvid.py b/nstvid.py index 18873d4..d663db3 100755 --- a/nstvid.py +++ b/nstvid.py @@ -3,11 +3,19 @@ # neural style transfer video generator # 2020-02-11 Oliver Meckmann +# meant to be run from the root directory of this project: +# https://github.com/ProGamerGov/neural-style-pt + +# opticalflow.py from this project should also be copied over to the +# neural-style-pt root directory +# https://github.com/larspars/neural-style-video + + from gooey import Gooey, GooeyParser import subprocess import os import glob -import shlex +#from shlex import quote @Gooey(default_size=(800, 600), terminal_font_color="#FFFFFF", \ header_bg_color="#000000") @@ -31,17 +39,21 @@ def init(): def main(): print("Running ffmpeg extract images") - subprocess.Popen("ffmpeg -i " + params.input_video \ - + " -r " + params.fps + " -f image2 " \ - + params.output_dir + os.sep + "image-%5d.jpg", \ - shell=True).wait() + command = [ + "ffmpeg", "-i", r"" + params.input_video, + "-r", r"" + params.fps, "-f", "image2", + r"" + params.output_dir + os.sep + "image-%5d.jpg"] + subprocess.Popen(command).wait() + print("Running ffmpeg extract audio") - subprocess.Popen("ffmpeg -y -i " + params.input_video + " " \ - + params.output_dir + os.sep + "rawaudio.wav", \ - shell=True).wait() + command = [ + "ffmpeg", "-y", "-i", r"" + params.input_video, + r"" + params.output_dir + os.sep + "rawaudio.wav"] + subprocess.Popen(command).wait() left = len(params.output_dir) - for fn in sorted(glob.glob(params.output_dir + os.sep + "image-*.jpg")): + flist = sorted(glob.glob(params.output_dir + os.sep + "image-*.jpg")) + for fn in flist: num = fn[left+len(os.linesep)+6:-4] print("Processing loop: new iteration") print("Num: " + num + ", input file: " + fn) @@ -49,9 +61,9 @@ def main(): command = [ "python", "neural_style.py", "-style_image", r"" + params.style_image, - "-content_image", params.output_dir + os.sep + "image-" \ + "-content_image", r"" + params.output_dir + os.sep + "image-" \ + str(num) + ".jpg", - "-output_image", params.output_dir + os.sep \ + "-output_image", r"" + params.output_dir + os.sep \ + "generated-" + str(num) + ".jpg", "-image_size", params.image_size, "-style_weight", params.style_weight, @@ -72,28 +84,33 @@ def main(): "-multidevice_strategy", "4,7,29"] subprocess.Popen(command).wait() - print("Running opticalflow: num: " + num) - subprocess.Popen( \ - "python opticalflow.py " - + "--input_1 " + params.output_dir \ - + os.sep + "image-" + str(num) + ".jpg " \ - + "--input_1_styled " + params.output_dir - + os.sep + "generated-" + str(num) + ".jpg " \ - + "--input_2 " + params.output_dir + os.sep + "image-" \ - + str(int(num)+1).zfill(5) + ".jpg " \ - + "--output " + params.output_dir \ - + os.sep + "blended-" + str(num) \ - + ".jpg " \ - + "--alpha 0.55 " \ - + "--flowblend False", shell=True).wait() + if fn is not flist[-1]: + print("Running opticalflow: num: " + num) + command = [ + "python", "opticalflow.py", + "--input_1", r"" + params.output_dir \ + + os.sep + "image-" + str(num) + ".jpg", + "--input_1_styled", r"" + params.output_dir \ + + os.sep + "generated-" + str(num) + ".jpg", + "--input_2", r"" + params.output_dir + os.sep + "image-" \ + + str(int(num)+1).zfill(5) + ".jpg", + "--output", r"" + params.output_dir \ + + os.sep + "blended-" + str(num) + ".jpg", + "--alpha", "0.55", + "--flowblend", "False"] + subprocess.Popen(command).wait() + else: + print("Last element: skipping opticalflow") print("Running ffmpeg merge") - subprocess.Popen("ffmpeg -y -framerate " + params.fps + " " \ - + "-i " + params.output_dir + os.sep + "blended-%05d.jpg " \ - + "-i " + params.output_dir + os.sep + "rawaudio.wav " \ - + "-c:v libx264 -preset veryslow -qp 0 -pix_fmt yuv420p " \ - + params.output_dir + os.sep + "out.mp4", shell=True).wait() - + command = [ + "ffmpeg", "-y", "-framerate", params.fps, + "-i", r"" + params.output_dir + os.sep + "blended-%05d.jpg", + "-i", r"" + params.output_dir + os.sep + "rawaudio.wav", + "-c:v", "libx264", "-preset", "veryslow", "-qp", "0", + "-pix_fmt", "yuv420p", r"" + + params.output_dir + os.sep + "out.mp4"] + subprocess.Popen(command).wait() if __name__ == '__main__': params = init() -- cgit v1.2.2-1-g5e49