aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpux <pux@pux.dom>2020-02-12 21:48:32 +0100
committerpux <pux@pux.dom>2020-02-12 21:48:32 +0100
commit4b3b7f70b12d3e59029eaac5619d425b9ea61f3b (patch)
tree62a129b8fc5f09f44156c57d20c302ec3602520c
parentdcccd74440ac048425866cb8839aab82cff952ed (diff)
downloadnstvid-4b3b7f70b12d3e59029eaac5619d425b9ea61f3b.tar.gz
nstvid-4b3b7f70b12d3e59029eaac5619d425b9ea61f3b.tar.bz2
nstvid-4b3b7f70b12d3e59029eaac5619d425b9ea61f3b.zip
temp. version, need to escape strings etc.
-rwxr-xr-x[-rw-r--r--]nstvid.py87
-rwxr-xr-x[-rw-r--r--]nstvid.py.ref0
2 files changed, 83 insertions, 4 deletions
diff --git a/nstvid.py b/nstvid.py
index 53c443c..18873d4 100644..100755
--- a/nstvid.py
+++ b/nstvid.py
@@ -1,21 +1,100 @@
#!/bin/env python
+# neural style transfer video generator
+# 2020-02-11 Oliver Meckmann
+
from gooey import Gooey, GooeyParser
+import subprocess
+import os
+import glob
+import shlex
-@Gooey(default_size=(800, 600), terminal_font_color="FFFFFF",
+@Gooey(default_size=(800, 600), terminal_font_color="#FFFFFF", \
header_bg_color="#000000")
def init():
parser = GooeyParser(description = \
"nstvid - Neural Style Transfer Video Creator")
+
parser.add_argument("style_image", help="Style image", \
widget="FileChooser")
- parser.add_argument("input_video", help="Source", widget="FileChooser")
+ parser.add_argument("input_video", help="Source video", \
+ widget="FileChooser", default="/home/pux/tmp/nstest/in.mp4")
+ parser.add_argument("output_dir", help="Where your video is", \
+ widget="DirChooser", default="/home/pux/tmp/nstest")
+ parser.add_argument("fps", help="Framerate", default=12)
+ parser.add_argument("image_size", help="Pixels", default=384)
+ parser.add_argument("style_weight", default=1000)
+ parser.add_argument("content_weight", default=5)
+
params = parser.parse_args()
return params
def main():
- pass
+ 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()
+ print("Running ffmpeg extract audio")
+ subprocess.Popen("ffmpeg -y -i " + params.input_video + " " \
+ + params.output_dir + os.sep + "rawaudio.wav", \
+ shell=True).wait()
+
+ left = len(params.output_dir)
+ for fn in sorted(glob.glob(params.output_dir + os.sep + "image-*.jpg")):
+ num = fn[left+len(os.linesep)+6:-4]
+ print("Processing loop: new iteration")
+ print("Num: " + num + ", input file: " + fn)
+
+ command = [
+ "python", "neural_style.py",
+ "-style_image", r"" + params.style_image,
+ "-content_image", params.output_dir + os.sep + "image-" \
+ + str(num) + ".jpg",
+ "-output_image", params.output_dir + os.sep \
+ + "generated-" + str(num) + ".jpg",
+ "-image_size", params.image_size,
+ "-style_weight", params.style_weight,
+ "-content_weight", params.content_weight,
+ "-cudnn_autotune",
+ "-tv_weight", "000085", "-num_iterations", "1000",
+ "-print_iter", "50",
+ "-init", "image", "-optimizer", "lbfgs",
+ "-learning_rate", "1.0",
+ "-lbfgs_num_correction", "100",
+ "-style_scale", "1.0",
+ "-pooling", "max",
+ "-backend", "cudnn",
+ "-seed", "100",
+ "-content_layers", "relu1_1,relu2_1,relu3_1,relu4_1,relu4_2," \
+ + "relu5_1",
+ "-style_layers", "relu3_1,relu4_1,relu4_2,relu5_1",
+ "-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()
+
+ 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()
+
if __name__ == '__main__':
- init()
+ params = init()
main()
diff --git a/nstvid.py.ref b/nstvid.py.ref
index bd526d9..bd526d9 100644..100755
--- a/nstvid.py.ref
+++ b/nstvid.py.ref
in each repos: see "about"-tab (if existing) for more details / README.
mailto contact at omeckman dot net
all timestamps in UTC (German winter time: UTC+01:00, summer time: UTC+02:00)
dark theme is a modded version of: https://gist.github.com/Yoplitein/f4b671a2ec70c9e743fa