Last active
September 6, 2024 18:16
-
-
Save pronebird/318cb03a9d020cf037f91f00c5d8f7f0 to your computer and use it in GitHub Desktop.
Convert videos in bulk to H264 baseline/YUV420p, preserve metadata and sanitize filenames
This file contains 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
caffeinate & | |
CAFFEINATE_PID=$! | |
for FILE in *.mkv; do | |
OUTPUT=$(echo $FILE | sed -r "s/[ ]*[\.-\(]?(480p|720p|1080p|WEB|576p|HDTV|Xvid).*(\.[a-z4]+)$/\2/I") | |
if [ "$OUTPUT" = "$FILE" ]; then | |
OUTPUT=$(echo $OUTPUT | sed -r "s/(\.[a-z4]+)$/.converted\1/I") | |
fi | |
if [ -f "$OUTPUT" ]; then | |
echo "File already exists: $OUTPUT" | |
echo "Type YES to skip it, anything else to overwrite" | |
read REPLY | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
echo "Skipping $OUTPUT" | |
continue | |
fi | |
fi | |
ffmpeg -i "$FILE" \ | |
-acodec aac \ | |
-vcodec h264 \ | |
-profile:v baseline \ | |
-scodec copy \ | |
-vf format=yuv420p \ | |
"$OUTPUT" | |
done | |
kill $CAFFEINATE_PID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment