Files
monde-usage-unity/Assets/Scripts/MISC/process_videos.sh
2024-09-22 21:45:37 +02:00

38 lines
1.0 KiBLFS
Bash
Executable File

#!/bin/bash
# Function to process the video
process_video() {
input_file="$1"
# Get the full path without extension
dir=$(dirname -- "$input_file")
filename=$(basename -- "$input_file")
extension="${filename##*.}"
filename="${filename%.*}"
# Check if the file already has _halfres in its name
if [[ "$filename" == *"_halfres" ]]; then
echo "Skipping $input_file, already processed (_halfres found)."
return
fi
# Create the output filename with full path
output_file="${dir}/${filename}_halfres.${extension}"
if [ -f "$output_file" ]; then
echo "Skipping $input_file, already transcoded."
return
fi
# Resize the video to half resolution using ffmpeg
ffmpeg -i "$input_file" -vf scale=960:540 "$output_file"
}
# Export the function so it can be used by find
export -f process_video
# Find all .mp4 files recursively and process them
find . -type f -name "*.mp4" ! -name "*_halfres.mp4" -exec bash -c 'process_video "$0"' {} \;
echo "All videos have been processed."