|
#!/bin/bash |
|
|
|
|
|
video_file=$1 |
|
shift |
|
gpu_indices=($@) |
|
n_gpus=${#gpu_indices[@]} |
|
n_frames=$(python -c "import sys; from vre import FFmpegVideo; print(len(FFmpegVideo(sys.argv[1])))" $video_file) |
|
fps=$(python -c "import sys; from vre import FFmpegVideo; print(FFmpegVideo(sys.argv[1]).fps)" $video_file) |
|
frames_per_gpu=$((n_frames / n_gpus)) |
|
|
|
|
|
cleanup() { |
|
echo "Terminating subprocesses..." |
|
pkill -P $$ |
|
exit 1 |
|
} |
|
|
|
trap cleanup SIGINT SIGTERM |
|
|
|
for ((i=0; i<n_gpus; i++)); do |
|
start_frame=$((i * frames_per_gpu)) |
|
end_frame=$((start_frame + frames_per_gpu)) |
|
|
|
|
|
if [[ $i -eq $((n_gpus - 1)) ]]; then |
|
end_frame=$n_frames |
|
fi |
|
|
|
echo "CUDA_VISIBLE_DEVICES=${gpu_indices[$i]} ./wip.py $video_file --frames $start_frame..$end_frame &" |
|
CUDA_VISIBLE_DEVICES=${gpu_indices[$i]} ./wip.py $video_file --frames $start_frame..$end_frame & |
|
done |
|
|
|
|
|
wait |
|
|
|
|
|
ffmpeg -framerate $fps -i out_"$video_file"/collage/%d.jpg -c:v libx265 -pix_fmt yuv420p out_"$video_file"/collage/collage.mp4 |
|
|