116 lines
2.9 KiB
Bash
Executable File
116 lines
2.9 KiB
Bash
Executable File
EXEC_SHELL_PATH=$(command -v bash)
|
|
|
|
|
|
# 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."
|
|
exit 1
|
|
fi
|
|
|
|
# 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
|
|
output_folder="/mnt/Zonai/Videos/converted_for_compatibility"
|
|
output_filename="compatible-$(basename "$input_file" | sed 's/[^a-zA-Z0-9._-]/_/g')"
|
|
output_file="$output_folder/$output_filename"
|
|
|
|
# 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
|
|
|
|
# Copy the input video to RAM
|
|
temp_file=$(mktemp -u)
|
|
cp "$input_file" "$temp_file"
|
|
|
|
# Set the number of threads to 32 (adjust as needed)
|
|
threads=32
|
|
|
|
# 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"
|
|
|
|
# Check if ffmpeg command was successful
|
|
if [ $? -ne 0 ]; then
|
|
echo "Error: FFmpeg command failed."
|
|
rm -f "$temp_file"
|
|
exit 1
|
|
fi
|
|
|
|
# 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
|
|
|
|
# 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"
|
|
|
|
# Clean up temporary file in RAM
|
|
rm -f "$temp_file"
|