2024-03-02 21:22:03 +00:00
|
|
|
EXEC_SHELL_PATH=$(command -v bash)
|
|
|
|
|
2024-06-01 05:00:40 +00:00
|
|
|
|
|
|
|
# Function to display script usage
|
|
|
|
usage() {
|
|
|
|
echo "Usage: $0 [--high] input_video"
|
|
|
|
echo " --high: Preserve original resolution of the input video"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if FFmpeg is installed
|
|
|
|
if ! command -v ffmpeg &>/dev/null; then
|
|
|
|
echo "Error: FFmpeg is not installed. Please install FFmpeg first."
|
2024-03-02 21:22:03 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-06-01 05:00:40 +00:00
|
|
|
# Parse command line options
|
|
|
|
preserve_resolution=false
|
|
|
|
|
|
|
|
while [[ "$#" -gt 0 ]]; do
|
|
|
|
case $1 in
|
|
|
|
--high)
|
|
|
|
preserve_resolution=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
input_file="$1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Check if input file is provided
|
|
|
|
if [ -z "$input_file" ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if input file exists
|
|
|
|
if [ ! -f "$input_file" ]; then
|
|
|
|
echo "Error: Input file '$input_file' not found."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Output folder and file paths
|
2024-09-08 20:03:55 +00:00
|
|
|
output_folder="/mnt/Zonai/Videos/converted_for_compatibility"
|
2024-06-01 05:00:40 +00:00
|
|
|
output_filename="compatible-$(basename "$input_file" | sed 's/[^a-zA-Z0-9._-]/_/g')"
|
|
|
|
output_file="$output_folder/$output_filename"
|
2024-03-02 21:22:03 +00:00
|
|
|
|
2024-06-01 05:00:40 +00:00
|
|
|
# Check if the output folder exists and is writable
|
|
|
|
if [ ! -d "$output_folder" ] || [ ! -w "$output_folder" ]; then
|
|
|
|
echo "Error: Output folder '$output_folder' does not exist or is not writable."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If output file already exists, delete it
|
|
|
|
if [ -e "$output_file" ]; then
|
|
|
|
echo "Output file '$output_file' already exists. Deleting it..."
|
|
|
|
rm -f "$output_file"
|
|
|
|
fi
|
2024-03-02 21:22:03 +00:00
|
|
|
|
|
|
|
# Copy the input video to RAM
|
2024-06-01 05:00:40 +00:00
|
|
|
temp_file=$(mktemp -u)
|
2024-03-02 21:22:03 +00:00
|
|
|
cp "$input_file" "$temp_file"
|
|
|
|
|
|
|
|
# Set the number of threads to 32 (adjust as needed)
|
|
|
|
threads=32
|
|
|
|
|
2024-06-01 05:00:40 +00:00
|
|
|
# Set the output resolution based on the --high parameter
|
|
|
|
if [ "$preserve_resolution" = true ]; then
|
|
|
|
output_resolution="scale='iw:-1'"
|
|
|
|
else
|
|
|
|
output_resolution="640x360"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Perform the encoding and compression on the video in RAM
|
|
|
|
ffmpeg -i "$temp_file" -c:v libx264 -pix_fmt yuv420p -preset veryslow -crf 25 -vf "$output_resolution" -c:a aac -b:a 128k -y "$output_file"
|
2024-03-02 21:22:03 +00:00
|
|
|
|
2024-06-01 05:00:40 +00:00
|
|
|
# Check if ffmpeg command was successful
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error: FFmpeg command failed."
|
|
|
|
rm -f "$temp_file"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-03-02 21:22:03 +00:00
|
|
|
|
2024-06-01 05:00:40 +00:00
|
|
|
# Check if the output file was created successfully
|
|
|
|
if [ ! -f "$output_file" ]; then
|
|
|
|
echo "Error: Output file '$output_file' not created."
|
|
|
|
rm -f "$temp_file"
|
|
|
|
exit 1
|
2024-03-02 21:22:03 +00:00
|
|
|
fi
|
|
|
|
|
2024-06-01 05:00:40 +00:00
|
|
|
# Increase the volume by 10 times
|
|
|
|
ffmpeg -i "$output_file" -af "volume=10.0" -c:v copy "$output_file"_loud.mp4
|
|
|
|
|
|
|
|
# Check if ffmpeg command was successful
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error: FFmpeg command failed."
|
|
|
|
rm -f "$temp_file"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Move the loud file to original output file
|
|
|
|
mv "$output_file"_loud.mp4 "$output_file"
|
|
|
|
|
|
|
|
# Check if the output file was created successfully
|
|
|
|
if [ ! -f "$output_file" ]; then
|
|
|
|
echo "Error: Output file '$output_file' not created."
|
|
|
|
rm -f "$temp_file"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Video conversion successful. Output file: $output_file"
|
|
|
|
|
2024-03-02 21:22:03 +00:00
|
|
|
# Clean up temporary file in RAM
|
|
|
|
rm -f "$temp_file"
|