Skip to content

Instantly share code, notes, and snippets.

@random-robbie
Created May 25, 2023 16:12
Show Gist options
  • Save random-robbie/002d51f199312f8343d15f97113fe4df to your computer and use it in GitHub Desktop.
Save random-robbie/002d51f199312f8343d15f97113fe4df to your computer and use it in GitHub Desktop.
Convert all MKV files in the current directory and make them mp4 compatible with Ipad
#!/bin/bash
# Iterate through all .mkv files in the current directory
for file in *.mkv; do
if [[ -f "$file" ]]; then
# Remove spaces and emoji characters from the file name
new_name=$(echo "$file" | sed -e 's/ /_/g' -e 's/[^[:alnum:]._\-]//g')
if [[ "$new_name" != "$file" ]]; then
mv "$file" "$new_name"
echo "Renamed file: $file -> $new_name"
file="$new_name"
fi
# Convert the file to iPad-compatible format using FFmpeg
output_file="${file%.*}.mp4"
ffmpeg -i "$file" -c:v h264 -crf 23 -preset medium -c:a aac -b:a 128k "$output_file"
echo "Converted file: $file -> $output_file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment