-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapply_inpainting.sh
executable file
·79 lines (57 loc) · 1.92 KB
/
apply_inpainting.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
#!/bin/bash
apt-get install parallel ffmpeg
pip install iopaint
INPUT_video=$1
echo Creating image files from video
mkdir data/
mkdir data/imgs_org/
mkdir data/imgs/
#By adding -vf "scale=720:540" you can scale here
ffmpeg -i $INPUT_video -vsync vfr data/imgs_org/%07d.png
# Extract raw frame rate as a fraction (e.g. "30000/1001"):
FPS_FRACTION=$(ffprobe -v error \
-select_streams v:0 \
-show_entries stream=avg_frame_rate \
-of csv=p=0 \
"$INPUT_video")
if [ ! -f "overlay_mask.png" ]; then
echo "File overlay_mask.png does not exist."
fi
echo moving image files to separate folders for paralization
NR_CPUs=16
# Define source folder
SOURCE="data/imgs_org"
# Get total number of files
TOTAL_FILES=$(find "$SOURCE" -maxdepth 1 -type f | wc -l)
# Number of folders
NUM_FOLDERS=$NR_CPUs
# Calculate files per folder (some folders might have one extra file)
FILES_PER_FOLDER=$((TOTAL_FILES / NUM_FOLDERS))
EXTRA_FILES=$((TOTAL_FILES % NUM_FOLDERS))
# Create folders
mkdir -p split_folders
cd split_folders
mkdir -p folder_{1..128}
# Distribute files
i=1
folder_num=1
for file in "$SOURCE"/*; do
mv "$file" "folder_$folder_num/"
# Switch to the next folder when enough files are moved
if (( i % FILES_PER_FOLDER == 0 )); then
if (( folder_num <= EXTRA_FILES )); then
# Distribute the extra files evenly among the first few folders
((i++))
fi
((folder_num++))
fi
((i++))
done
cd ..
#Run iopaint once to predownload the model
iopaint run --model=lama --device cuda --image /dev/zero --mask /dev/zero --output /dev/null
echo doing inpainting
#migan is faster but to slow
find split_folders -mindepth 1 -maxdepth 1 -type d | parallel -j $NR_CPUs 'iopaint run --model=lama --device cuda --image {} --mask overlay_mask.png --output data/imgs/'
echo recombining inpainted images to a video
ffmpeg -framerate $FPS_FRACTION -i data/imgs/%07d.png -c:v libx264 -crf 6 -pix_fmt yuv420p data/preprocessed_video.mp4