#!/bin/bash while getopts d:i:o: flag do case "${flag}" in d) directory="${OPTARG}";; i) input_file="${OPTARG}";; o) output_file="${OPTARG}";; *) # Catch-all for unexpected arguments echo "Invalid option: -$OPTARG" >&2 echo "Usage: ./compress.sh -d -i -o " exit 1 ;; esac done # Check if the directory is provided if [ -z "$directory" ]; then echo "Directory is required." echo "Usage: ./compress.sh -d -i -o " exit 1 fi if [ -z "$input_file" ]; then echo "Input file is required." echo "Usage: ./compress.sh -d -i -o " exit 1 fi if [ -z "$output_file" ]; then echo "Output file is required." echo "Usage: ./compress.sh -d -i -o " exit 1 fi cd "$directory" || exit 1 # Compress the file /usr/bin/ffmpeg -i "$input_file" -ar 16000 -ac 1 -map 0:a "$output_file" WAIT_TIME=5 # Function to check for file existence check_file() { if [ -f "$output_file" ]; then echo "File $output_file is available." return 0 else echo "File $output_file is not available yet. Waiting..." return 1 fi } # Wait for the file to become available while ! check_file; do sleep $WAIT_TIME done