You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
#!/bin/bash
|
|
|
|
# Check if ffmpeg is installed
|
|
if ! command -v ffmpeg &> /dev/null; then
|
|
echo "Error: ffmpeg is not installed. Install ffmpeg to use this script."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if directory argument is provided
|
|
if [ -z "$1" ]; then
|
|
echo "Usage: $0 <directory> [--dry-run]"
|
|
exit 1
|
|
fi
|
|
|
|
dir="$1"
|
|
dry_run=false
|
|
|
|
# Check for --dry-run option
|
|
if [[ "$2" == "--dry-run" ]]; then
|
|
dry_run=true
|
|
fi
|
|
|
|
# Find all .mkv files recursively
|
|
find "$dir" -type f -name "*.mkv" | while read -r file; do
|
|
echo "Processing: $file"
|
|
|
|
# Get subtitle stream indices with language "jpn"
|
|
mapfile -t subtitle_streams < <(ffprobe -loglevel error -select_streams s -show_entries stream=index:stream_tags=language -of csv=p=0 "$file" | awk -F, '$2 == "jpn" {print NR-1, $1}')
|
|
|
|
if [[ ${#subtitle_streams[@]} -eq 0 ]]; then
|
|
echo "No Japanese subtitle tracks found in $file. Skipping..."
|
|
continue
|
|
fi
|
|
|
|
# Temporary output file
|
|
output_file="${file%.mkv}_modified.mkv"
|
|
|
|
# Build ffmpeg metadata arguments
|
|
ffmpeg_args=()
|
|
for stream_info in "${subtitle_streams[@]}"; do
|
|
read -r stream_index track_id <<< "$stream_info"
|
|
echo "Changing subtitle track ID $track_id (subtitle index $stream_index) to English in $file"
|
|
ffmpeg_args+=("-metadata:s:s:$stream_index" "language=eng")
|
|
done
|
|
|
|
# Print the command if dry-run is enabled
|
|
echo "ffmpeg -i \"$file\" -map 0 -c copy \"${ffmpeg_args[@]}\" \"$output_file\""
|
|
|
|
if [ "$dry_run" = false ]; then
|
|
ffmpeg -i "$file" -map 0 -c copy "${ffmpeg_args[@]}" "$output_file" && mv "$output_file" "$file"
|
|
fi
|
|
|
|
echo "Finished processing: $file"
|
|
|
|
done
|
|
|
|
echo "All done!"
|
|
|