-
Notifications
You must be signed in to change notification settings - Fork 2
/
stylizeVideo_target.sh
73 lines (61 loc) · 1.94 KB
/
stylizeVideo_target.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
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 1 ]; then
echo "Usage: ./stylizeVideo_target <path_to_video> <path_to_style_image>"
exit 1
fi
# parse arguments
filename=$(basename "$1")
extension="${filename##*.}"
filename="${filename%.*}"
filename=v_target/${filename//[%]/x}
style_image=$2
style_filename=$(basename "$2")
style_extension="${style_filename##*.}"
style_filename="${style_filename%.*}"
style_filename=${style_filename//[%]/x}
# create output folder
mkdir -p $filename
backend=${backend:-nn}
# extract video to images
$FFMPEG -i $1 -vf scale='320:240' -framerate 5 ${filename}/frame_%04d.ppm
content_weight=10
style_weight=75
tv_weight=1e-3
temporal_weight=1e3
gpu=${gpu:-0}
# calculate optical flow
bash makeOptFlow.sh ./${filename}/frame_%04d.ppm ./${filename}/flow_320:240
# perform style transfer
th ./artistic_video.lua \
-content_pattern ${filename}/frame_%04d.ppm \
-flow_pattern ${filename}/flow_320:240/backward_[%d]_{%d}.flo \
-flowWeight_pattern ${filename}/flow_320:240/reliable_[%d]_{%d}.pgm \
-content_weight $content_weight \
-style_weight $style_weight \
-tv_weight $tv_weight \
-temporal_weight $temporal_weight \
-output_folder ${filename}/ \
-style_image $style_image \
-backend $backend \
-gpu $gpu \
-cudnn_autotune \
-number_format ${style_filename}-%04d \
-num_images 64
# create video from output images
$FFMPEG -i ${filename}/out-${style_filename}-%04d.png -framerate 5 ${filename}-stylized_${style_filename}.$extension
# save output images as npy
python save_stylized_npy.py \
--styled-video-name ${filename}-stylized_${style_filename}.$extension \
--orig-video-name ${filename} \
--style-img-name ${style_filename}