EXEC_SHELL_PATH=$(command -v bash) if [ "$#" -ne 1 ]; then echo "Usage: $0 input_video" exit 1 fi input_file="$1" output_folder="$HOME/Videos/converted_for_compatibility" temp_folder="/dev/shm" # Use tmpfs to store files in RAM temp_file="$temp_folder/temp-$(basename "$input_file")" output_file="$output_folder/compatible-$(basename "$input_file")" # Create the output folder if it doesn't exist mkdir -p "$output_folder" # Copy the input video to RAM cp "$input_file" "$temp_file" # Set the number of threads to 32 (adjust as needed) threads=32 # Set the output resolution to 360p output_resolution="640x360" # Perform the encoding on the downscaled video in RAM ffmpeg -i "$temp_file" -c:v libx264 -pix_fmt yuv420p -preset veryslow -crf 23 -s "$output_resolution" -threads "$threads" -y "$output_file" # Check if the video got saved successfully if [ $? -eq 0 ]; then echo "Video conversion successful. Output file: $output_file" else echo "Error: Video conversion failed." fi # Clean up temporary file in RAM rm -f "$temp_file"