Skip to content

Instantly share code, notes, and snippets.

@pronebird
Last active January 12, 2024 18:50
Show Gist options
  • Save pronebird/318cb03a9d020cf037f91f00c5d8f7f0 to your computer and use it in GitHub Desktop.
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
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
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