-
Notifications
You must be signed in to change notification settings - Fork 31
/
make_video.sh
executable file
·88 lines (73 loc) · 2.31 KB
/
make_video.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
set -e
# Get a carriage return into `cr`
cr=`echo $'\n.'`
cr=${cr%.}
# Find out whether ffmpeg or avconv is installed on the system
FFMPEG=ffmpeg
command -v $FFMPEG >/dev/null 2>&1 || {
FFMPEG=avconv
command -v $FFMPEG >/dev/null 2>&1 || {
echo >&2 "This script requires either ffmpeg or avconv installed. Aborting."; exit 1;
}
}
if [ "$#" -le 0 ]; then
echo "Usage: ./make_video <path_to_video>"
exit 1
fi
# Parse arguments
filename=$(basename "$1")
extension="${filename##*.}"
filename="${filename%.*}"
filename=${filename//[%]/x}
style_image=$2
echo ""
read -p "Which backend do you want to use? \
For Nvidia GPU, use cudnn if available, otherwise nn. \
For non-Nvidia GPU, use clnn. Note: You have to have the given backend installed in order to use it. [nn] $cr > " backend
backend=${backend:-nn}
if [ "$backend" == "cudnn" ] || [ "$backend" = "nn" ] || [ "$backend" = "clnn" ]; then
echo ""
read -p "Please enter a resolution at which the video should be processed. \
This value should be exactly same as what you input to fast_stylize.sh and opt_flow.sh. \
In the format w:h, or leave blank to use the original resolution $cr > " resolution
else
echo "Unknown backend."
exit 1
fi
style_weight=8e0
temporal_weight=9e3
perceptual_weight=3e1
pixel_weight=1.5e-3
#LOW PIXEL_WEIGHT, MORE STABLE
#style_weight=8e0
#temporal_weight=8e3
#perceptual_weight=3e1
#pixel_weight=9e-5
echo ""
read -p "Enter the zero-indexed ID of the GPU to use, or -1 for CPU mode (very slow!).\
[0] $cr > " gpu
gpu=${gpu:-0}
echo ""
echo "Computing optical flow. This may take a while..."
start=$(date +%s.%N)
# Perform style transfer
th artistic_video.lua \
-content_pattern ${filename}/frame_%06d.ppm \
-flow_pattern ${filename}/flow_${resolution}/backward_[%d]_{%d}.flo \
-flowWeight_pattern ${filename}/flow_${resolution}/reliable_[%d]_{%d}.pgm \
-style_weight $style_weight \
-temporal_weight $temporal_weight \
-perceptual_weight $perceptual_weight \
-pixel_weight $pixel_weight \
-output_folder ${filename}/ \
-backend $backend \
-gpu $gpu \
-cudnn_autotune \
-number_format %06d \
-num_iterations 30
end=$(date +%s.%N)
runtime=$(python -c "print(${end} - ${start})")
echo "Consistency Network Runtime Was $runtime Seconds"
# Create video from output images.
$FFMPEG -i ${filename}/out-%06d.png ${filename}-stylized.$extension