#!/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