saviodesign
Dabbler
- Joined
- Apr 7, 2017
- Messages
- 21
How to Batch Remove meta tags and/or Remux .mkv files
Sometimes your acquired media isn’t always from a great source (torrents, friends, family, etc.) and may be littered with meta tags.
While this is easily remedied for “.mp4” and “.avi” files, there hasn’t been a real clean way to do this for .mkv files. So I decided to build a few scripts to assist the community with this using open sourced tools which are already able to do this.
Using the scripts provided you’ll be able to remove tags .mkv from files and/or convert “.mp4” and “.avi” files to “.mkv” in batch.
Note: I have taken the liberty of placing these scripts into a zip container,
Step 1: Create a jail for our programs
Note: if you have a jail that’s not dedicated to a service like Plex OpenVPN, Transmission, Sonarr, etc you can skip this step and move on to step 2
Log into your FreeNAS / FreeBSD host, via the Web UI ( e.g. http://192.168.1.25/ui/sessions/signin)
Head to Jails choose ADD, set the following parameters
Jail Name: mkvtool
Release: Most recent one (usually ending with “fetched”)
Check the following boxes: DHCP Autoconfigure IPv4 and VNET
Confirm and create the jail, once it’s done click the 3 dots to the right of your newly created jail and choose edit.
Add a check to the box labeled “Auto-start”, scroll down and Save
Click the 3 dots to the right of your jail once more and choose Mount Points.
- Set your Source to somewhere you can move or easily access your media ( e.g. /mnt/freenashost/media)
- Set your destination as: /mnt/iocage/jails/mkvtool/root/media
Step 2: Log into the jail and install bash and mkvtoolnix
Login to your freeness host from a command line tool like PuTTY or MobaXTerm, and elevate to “root”
Note: How to Log in to an iocage jail
To log into the jail, first, you'll need to find your jail name by entering
iocage list
You’ll see something similar to the following:
+-----+----------+-------+--------------+------+
| JID | NAME | STATE | RELEASE | IP4 |
+=====+==========+=======+==============+======+
| 3 | plex | up | 11.2-RELEASE | DHCP |
+-----+----------+-------+--------------+------+
| 2 | mvktool | up | 11.2-RELEASE | DHCP |
Next log in by entering: iocage console jailname
e.g. iocage console mkvtool
- Log into the new jail iocage console mkvtool
- Install bash mkvtoolnix (prerequisites for our script to run), and nano (much easier text editor than navigating through VI editor)
pkg install -y -q bash mkvtoolnix nano
- Create a short cut to access your media and the script to clean the tags:
ln -s /media/the/path/to/your/media/files ~/meta
- Navigate to the shortcut we created earlier
cd ~/meta
Step 3: Build your scripts
Let’s create a script called “cleantags.sh”
nano cleantags.sh
copy and paste the following:
#!/bin/sh
############################################################
### Use this script to remove meta tags from .mkv files ####
############################################################
for f in *.mkv
do
echo -n $f ' '
mkvpropedit --delete title "${f}"
done
Let’s create a second script called “remux.sh”
nano remux.sh
copy and paste the following:
#!/usr/local/bin/bash
############################################################
###Use this script to convert .avi and .mp4 files to .mkv###
############################################################
###convert .avi to .mkv
for f in *.avi
do
echo -n $f ' '
mkvmerge -o "${f}.mkv" --language 0:eng --language 1:eng "${f}"
done
###convert .mp4 to .mkv
for f in *.mp4
do
echo -n $f ' '
mkvmerge -o "${f}.mkv" --language 0:eng --language 1:eng "${f}"
done
### Correct issues with maning convention ###
#Renaming .avi.mkv to .mvk
for i in *.avi.mkv
do
mv "$i" "${i/.avi.mkv/.mkv}"
done
#Renaming .mp4.mkv to .mvk
for i in *.mp4.mkv
do
mv "$i" "${i/.mp4.mkv/.mkv}"
done
echo "All done boss!!!"
Step 4: Let’s make them both executable
chmod 755 cleantags.sh remux.sh
From here we should be golden.
To start removing the title tags from your .mkv files: ./cleantags.sh
To start remuxing your .avi and .mp4’ files to .mkv containers: ./remux.sh
Note: These scripts are set up to run locally, meaning it will only execute against files within the same folder as the scripts themselves. If you would like this to run in an alternate folder, it would be better to copy and run these scripts within that folder.
Last edited: