Commite Code
This commit is contained in:
37
Moodle/Tools/getvtt.sh
Normal file
37
Moodle/Tools/getvtt.sh
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set the custom cache directory for Whisper models
|
||||
export XDG_CACHE_HOME="/backup/whisper"
|
||||
|
||||
# Create the cache directory if it does not exist
|
||||
mkdir -p "$XDG_CACHE_HOME"
|
||||
|
||||
# Function để xử lý từng file (chạy trong từng tiến trình riêng)
|
||||
process_file() {
|
||||
file="$1"
|
||||
dir=$(dirname "$file")
|
||||
filename=$(basename "$file" .mp4)
|
||||
vtt_file="$dir/$filename.vtt"
|
||||
|
||||
if [ ! -f "$vtt_file" ]; then
|
||||
echo "🔄 Generating subtitles for: $file"
|
||||
whisper "$file" --model medium --output_format vtt --task transcribe --language en --output_dir "$dir"
|
||||
|
||||
if [ -f "$dir/${filename}_en.vtt" ]; then
|
||||
mv "$dir/${filename}_en.vtt" "$vtt_file"
|
||||
echo "✅ Created: $vtt_file"
|
||||
else
|
||||
echo "⚠️ Warning: Expected $dir/${filename}_en.vtt not found."
|
||||
fi
|
||||
else
|
||||
echo "⏩ Subtitle already exists for: $file"
|
||||
fi
|
||||
}
|
||||
|
||||
export -f process_file
|
||||
export XDG_CACHE_HOME
|
||||
|
||||
# Tìm tất cả file .mp4 và xử lý song song với tối đa 4 tiến trình
|
||||
find . -type f -name "*.mp4" | xargs -n 1 -P 4 -I {} bash -c 'process_file "$@"' _ {}
|
||||
|
||||
echo "🎉 All done!"
|
Reference in New Issue
Block a user