Created
July 27, 2025 12:57
-
-
Save niskala5570/4cdb57eb6208904e8bc0c746ffb8824b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
use_ditukar=false | |
if [[ "$1" == "-f" ]]; then | |
use_ditukar=true | |
shift | |
fi | |
if [[ $# -eq 0 ]]; then | |
read -p "Enter one or more input files (use quotes if they have spaces): " input_line | |
eval set -- $input_line | |
fi | |
process_file() { | |
local input="$1" | |
# Clean up quotes | |
input="${input%\"}" | |
input="${input#\"}" | |
input="${input%\'}" | |
input="${input#\'}" | |
if [[ ! -f "$input" ]]; then | |
echo "❌ Fail tidak dijumpai: $input" | |
return 1 | |
fi | |
local dir base filename output_dir temp output | |
dir=$(dirname -- "$input") | |
base=$(basename -- "$input") | |
filename="${base%.*}" | |
if $use_ditukar; then | |
output_dir="$dir/ditukar" | |
mkdir -p "$output_dir" | |
else | |
output_dir="$dir" | |
fi | |
# Create a unique temp file using filename + $$ (PID) | |
temp="$output_dir/temp_fdkaac_${filename}_$$.m4a" | |
output="$output_dir/${filename}_final.m4a" | |
echo "" | |
echo ">>> Mengekod $base kepada HE-AACv2..." | |
ffmpeg -i "$input" -f wav - 2>/dev/null | fdkaac -p 29 -m 1 -b 64k -o "$temp" - | |
if [[ $? -ne 0 ]]; then | |
echo "❌ fdkaac encoding failed for: $base" | |
rm -f "$temp" | |
return 1 | |
fi | |
echo ">>> Muxing metadata and album art..." | |
ffmpeg -i "$temp" -i "$input" -map 0:a -map 1:v? -map_metadata 1 -c copy "$output" -y | |
if [[ $? -eq 0 ]]; then | |
echo "✔ Success: $output" | |
rm -f "$temp" | |
else | |
echo "❌ ffmpeg muxing failed for: $base" | |
rm -f "$temp" | |
return 1 | |
fi | |
} | |
for input in "$@"; do | |
process_file "$input" & | |
done | |
wait | |
echo "All processing done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment