diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-01-16 01:59:41 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-01-16 01:59:41 +0100 |
| commit | a8e994a32e481f667424fc55bffa16f8cd1e2b04 (patch) | |
| tree | 1dd3e7a72458588ee91a0e6b5f415e19efb16d40 | |
| parent | 17c69a6138301564bd05804293734d4eaf221fa8 (diff) | |
start/end
| -rw-r--r-- | crop_frames.py | 13 | ||||
| -rw-r--r-- | merge_frames.py | 27 | ||||
| -rw-r--r-- | run.sh | 13 |
3 files changed, 44 insertions, 9 deletions
diff --git a/crop_frames.py b/crop_frames.py index 0f700b8..dd8c1e6 100644 --- a/crop_frames.py +++ b/crop_frames.py @@ -9,9 +9,11 @@ from PIL import Image parser = argparse.ArgumentParser() parser.add_argument('--step', default=192, type=int, help='Width of frames') parser.add_argument('--overlap', default=2, type=int, help='Expand all frames by this margin') -parser.add_argument('--ratio', default=2, type=int, help='Pre-crop frames to this ratio') +parser.add_argument('--ratio', default=2.0, type=float, help='Pre-crop frames to this ratio') parser.add_argument('--in_dir', help='Directory to process') parser.add_argument('--out_dir', default='inputs', help='Directory to output crops to') +parser.add_argument('--start', default=0, type=int, help='Minimum frame number') +parser.add_argument('--end', default=99999, type=int, help='Maximum frame number') args = parser.parse_args() def crop_dir(): @@ -43,7 +45,14 @@ def crop_dir(): dataset = [] for raw_fn in files: - dataset.append((raw_fn, width, height, step, side, overlap, top_offset,)) + fn, ext = os.path.splitext(os.path.basename(raw_fn)) + partz = fn.split('_') + try: + num = int(partz[-1].replace('.png', '')) + if num >= start and num <= end: + dataset.append((raw_fn, width, height, step, side, overlap, top_offset,)) + except: + pass chunksize = 3 with Pool(processes=cpu_count()) as pool: diff --git a/merge_frames.py b/merge_frames.py index e265fea..32e0341 100644 --- a/merge_frames.py +++ b/merge_frames.py @@ -11,13 +11,29 @@ parser = argparse.ArgumentParser() parser.add_argument('--step', default=192, type=int) parser.add_argument('--overlap', default=2, type=int) parser.add_argument('--scale', default=4, type=int) -parser.add_argument('dir', metavar='dir', help='Directory to process') +parser.add_argument('--in_dir', help='Directory to process') +parser.add_argument('--render_dir', help='Directory to output render to') +parser.add_argument('--mov', action='store_true', help='whether to create an mp4') args = parser.parse_args() def split_crop_dir(fn): crop, x, y, w, h = os.path.basename(fn).split("_") return int(x), int(y), int(w), int(h) +def make_movie(merge_dir, dataset): + subprocess.call([ + 'ffmpeg', + '-hide_banner', + '-i', os.path.join(merge_dir, 'frame_%05d.png'), + '-y', + '-c:v', 'libx264', + '-preset', 'slow', + '-crf', '19', + '-vf', 'fps=25', + '-pix_fmt', 'yuv420p', + os.path.join(opt.render_dir, dataset + '.mp4') + ]) + def merge_files(file, crop_dir_list, ww, hh, overlap, merge_dir): fn = os.path.basename(file) print(fn) @@ -32,8 +48,10 @@ def merge_files(file, crop_dir_list, ww, hh, overlap, merge_dir): def merge_dir(): overlap = args.overlap * args.scale - crop_dirs = glob.glob("{}/crop_*".format(args.dir)) - merge_dir = "{}/merged".format(args.dir) + partz = args.dir.trim('/').split('/') + dataset = partz[-1] + crop_dirs = glob.glob("{}/crop_*".format(args.in_dir)) + merge_dir = "{}/merged".format(args.in_dir) os.makedirs(merge_dir, exist_ok=True) ww = 0 hh = 0 @@ -69,5 +87,8 @@ def merge_dir(): with Pool(processes=cpu_count()) as pool: pool.starmap(merge_files, dataset, chunksize) + if args.mov: + make_movie(merge_dir, dataset) + if __name__ == "__main__": merge_dir() @@ -3,13 +3,18 @@ rm -rf inputs/* rm -rf results/* -name=$1 +path=$1 +name=`basename $path` start=`date` -python crop_frames.py --in_dir "$name" --out_dir "inputs/$name" +echo "Start: $start" +echo $path + +python crop_frames.py --in_dir "$name" --out_dir "inputs/$name" --ratio 6.0 python test.py --in_dir "inputs/$name" --out_dir "results/$name" -python merge_frames --in_dir "results/$name" --out_dir "inputs/$name" -ffmpeg -i ./results/28L/L/merged/frame_%05d.png -y -c:v libx264 -vf fps=25 -pix_fmt yuv420p "./results/${name}_uprez.mp4" +python merge_frames --in_dir "results/$name" --render_dir "./renders" --mov + +# ffmpeg -i ./results/$name/merged/frame_%05d.png -y -c:v libx264 -vf fps=25 -pix_fmt yuv420p "./results/${name}_uprez.mp4" # scp "./results/${name}_uprez.mp4" jules@lmno:asdf/neural/uprez/ endd=`date` |
