Skip to content

Instantly share code, notes, and snippets.

@luckylittle
Created July 3, 2019 04:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luckylittle/bec98791c037d0837333ef89eea22f5d to your computer and use it in GitHub Desktop.
Save luckylittle/bec98791c037d0837333ef89eea22f5d to your computer and use it in GitHub Desktop.
Convert all MP4s in a folder to MKVs using MKVMerge
#!/bin/bash
# Requires: mkvmerge
for RH in *; do mkvmerge ${RH} -o $(basename -s .mp4 ${RH}).mkv; done; echo 'Done!'
# rm *.mp4
@luckylittle
Copy link
Author

One-liner that converts all *.mp4 in ~/Downloads to *.mkv using mkvmerge:

find ~/Downloads -type f -name "*.mp4" -exec sh -c  'mkvmerge -o ~/Downloads/"$(basename "{}" .mp4)".mkv {}' \;

@luckylittle
Copy link
Author

Alias in .bashrc or .zshrc:

alias convert2mkv="echo 'Converting MP4 to MKV in ~/Downloads/...'; find ~/Downloads -type f -name \"*.mp4\" -exec sh -c 'mkvmerge -o ~/Downloads/\$(basename "{}" .mp4).mkv {}' \;"

Alias also with folders creation:

alias convert2mkv="echo 'Converting MP4 to MKV in ~/Downloads/...'; find ~/Downloads -type f -name \"*.mp4\" -exec sh -c 'mkvmerge -o ~/Downloads/\$(basename "{}" .mp4).mkv {} ; mkdir -p ~/Downloads/\$(basename "{}" .mp4)' \;"

@luckylittle
Copy link
Author

To convert all video/MP2T (*.ts):

find . -type f -iname "*.ts" -execdir sh -c 'mkvmerge {} -o $(basename {} .ts).mkv' \;

@luckylittle
Copy link
Author

Merge one *.mp4 and one *.m4a inside each directory into a *.mkv:

find . -name '*.mp4' -execdir sh -c 'mkvmerge -o "$(basename "{}" .mp4)".mkv {} "$(basename "{}" .mp4)".m4a' \;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment