Meehai's picture
added consistency script
8010ada
#!/bin/bash
# Read arguments
video_file=$1
shift # Remove first argument (video_file)
gpu_indices=($@) # Remaining arguments are GPU indices
n_gpus=${#gpu_indices[@]} # Derive n_gpus from the array length
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))
# Function to clean up child processes on script termination
cleanup() {
echo "Terminating subprocesses..."
pkill -P $$ # Kill all child processes of this script
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))
# Ensure the last partition captures all remaining frames
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 for all background processes to complete
wait
# Combine output frames into a video using ffmpeg
ffmpeg -framerate $fps -i out_"$video_file"/collage/%d.jpg -c:v libx265 -pix_fmt yuv420p out_"$video_file"/collage/collage.mp4